From patchwork Tue Apr 3 22:04:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 10321815 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A250360532 for ; Tue, 3 Apr 2018 22:04:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E74C28CFD for ; Tue, 3 Apr 2018 22:04:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E03C28D05; Tue, 3 Apr 2018 22:04:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1448428CFD for ; Tue, 3 Apr 2018 22:04:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:To:From :Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=90TygSQ2DKV/qDZ+obtIoAjtPhe+dJkMNcQVQ1Jvxsg=; b=CmI49YtyyK50WA ZlwCMDXEUzlkfjorN7WoGVpFz89pnsgTFp7b8OHaU8yc4hL1eXKKVqY1TIZ+aMDKAVpsfETGbPZMg xKwZgC9Ccwalj12R1yzo0/KQA8oc8yMFQwKbkfOGQMVdPvRY/ujb6R6YvMhFYHC/uoJgdJmj5uZZ2 IIw66UnD7CM3dcJmv7l76HHEk/IBfCKufQoGi0Ja3tfERyo89OIsGosuo696ZLNKRsGWeYW6rQFGO 2VkQUJA4bCKDHEEMhR70v+jNPUi8Qk1VxNlIZ1YaiLXtLYRfBZ7XwddQ2llvjJNFxmwOwG5tu6zW1 5+pHZe7E7Cc6J3JKY3Ig==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f3U2i-000800-Ur; Tue, 03 Apr 2018 22:04:40 +0000 Received: from gateway36.websitewelcome.com ([50.116.125.2]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f3U2g-0007yS-5u for linux-arm-kernel@lists.infradead.org; Tue, 03 Apr 2018 22:04:39 +0000 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway36.websitewelcome.com (Postfix) with ESMTP id 5029D400CD864 for ; Tue, 3 Apr 2018 17:04:25 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id 3U2TfY6EPE0sx3U2TfThBO; Tue, 03 Apr 2018 17:04:25 -0500 Received: from [189.145.54.187] (port=54128 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.89_1) (envelope-from ) id 1f3U2S-001C9v-RI; Tue, 03 Apr 2018 17:04:24 -0500 Date: Tue, 3 Apr 2018 17:04:23 -0500 From: "Gustavo A. R. Silva" To: Eric Dumazet , Sunil Goutham , Robert Richter Subject: [PATCH v2] net: thunderx: nicvf_main: Fix potential NULL pointer dereferences Message-ID: <20180403220423.GA718@embeddedor.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - lists.infradead.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.145.54.187 X-Source-L: No X-Exim-ID: 1f3U2S-001C9v-RI X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.145.54.187]:54128 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 4 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180403_150438_265832_C69D3553 X-CRM114-Status: UNSURE ( 6.96 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, "Gustavo A. R. Silva" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add null check on kmalloc() return value in order to prevent a null pointer dereference. Addresses-Coverity-ID: 1467429 ("Dereference null return value") Fixes: 37c3347eb247 ("net: thunderx: add ndo_set_rx_mode callback implementation for VF") Signed-off-by: Gustavo A. R. Silva --- Changes in v2: - Add a null check on a second kmalloc a few lines below. Thanks to Eric Dumazet for pointing this out. drivers/net/ethernet/cavium/thunder/nicvf_main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_main.c b/drivers/net/ethernet/cavium/thunder/nicvf_main.c index 1e9a31f..f7b5ca5 100644 --- a/drivers/net/ethernet/cavium/thunder/nicvf_main.c +++ b/drivers/net/ethernet/cavium/thunder/nicvf_main.c @@ -1999,10 +1999,14 @@ static void nicvf_set_rx_mode(struct net_device *netdev) struct xcast_addr *xaddr; mc_list = kmalloc(sizeof(*mc_list), GFP_ATOMIC); + if (unlikely(!mc_list)) + return; INIT_LIST_HEAD(&mc_list->list); netdev_hw_addr_list_for_each(ha, &netdev->mc) { xaddr = kmalloc(sizeof(*xaddr), GFP_ATOMIC); + if (unlikely(!xaddr)) + return; xaddr->addr = ether_addr_to_u64(ha->addr); list_add_tail(&xaddr->list,