Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1583701rdh; Mon, 25 Sep 2023 18:30:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHAYEb+CW+NATU8u9XgeO9ODEz0pHRAyJvNy7kl+lx7jayXEgwl1oxtURD0ZGdUHU6o2eHA X-Received: by 2002:a05:6a21:6d95:b0:15c:fa48:2c09 with SMTP id wl21-20020a056a216d9500b0015cfa482c09mr7889513pzb.15.1695691853694; Mon, 25 Sep 2023 18:30:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695691853; cv=none; d=google.com; s=arc-20160816; b=wFLgkvqa9oXAUITKF+z82kBtiViGVW2KxGWE2TIjbDUGChZ8pfZlCPX9E8zu0Ot9qE 8DI86K7OP4mXRj/I8vYOy46qb4onasN+aebZqXbslbWuhSQMr5M0Sr9+2noga9DjyRzn lMeV9em/vSQkIcLhwFlFsUcpa9LYgcb6RH521AVeH4fr1kkhZ1hGPCWyhjxoVXC6yDqW pUU3bnNioec+6jWlkeKJMmuCm2BgJ8q5wJjKfaBId5DVtFCQy6fZPfwntkJ1/xICLq8M bizqEb7SPhsOM/mih2HKw1uOr4GxpXp+wrEr3Ah/yKZgtryrFRHQUXdz1wjYVesDiqXV dO8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=HmMAleqBn75OUwpk4uKmeZt9A0MWGGQ0YJrxgXueRFc=; fh=Cm2hpEw9Qfn09vBSh99ILDXNDwRc/8JGNd2MumiWRf0=; b=FR6Kf/pErXm30GYuOzqX3ZACXl+UWfZAzHJHGBx8pP8AU0sHOHdC8FiutZKQhjE+/u Z8c8A10y5xXwQJ9MLtlqAp/bIWd4yC25mdbXw4TQALpvB7sSDRaV/wghtwJaVtt24CnS eAp5A0I9frlOUSGRSPjL0EeUSzPodR97jNHR7SWPFhaIeVU9jeX/YTBzcGfcGuI4yqXA YNVSQlP3c2FvwWpUhLXMflA7WyMkjoNynaT5bFFNMgc0vMiP/7V0v5GAj1NB787c+gTz WXxT8J/x7aIwpaQTEnKH3SdO72ZoAXkbWW0s855mC0x1Hi0F0RIYA49wu4TmnDrR7GTM hk5A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id u15-20020a170902714f00b001b8ae9058d3si9310831plm.516.2023.09.25.18.30.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 18:30:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 7A39880215BB; Mon, 25 Sep 2023 18:27:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232893AbjIZB2B (ORCPT + 99 others); Mon, 25 Sep 2023 21:28:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232218AbjIZB2A (ORCPT ); Mon, 25 Sep 2023 21:28:00 -0400 Received: from mail.nfschina.com (unknown [42.101.60.195]) by lindbergh.monkeyblade.net (Postfix) with SMTP id F3DD4101; Mon, 25 Sep 2023 18:27:52 -0700 (PDT) Received: from localhost.localdomain (unknown [180.167.10.98]) by mail.nfschina.com (Maildata Gateway V2.8.8) with ESMTPA id D75F9604DFA33; Tue, 26 Sep 2023 09:27:48 +0800 (CST) X-MD-Sfrom: suhui@nfschina.com X-MD-SrcIP: 180.167.10.98 From: Su Hui To: sfrench@samba.org, pc@manguebit.com, lsahlber@redhat.com, sprasad@microsoft.com, tom@talpey.com Cc: Su Hui , dan.carpenter@linaro.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH v2] cifs: avoid possible NULL dereference Date: Tue, 26 Sep 2023 09:27:34 +0800 Message-Id: <20230926012733.814657-1-suhui@nfschina.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,RDNS_NONE, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 25 Sep 2023 18:27:59 -0700 (PDT) smatch warn: fs/smb/client/file.c:4910 cifs_oplock_break() warn: variable dereferenced before check 'inode' (see line 4881) If 'inode' is NULL, print some warning and return. Signed-off-by: Su Hui --- fs/smb/client/file.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c index 2108b3b40ce9..de705c8b2d22 100644 --- a/fs/smb/client/file.c +++ b/fs/smb/client/file.c @@ -4878,8 +4878,8 @@ void cifs_oplock_break(struct work_struct *work) struct cifsFileInfo *cfile = container_of(work, struct cifsFileInfo, oplock_break); struct inode *inode = d_inode(cfile->dentry); - struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); - struct cifsInodeInfo *cinode = CIFS_I(inode); + struct cifs_sb_info *cifs_sb; + struct cifsInodeInfo *cinode; struct cifs_tcon *tcon; struct TCP_Server_Info *server; struct tcon_link *tlink; @@ -4888,6 +4888,13 @@ void cifs_oplock_break(struct work_struct *work) __u64 persistent_fid, volatile_fid; __u16 net_fid; + if (!inode) { + cifs_dbg(FYI, "%s : failed to find inode\n", __func__); + return; + } + cifs_sb = CIFS_SB(inode->i_sb); + cinode = CIFS_I(inode); + wait_on_bit(&cinode->flags, CIFS_INODE_PENDING_WRITERS, TASK_UNINTERRUPTIBLE); @@ -4907,7 +4914,7 @@ void cifs_oplock_break(struct work_struct *work) cinode->oplock = 0; } - if (inode && S_ISREG(inode->i_mode)) { + if (S_ISREG(inode->i_mode)) { if (CIFS_CACHE_READ(cinode)) break_lease(inode, O_RDONLY); else -- 2.30.2