Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6871174rwb; Mon, 12 Dec 2022 07:23:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Til2FjUIv7ahE0NTS+W/pUi+YjbpuifiLv72hHACOVnZjTFbZkXSrmPAjjSeE5lPUaV6V X-Received: by 2002:a17:90a:4812:b0:218:b7b7:6994 with SMTP id a18-20020a17090a481200b00218b7b76994mr17176156pjh.43.1670858630299; Mon, 12 Dec 2022 07:23:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670858630; cv=none; d=google.com; s=arc-20160816; b=OyoIDaJDaHQ+vlgS5HCBiTFcN8GZSE0ISfvLnfzoCLKPWewXJAzBDn1M4XC05teZfx WTYx8Whg4CrB/Ly6NwPc6JyWoQgYGMvtjPObYcGViMy7Co3QLNfcTiVqwTjk3iIg7GEC PgT6RxgwetnDN22rljjto8lwmypZqNl47AYft36zFaRZ+2JnNuy+CYOVrqy5GvpKGb9+ xcaxrMBcwclx+gpEkJyh8CEGAEfXmepTB+g3Du4o/rg52ewx2SdtsHcSLC/yrvBzezNh 2i3moxseyWyD6Duf2qBxSXf4MgEVaOfOV3SK159kJWmCEIvH0SGm+Cdoh5tWhELSLtg5 dXsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=rMSyr5638iNOtaU3fOtozQM+rs1xVMiAVVRy7/1E6tY=; b=f9VTAPPsWZB5YpqcfskxpL1CeUCmboAGqoR8T7agBSEK0lR+RCeZEHLMWbMOj+lZb+ JPtUxZCdvZDEYHWh95FVFcfIqZ7HhKTJWIQzaRuOiAnEWey9gZDJMsxbjLKu7r+iDhA5 OPXAwYWqmzJg8dITMtZwEBbgc1YXr9nnB/ZcPmPY0/vMav57bv21SNDR1bzjNzpTXuSI D/vBMm9OBeeJ56SLR1aLnOokV1HEcdCzxdceLPftfZrzgjTPK8suqjBaGc9zn0LB9ONw QRwCtFiH+YtXYPzpoUuGINwUsx0T/IbfIJ4Jl6S+K3qS5lKP0fJgz1PjImLjEXKxnyZF aqZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2022-7-12 header.b=adBff1HH; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id np8-20020a17090b4c4800b0020ad8a730dbsi10447982pjb.58.2022.12.12.07.23.30; Mon, 12 Dec 2022 07:23:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-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=@oracle.com header.s=corp-2022-7-12 header.b=adBff1HH; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231768AbiLLPLe (ORCPT + 99 others); Mon, 12 Dec 2022 10:11:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230189AbiLLPLd (ORCPT ); Mon, 12 Dec 2022 10:11:33 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D68312D2C for ; Mon, 12 Dec 2022 07:11:32 -0800 (PST) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2BC98QnQ028925; Mon, 12 Dec 2022 15:11:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2022-7-12; bh=rMSyr5638iNOtaU3fOtozQM+rs1xVMiAVVRy7/1E6tY=; b=adBff1HHiHglWeiGwa3zFbV6kZaD8PeVHRuUpNtHB3eqc9PcoCgyfoEAOnf8KFDx/xje 6YnGhfVjfctv1sDu/6JptHY2ialBGUkr1byCgv+d79t7PcTvjcsYFnEhsnodtRtoDQIH VQf8e4hhcYBLLt0w26P0MDf6kaFTpdGG7f6S2L4mKp9Uyo6bZSWvn5YjeF8dhcoZ/cWl gJSLkHvDqwqje1a4QA+h9wngo43i+Twmp5kgWLdDHkBd4yFV/3SWUpGVItDLNdq79oTw mN6oQwNUISCtn7E7GVcowQe4luf+DyGRgv5jKmrs/rBZMIFCRgQb8Q7xzRJurmYXwSxD ug== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3mch1a302n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 12 Dec 2022 15:11:29 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2BCE34jT018553; Mon, 12 Dec 2022 15:11:27 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3mcgjamrh6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 12 Dec 2022 15:11:27 +0000 Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2BCFA3Vs012034; Mon, 12 Dec 2022 15:11:27 GMT Received: from ca-common-hq.us.oracle.com (ca-common-hq.us.oracle.com [10.211.9.209]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 3mcgjamrfp-1; Mon, 12 Dec 2022 15:11:27 +0000 From: Dai Ngo To: chuck.lever@oracle.com, jlayton@kernel.org Cc: kolga@netapp.com, hdthky0@gmail.com, linux-nfs@vger.kernel.org, security@kernel.org Subject: [PATCH v2 1/1] NFSD: fix use-after-free in __nfs42_ssc_open() Date: Mon, 12 Dec 2022 07:11:09 -0800 Message-Id: <1670857869-14618-1-git-send-email-dai.ngo@oracle.com> X-Mailer: git-send-email 1.8.3.1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-12_02,2022-12-12_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2212120139 X-Proofpoint-GUID: pptHuGEpwlzg-zxMcXyPWFTwff6jA7mI X-Proofpoint-ORIG-GUID: pptHuGEpwlzg-zxMcXyPWFTwff6jA7mI X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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-nfs@vger.kernel.org Problem caused by source's vfsmount being unmounted but remains on the delayed unmount list. This happens when nfs42_ssc_open() return errors. Fixed by removing nfsd4_interssc_connect(), leave the vfsmount for the laundromat to unmount when idle time expires. Removed unneeded check for NULL nfsd_net and added pr_warn if vfsmount not found on delayed unmount list. Reported-by: Xingyuan Mo Signed-off-by: Dai Ngo --- fs/nfsd/nfs4proc.c | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 8beb2bc4c328..84646df60212 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1463,13 +1463,6 @@ nfsd4_interssc_connect(struct nl4_server *nss, struct svc_rqst *rqstp, return status; } -static void -nfsd4_interssc_disconnect(struct vfsmount *ss_mnt) -{ - nfs_do_sb_deactive(ss_mnt->mnt_sb); - mntput(ss_mnt); -} - /* * Verify COPY destination stateid. * @@ -1526,10 +1519,6 @@ nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct file *filp, nfsd_file_put(dst); fput(filp); - if (!nn) { - mntput(ss_mnt); - return; - } spin_lock(&nn->nfsd_ssc_lock); timeout = msecs_to_jiffies(nfsd4_ssc_umount_timeout); list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) { @@ -1548,10 +1537,8 @@ nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct file *filp, } } spin_unlock(&nn->nfsd_ssc_lock); - if (!found) { - mntput(ss_mnt); - return; - } + if (!found) + pr_warn("vfsmount not found on delayed unmount list\n"); } #else /* CONFIG_NFSD_V4_2_INTER_SSC */ @@ -1572,11 +1559,6 @@ nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct file *filp, { } -static void -nfsd4_interssc_disconnect(struct vfsmount *ss_mnt) -{ -} - static struct file *nfs42_ssc_open(struct vfsmount *ss_mnt, struct nfs_fh *src_fh, nfs4_stateid *stateid) @@ -1762,7 +1744,7 @@ static int nfsd4_do_async_copy(void *data) struct file *filp; filp = nfs42_ssc_open(copy->ss_mnt, ©->c_fh, - ©->stateid); + ©->stateid); if (IS_ERR(filp)) { switch (PTR_ERR(filp)) { case -EBADF: @@ -1771,7 +1753,7 @@ static int nfsd4_do_async_copy(void *data) default: nfserr = nfserr_offload_denied; } - nfsd4_interssc_disconnect(copy->ss_mnt); + /* ss_mnt will be unmounted by the laundromat */ goto do_callback; } nfserr = nfsd4_do_copy(copy, filp, copy->nf_dst->nf_file, @@ -1852,8 +1834,10 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, if (async_copy) cleanup_async_copy(async_copy); status = nfserrno(-ENOMEM); - if (nfsd4_ssc_is_inter(copy)) - nfsd4_interssc_disconnect(copy->ss_mnt); + /* + * source's vfsmount of inter-copy will be unmounted + * by the laundromat + */ goto out; } -- 2.9.5