Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2856768pxb; Mon, 18 Apr 2022 09:40:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1Q+3w72h6ngXiJV2haFrghQaqH+trm/YxG7K4Ep/wg2iaPyjfejJHeGtI3QT2Gr+YRWRc X-Received: by 2002:a17:906:9b85:b0:6e0:5c22:f0df with SMTP id dd5-20020a1709069b8500b006e05c22f0dfmr9640888ejc.114.1650300000476; Mon, 18 Apr 2022 09:40:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650300000; cv=none; d=google.com; s=arc-20160816; b=SDpAuqsXazxNnYJBeRS/jQDtqjWTTBiZIxfL0IzgMw4j4dnRGgXGM8dUIxZ2xTrGEF vpjpdOuQV3Q0hmrwmr1j/Su5rCD47ahUHFvZycA7YBVPJwqg1yDxb08chhBBclM6XIas y+60OunUVHC9YM6yygkpM9wVh2PeCeYX2GIb6MFiqUeo0/EerEX4PkxMz4WkJ71efVNI HyLdBs8YVaKidfLTekZRlMCcdb4rIoPByG+Dn7U85Gkh1piYkEb/s+bOPZLshzsT7BpT /jvwMgey9TRCcdSTBNlde4HAFAeEjlpFbrAOEMqTfyIdniF/fdVGqJb0b2Xo171QBL2t 2npQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=IZh1GS8LyiGONFZ7sGYvHXquA11y4VTmsDF0NeUsVCk=; b=osUYGECqBNw3uZ/KQSB2Yzg2zOk/EIlhcIAveRGNeYy+ACQrzU96RNPtmMmAF56fU2 RIaG6HNGZqIoaVAmqPHbVMM6dOGJRNggMchvef0IKnvOYucqlLOWmIM+tnsmesEeKERt swefl09cYqte68uIuhFKaJW4zOkkqmDYI02Iqq7XAT3hY/vo3ZEsp3yYJ/taT29f70ty GtasZ54q+U2VlO0Ep56S/Rk5K7fs2nEjx6BegPvvgp6LqOUS4GrjremUtVyEp59SXJKa T7szUE7Lxk3P2/7c6DWp1Mc3v70Y73PGcoyCCNuExK9AUmaG4tzPkqzQhTEkLkY+mVxP +sNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xMluKMGr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hb19-20020a170906b89300b006e7fca9e87asi6331331ejb.656.2022.04.18.09.39.35; Mon, 18 Apr 2022 09:40:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xMluKMGr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239660AbiDRMh5 (ORCPT + 99 others); Mon, 18 Apr 2022 08:37:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239161AbiDRMcb (ORCPT ); Mon, 18 Apr 2022 08:32:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 818FF25C7F; Mon, 18 Apr 2022 05:24:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C8B7260FB0; Mon, 18 Apr 2022 12:24:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D11F4C385AB; Mon, 18 Apr 2022 12:24:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650284658; bh=m9viVS1D+NUit2asz3mAmwwfeEnNpj04FNw9SDwXsWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xMluKMGrhUKe4zD6KVHac4WFhX/K6nXW6lTvFAW/Vn9K2Kqa7mELZhFAdoFCDMl/U 6DXGXVFcR7ZPpnGTm3nd8IryjhbsD0UR238EmCYdwUcKyq61sy60hkGCxsNVh8bM7n vW7MEX/oelJhEWdTmMWomW0QW6iaezCCjABMzwhM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ronnie Sahlberg , Shyam Prasad N , Xiaoli Feng , Steve French Subject: [PATCH 5.17 187/219] cifs: verify that tcon is valid before dereference in cifs_kill_sb Date: Mon, 18 Apr 2022 14:12:36 +0200 Message-Id: <20220418121212.112167732@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121203.462784814@linuxfoundation.org> References: <20220418121203.462784814@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 From: Ronnie Sahlberg commit 8b6c58458ee3206dde345fce327a4cb83e69caf9 upstream. On umount, cifs_sb->tlink_tree might contain entries that do not represent a valid tcon. Check the tcon for error before we dereference it. Signed-off-by: Ronnie Sahlberg Cc: stable@vger.kernel.org Reviewed-by: Shyam Prasad N Reported-by: Xiaoli Feng Signed-off-by: Steve French Signed-off-by: Greg Kroah-Hartman --- fs/cifs/cifsfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -266,10 +266,11 @@ static void cifs_kill_sb(struct super_bl * before we kill the sb. */ if (cifs_sb->root) { - node = rb_first(root); - while (node != NULL) { + for (node = rb_first(root); node; node = rb_next(node)) { tlink = rb_entry(node, struct tcon_link, tl_rbnode); tcon = tlink_tcon(tlink); + if (IS_ERR(tcon)) + continue; cfid = &tcon->crfid; mutex_lock(&cfid->fid_mutex); if (cfid->dentry) { @@ -277,7 +278,6 @@ static void cifs_kill_sb(struct super_bl cfid->dentry = NULL; } mutex_unlock(&cfid->fid_mutex); - node = rb_next(node); } /* finally release root dentry */