From nobody Mon May 25 05:12:55 2026 Received: from cstnet.cn (smtp81.cstnet.cn [159.226.251.81]) (using TLSv1.2 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B2D62D8378; Mon, 18 May 2026 15:31:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.226.251.81 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779118275; cv=none; b=qTeEvp7dn7+TTmMD4vKQk0Qg3IDcfIqKvQflKqEEWJqaA2EaS0A1M+Y4jatMf6iWLN2zrsp9IwYTdx35eEQmobwKVJai4WUmGTjg3deXLxirUkulooWsHVqzRqVVdwHHwWF+QDPy6CAzjluPuZlDDyfU4ztvWiWhSy4sqOG/Hgk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779118275; c=relaxed/simple; bh=qhbDMOvMPQeHRe/9aaGcQ3ujNEB6olbTTpOnMHb3mOk=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=fnkkvkOz8wJPA56q3coXsHZrNhJKlJPprFJ1bSF7AWRavrE3BnDlPyeIICZkx9juW6Rd7Hoxb92EWFE4vFwQwhLLddvXefspFhLdV7MM6IrnuphMwNF84C5f66mlzPqjyHHuYWXdK5Wn9ErW6b/GFq0k9qwniuSMrNcTv5UbEhg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn; spf=pass smtp.mailfrom=iscas.ac.cn; arc=none smtp.client-ip=159.226.251.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iscas.ac.cn Received: from dfae2b116770.home.arpa (unknown [36.110.52.2]) by APP-03 (Coremail) with SMTP id rQCowAAHKN+rMAtq0WBoEQ--.4645S2; Mon, 18 May 2026 23:30:51 +0800 (CST) From: Wentao Liang To: Chuck Lever , Jeff Layton Cc: NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, Wentao Liang , stable@vger.kernel.org Subject: [PATCH] nfsd: fix use-after-free in nfsd4_lock() when releasing new lock stateid Date: Mon, 18 May 2026 15:30:48 +0000 Message-Id: <20260518153048.1343021-1-vulab@iscas.ac.cn> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: rQCowAAHKN+rMAtq0WBoEQ--.4645S2 X-Coremail-Antispam: 1UD129KBjvJXoW7ZrWrKrW7tF13Wr4fWrWxJFb_yoW8WrWrpr s7Ja13KFWUXF4IqFsrZ3yUZFn5Gw1Fgr15Kryvq39Iyws3Xr13WryF934q9w4qvrWxXa1D XF1Dtws8Ww4DX3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9014x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r4j6ryUM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j 6F4UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s 0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xII jxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWxJVW8Jr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628v n2kIc2xKxwCY1x0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7x kEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E 67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCw CI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1x MIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIda VFxhVjvjDU0xZFpf9x0JUZtxDUUUUU= X-CM-SenderInfo: pyxotu46lvutnvoduhdfq/1tbiBwkLA2oLKugMcgAAsb Content-Type: text/plain; charset="utf-8" When processing a new lock request that fails with an error, nfsd4_lock() may call release_lock_stateid() on a newly created lock stateid. release_lock_stateid() can free the stateid via nfs4_put_stid() if it is the last reference, but the caller subsequently accesses lock_stp->st_mutex and lock_stp->st_stid, leading to a use-after-free. Fix this by moving mutex_unlock() before release_lock_stateid() and jumping over the remaining lock_stp cleanup after release, since release_lock_stateid() already handles the final put. This ensures no further access to lock_stp after it may be freed. Fixes: 5db1c03feb00 ("nfsd: clean up lockowner refcounting when finding the= m") Cc: stable@vger.kernel.org Signed-off-by: Wentao Liang --- fs/nfsd/nfs4state.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 88c347957da5..cef9d8ddfc43 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -8388,13 +8388,18 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_com= pound_state *cstate, * If this is a new, never-before-used stateid, and we are * returning an error, then just go ahead and release it. */ - if (status && new) + if (status && new) { + mutex_unlock(&lock_stp->st_mutex); release_lock_stateid(lock_stp); + goto out_no_lock_stp; + } =20 mutex_unlock(&lock_stp->st_mutex); =20 nfs4_put_stid(&lock_stp->st_stid); } + +out_no_lock_stp: if (open_stp) nfs4_put_stid(&open_stp->st_stid); nfsd4_bump_seqid(cstate, status); --=20 2.34.1