From patchwork Mon Jan 23 15:38:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Gherzan X-Patchwork-Id: 1730532 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=lgXWRNQL; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P0vRP0DPKz23gY for ; Tue, 24 Jan 2023 02:39:29 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pJyup-0003A5-34; Mon, 23 Jan 2023 15:39:23 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pJyun-00038o-IH for kernel-team@lists.ubuntu.com; Mon, 23 Jan 2023 15:39:21 +0000 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 89F52419B6 for ; Mon, 23 Jan 2023 15:39:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1674488360; bh=s2r0fqi7F1pSxiJhadD7ki27IpkuRqBv5+TvkPE/fqM=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lgXWRNQLZX3a9HZ1Zzo/WE9SAmjJzN4VKGwiVbdPxI0p7mlWIF43JPbRNY9E37YE4 MT2eg7o1KoVoqwCJ+HMHEeCtzHG0C3LEOA9pOlaJJ0irTdUntrBGZdHC9we/SviPvQ uhlcfAlPog480/Fo9sV9RdYSDO1qeDxYrXrHK1Z9Xws2s9C2tHySsxa5eE2XbA1fVe SsLVSr8n+0DHngdBQhVemEG8f6tpQ2mtt2Kz2efNkwMq+8eu5ACnP9nAdX458N+N0a uQe1sxNAq9qFeQLB5wgOJghvlhqiZpDUbr5WUDLAcOMeGUtGdDXvF8JEOlu44cP71K mkBjTWBS3hFDA== Received: by mail-wm1-f69.google.com with SMTP id p1-20020a05600c1d8100b003daff82f5edso7689658wms.8 for ; Mon, 23 Jan 2023 07:39:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s2r0fqi7F1pSxiJhadD7ki27IpkuRqBv5+TvkPE/fqM=; b=oO2sDzX1q29enapsvFOm8wHe7w8wOPlKZygNs+5LGugheWNoPmJROGMSRO8xLVI7Lt rfu9AZCpmrx53lA536Et4FcU2iPqKaGs5Aetccfyv+XEopJBs14nAhNtu18sVs5BYQrM jNUSNlMcaCN5m9XVK1k/s/3qOMg5CmHXzlYRxxeyNwzHdkB19HJq9hegnqiBepZlgq1X 9hHAYU/COwn05gHZnbM3dNnnLP5q9vtpHoErARnr2D4kPkl0GyCdsgEohdPNba4XtTI+ 3mCRmD1579JuVEJur0UeaexcsR4QWqJMitndJyG2QFSshA1LH6vYKn7DINxqsjUdnH8H FoAw== X-Gm-Message-State: AFqh2kp8SOYQWV+EbDbiIuBTHpdzkrBwXfw3DelXO6AWxyJXKBxVLobT s2hW68CLVbI/jUztXoq3UBkf2melMnfMda2VDg7RzsIHQyJOkcw5T4q2lwPbtB8yC6AH3GGFTSm XBEJnzBUpH3AWOHy7uVXz2Y5gdc5JWq1xAdSvvDrI6A== X-Received: by 2002:a05:6000:803:b0:2bd:da9b:b88f with SMTP id bt3-20020a056000080300b002bdda9bb88fmr35654372wrb.8.1674488358790; Mon, 23 Jan 2023 07:39:18 -0800 (PST) X-Google-Smtp-Source: AMrXdXsCKkx11yIeduYFedJGMBJD24WgoACO+ivX7UeLKAsy2CXBW3qTxmIA1meP0pe5Yjd2lWHV+g== X-Received: by 2002:a05:6000:803:b0:2bd:da9b:b88f with SMTP id bt3-20020a056000080300b002bdda9bb88fmr35654364wrb.8.1674488358552; Mon, 23 Jan 2023 07:39:18 -0800 (PST) Received: from localhost.localdomain ([2001:67c:1560:8007::aac:c4dd]) by smtp.gmail.com with ESMTPSA id u24-20020adfa198000000b002bc84c55758sm42093129wru.63.2023.01.23.07.39.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 07:39:18 -0800 (PST) From: Andrei Gherzan To: kernel-team@lists.ubuntu.com Subject: [SRU][Jammy][PATCH 1/1] NFSD: fix use-after-free in __nfs42_ssc_open() Date: Mon, 23 Jan 2023 15:38:44 +0000 Message-Id: <20230123153844.75571-2-andrei.gherzan@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230123153844.75571-1-andrei.gherzan@canonical.com> References: <20230123153844.75571-1-andrei.gherzan@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Dai Ngo 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. We don't need to call nfs_do_sb_deactive when nfs42_ssc_open return errors since the file was not opened so nfs_server->active was not incremented. Same as in nfsd4_copy, if we fail to launch nfsd4_do_async_copy thread then there's no need to call nfs_do_sb_deactive Reported-by: Xingyuan Mo Signed-off-by: Dai Ngo Tested-by: Xingyuan Mo Signed-off-by: Chuck Lever CVE-2022-20369 (backported from commit 75333d48f92256a0dec91dbf07835e804fc411c0) [agherzan: 1913cdf56cb5bfbc8170873728d13598cbecda23 replaces the boolean fields in nfsd4_copy which now needs adaptations for this patch to use nfsd4_ssc_is_inter, for the nfsd4_do_async_copy conflict there are multiple changes affecting the backport but the code path is simple to adapt for handling the nfsd4_interssc_disconnect call] Signed-off-by: Andrei Gherzan --- fs/nfsd/nfs4proc.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 59061da3b1d1..5043b1679353 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1348,13 +1348,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. * @@ -1457,11 +1450,6 @@ nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct nfsd_file *src, { } -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) @@ -1619,14 +1607,14 @@ static int nfsd4_do_async_copy(void *data) copy->nf_src = kzalloc(sizeof(struct nfsd_file), GFP_KERNEL); if (!copy->nf_src) { copy->nfserr = nfserr_serverfault; - nfsd4_interssc_disconnect(copy->ss_mnt); + /* ss_mnt will be unmounted by the laundromat */ goto do_callback; } copy->nf_src->nf_file = nfs42_ssc_open(copy->ss_mnt, ©->c_fh, ©->stateid); if (IS_ERR(copy->nf_src->nf_file)) { copy->nfserr = nfserr_offload_denied; - nfsd4_interssc_disconnect(copy->ss_mnt); + /* ss_mnt will be unmounted by the laundromat */ goto do_callback; } } @@ -1711,8 +1699,10 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, if (async_copy) cleanup_async_copy(async_copy); status = nfserrno(-ENOMEM); - if (!copy->cp_intra) - nfsd4_interssc_disconnect(copy->ss_mnt); + /* + * source's vfsmount of inter-copy will be unmounted + * by the laundromat + */ goto out; }