Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2101964iof; Tue, 7 Jun 2022 19:48:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzc7trxfq6Av82LG569KhN+lJMr1FoVvgapmRxGrPRYXRkBk1w2JsLr+XcOBm4iHvtz079S X-Received: by 2002:a17:90a:e50c:b0:1ea:14c1:2236 with SMTP id t12-20020a17090ae50c00b001ea14c12236mr4266051pjy.2.1654656535489; Tue, 07 Jun 2022 19:48:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654656535; cv=none; d=google.com; s=arc-20160816; b=zWeM23tZCwVhXud0Keh632FgUSE39VMcqLInASHWxh7GzscJkonEF31AGIMRUYtTAw 6KgPAz8xdOqR5qoLVCkVzvxG4TREc4ByZyrz1vbFim6mQDBpNnvxA/D+rlTbk5ncDkmP GG3dRqWJ5TZN5+6t/yVGvpmgFxwHDokP12w3Ta2K47YKQO7WwtBLKdnIcIMVSA4JnUmF vpJyHRsNE5n6WebfuAk3PscJ3nvS0m53cBRW8ddJQ519/loMgNmruuWTqdgiYFFK+I+W srP51fhlLXAt1CBm7dXjOXreQ3Ouhoy+SnH2J0sDG0ju5tQQqzDXGF+a6NfxhX5o+xe+ a1jQ== 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=AnzVqIcdo8t/Y+MqRjGomhpxcloe6KxJBX44gSL5108=; b=WEedrnN3y3DLyw5ui5mCfUvqtT61MrG2boZq7bJaaeULcFxFkawrWqjG+sywU4oQtg CO+rIViJtgPbxjIF21oyt0sRaY63//+BgYtWTWQEVaFHpv+bumVisoY325C53jUk/KFE ms6cfow4dLeRW+Pkyb/G9ywIZEsoVeQ6Oyx8EulQK/LBvR3iWvn1hiDjpG82SGWQ8qzR aba1WJdiTwHz72O/Y+D8cQgZy1OcJt/tY4BKrmBosGYwXLOO3ABd3OoKn/FN8iEgaoJ2 lduLiDC/Gw/1Niyxw7BXq2/S/FIm0jASxOLbOlcsFo4kt8agqyMFmaJ/X4PzQB24ZOIT v+oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ConUKPUQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j4-20020a635504000000b003f9d5d48e42si26377496pgb.99.2022.06.07.19.48.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 19:48:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ConUKPUQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2ABB9279E7F; Tue, 7 Jun 2022 18:19:27 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381989AbiFGVze (ORCPT + 99 others); Tue, 7 Jun 2022 17:55:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379223AbiFGVCN (ORCPT ); Tue, 7 Jun 2022 17:02:13 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9026EBBC; Tue, 7 Jun 2022 11:46:58 -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 ams.source.kernel.org (Postfix) with ESMTPS id 48D7EB81FE1; Tue, 7 Jun 2022 18:46:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95656C34115; Tue, 7 Jun 2022 18:46:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654627615; bh=InTEJxokk0gSldDDmnuCDCLtUbImqooZSkroi+Xe/fA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ConUKPUQljQl8f38nIqrienv97ERXDR3w6xAlTNtPpPL/jVfYK3pFEM19lfwX/9Tn YJrucOM6WBEpzotHj+TndYqP8H7aeT9SelNbqJHaVyXte1oqLW3c7WZFAGoEXrhpVh 0cbzaBx1j4k3/dtU1qqZWpu1x8K2y9iK8gc2BmxQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Roberto Bergantinos , Ronnie Sahlberg , Steve French Subject: [PATCH 5.18 032/879] cifs: fix potential double free during failed mount Date: Tue, 7 Jun 2022 18:52:30 +0200 Message-Id: <20220607165003.608638078@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@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=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 8378a51e3f8140f60901fb27208cc7a6e47047b5 upstream. RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=2088799 Cc: stable@vger.kernel.org Signed-off-by: Roberto Bergantinos Signed-off-by: Ronnie Sahlberg Signed-off-by: Steve French Signed-off-by: Greg Kroah-Hartman --- fs/cifs/cifsfs.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -836,7 +836,7 @@ cifs_smb3_do_mount(struct file_system_ty int flags, struct smb3_fs_context *old_ctx) { int rc; - struct super_block *sb; + struct super_block *sb = NULL; struct cifs_sb_info *cifs_sb = NULL; struct cifs_mnt_data mnt_data; struct dentry *root; @@ -932,9 +932,11 @@ out_super: return root; out: if (cifs_sb) { - kfree(cifs_sb->prepath); - smb3_cleanup_fs_context(cifs_sb->ctx); - kfree(cifs_sb); + if (!sb || IS_ERR(sb)) { /* otherwise kill_sb will handle */ + kfree(cifs_sb->prepath); + smb3_cleanup_fs_context(cifs_sb->ctx); + kfree(cifs_sb); + } } return root; }