Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4077457imu; Tue, 18 Dec 2018 08:42:28 -0800 (PST) X-Google-Smtp-Source: AFSGD/XdIBibS7DyE3wgRRIpEI8yosv5/IDh7ghOwJz/vDOqlJgycxdx9kKUIJo3gWXuEq0JekxV X-Received: by 2002:a62:2fc3:: with SMTP id v186mr17407612pfv.82.1545151348537; Tue, 18 Dec 2018 08:42:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545151348; cv=none; d=google.com; s=arc-20160816; b=igbgE0xiFSK1nsAuhqk6cE3Gsio0Y4DIkDnwuY1OgWGwrpyOmLFKLY7uWkkjfKon6k CT4Lcd+Egv2NqxeSiSIiw5a9DURluTZZJBosNkVIU6bC7jDButjp2H0VWHgZLCbexbUT xofuoG19teetk7u/S6H8GFIhzout/IW7arHfbTp17122TXJiaJP5lu5Yq14kq4X5Y2fu C7VBPNKrRLNjy/83TB+eOZqTI5pecdvf/4a7jQqfGs4WeWTbeVBd6Nk+2ybE0jciVrYo IsTN/Xm0RFTxkQd0OsXzhs76qvKBTm3W/XNuXdqbUMnllPLdvHu9LVf7BQBiqbw0ANBX NMpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=ll2WxwfhjUnZ7SisiAnlGTR10/9OPEpzNthtLNQ9JYw=; b=vUZl0ImKVdpNpO4Y5oOAa64CwwpvE1FiVL4CzCB0kfIH2ke+QllnRfPkpnZ4TsU/Qv 65OcboIFlMk4TDdwbAgYh1DZ/91xLfgmkcICeEpmc8lWoshhv6f8gT1mtXFXZbrpgI9R Q1Yx6Sejb9js0MNlnio9G9xasuDOOkpvWi6BVuIEbgU9esUIQFKawnIgl+Dl4Ev5dnW1 nxk1YA72dMhpLVaWahGAmWquQ1mXsHs2I5AlSvqBF4If2mb6fhkoX/WVts8riMP1oq3e 47HlbO1elDjiU5rM2tqNztIS4OfD0fi3nzkgWZrobQuugq3dCLC/A97T+ao7deO/AtfP YaoQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b2si14193076pgh.475.2018.12.18.08.42.09; Tue, 18 Dec 2018 08:42:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727281AbeLRQeE (ORCPT + 99 others); Tue, 18 Dec 2018 11:34:04 -0500 Received: from www.osadl.org ([62.245.132.105]:47281 "EHLO www.osadl.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726939AbeLRQeE (ORCPT ); Tue, 18 Dec 2018 11:34:04 -0500 Received: from debian01.hofrr.at (178.115.242.59.static.drei.at [178.115.242.59]) by www.osadl.org (8.13.8/8.13.8/OSADL-2007092901) with ESMTP id wBIGUaNb012983; Tue, 18 Dec 2018 17:30:36 +0100 From: Nicholas Mc Guire To: Steve French Cc: linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-kernel@vger.kernel.org, Nicholas Mc Guire Subject: [PATCH] cifs: check kzalloc return Date: Tue, 18 Dec 2018 17:27:19 +0100 Message-Id: <1545150439-26055-1-git-send-email-hofrat@osadl.org> X-Mailer: git-send-email 2.1.4 X-Spam-Status: No, score=-1.9 required=6.0 tests=BAYES_00 autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on www.osadl.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org kzalloc can return NULL so a check is needed. While there is a check for ret_buf there is no check for the allocation of ret_buf->crfid.fid - this check is thus added. Both call-sites of tconInfoAlloc() check for NULL return of tconInfoAlloc() so returning NULL on failure of kzalloc() here seems appropriate. As the kzalloc() is the only thing here that can fail it is moved to the beginning so as not to initialize other resources on failure of kzalloc. Signed-off-by: Nicholas Mc Guire Fixes: 3d4ef9a15343 ("smb3: fix redundant opens on root") --- Problem located with an experimental coccinelle script While at it make checkpatch happy by using *ret_buf->crfid.fid rather than struct cifs_fid. Patch was compile tested with: x86_64_defconfig + CIFS=m (with some unrelated smatch warnings and some pending cocci fixes) Patch is against v4.20-rc7 (localversion-next is next-20181218) fs/cifs/misc.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c index 8a41f4e..59efffe 100644 --- a/fs/cifs/misc.c +++ b/fs/cifs/misc.c @@ -113,6 +113,13 @@ tconInfoAlloc(void) struct cifs_tcon *ret_buf; ret_buf = kzalloc(sizeof(struct cifs_tcon), GFP_KERNEL); if (ret_buf) { + ret_buf->crfid.fid = kzalloc(sizeof(*ret_buf->crfid.fid), + GFP_KERNEL); + if (!ret_buf->crfid.fid) { + kfree(ret_buf); + return NULL; + } + atomic_inc(&tconInfoAllocCount); ret_buf->tidStatus = CifsNew; ++ret_buf->tc_count; @@ -120,8 +127,6 @@ tconInfoAlloc(void) INIT_LIST_HEAD(&ret_buf->tcon_list); spin_lock_init(&ret_buf->open_file_lock); mutex_init(&ret_buf->crfid.fid_mutex); - ret_buf->crfid.fid = kzalloc(sizeof(struct cifs_fid), - GFP_KERNEL); spin_lock_init(&ret_buf->stat_lock); atomic_set(&ret_buf->num_local_opens, 0); atomic_set(&ret_buf->num_remote_opens, 0); -- 2.1.4