From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379718; b=PykpJYr/1130T9V0zSj3yAv9MVf3ncE3mBxeNR8Ck7EQc7mw9jKNWGVGacl/zwmlH/+s Yhs8DB+d4bhsT7EG22qi9mLikoIANov7W23aHOr2QfGLYTU57cYqFH2qN8kzsCi3FJ7rq HW9sR618yMz+pwX5ky6tZtNcKwXNUSNFqXnQQHyD3c4siCy44niQU+e5uRaKm0d2TpPQm B/eWwmQwOjC4Q5Rj5D14xG7dNGcv084pPBACVQzNOYqeRro1gxfTosxScuV7Mv10q6m6w oDi3DP6zvfQgr0dgdcxAN1KcFPT5Z/oUrLTDdMICXg2IpxI/3xlyA2ZANrz/5teC6Uw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379718; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=/ciVES0Jdx0PRT13EsWjRqxR4QotXAEBM3I/Dy6cqBc=; b=VdVX2nqf6z3yfDQMqz5ot+Iv2VJ4r1axihXR/H0q6o9VnD4OjaFcqT2MrOr435bmFAm+ dPPB8IabEsKMNdMtiaOBcJ+I0AI2UkndZbryHyvLTH/PBlzpKEpPAPXtlz/nbVR2Z26ol MXyvIPuk2+yMVnmJP+lBSgq+TImsuxs3paKYlkkjiTSCXpw1tocf7gq+tzf0X47l/KJCr gRgqp423G1y1SyRhRsVoBfh8zk0JC6T4poi9LtLk0+MpjlLoKjxBwqYX/8/CBDmGaHWeu LrFHcM8gvw6e+xODdxdWHHhp00iT6PCfRmIAP7X78cLQ6OjJRMyrNmQUa20XbRcJLNg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=hVZaTlNF; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D023606A322; Fri, 4 Dec 2026 10:21:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=hVZaTlNF Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A48A1F000CE; Fri, 4 Dec 2026 10:21:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379718; bh=/ciVES0Jdx0PRT13EsWjRqxR4QotXAEBM3I/Dy6cqBc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hVZaTlNF369UqU1ZVR43LkzqrKvinIRZuinS5LmBWVJAmI4QzAp8BLOVbtBzjynBm 7yAwtsQfjo5oiMQomkW2va4L+xMz7svVVE+l9m1aHpchlR5IAA43kUq+2oMIWi4PbF 92EV1jEgVrDnucM3vw+GRUKkbRG9V/GlK8URU1Dw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Haobin Wu <853555@gmail.com>, Christian Schoenebeck , Dominique Martinet , Sasha Levin Subject: [PATCH 6.6 0040/1167] 9p: skip intermediate directory entry name copy in p9dirent_read() Date: Fri, 4 Dec 2026 18:51:07 +0900 Message-ID: <20261204100703.096583966@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Haobin Wu <853555@gmail.com> [ Upstream commit 8bb0279930cc90975f03bad4d83282613e5f57fa ] v9fs_dir_readdir_dotl() decodes each entry of a Rreaddir reply with p9dirent_read(), which parses it through p9pdu_readf("Qqbs"). The 's' conversion in p9pdu_vreadf() already allocates a NUL-terminated copy of the name from the wire buffer; p9dirent_read() then strscpy()s that copy into the fixed 256-byte p9_dirent::d_name and frees the original. The wire format carries the name length in 16 bits, so a name longer than 255 bytes is valid on the wire and may well be valid on the server's filesystem, but it makes strscpy() return -E2BIG. v9fs_dir_readdir_dotl() turns that into -EIO and aborts getdents64(), so every entry after the long one disappears from the listing. Drop the second copy: keep the string allocated by p9pdu_vreadf() in p9_dirent and let v9fs_dir_readdir_dotl(), its only user, free it once dir_emit() has consumed it. p9_dirent is a short-lived stack object, so the string's lifetime does not change. Note that the VFS only rejects names of PATH_MAX bytes or more in verify_dirent_name(), so after this change a name between NAME_MAX and PATH_MAX is returned by getdents64() even though any later lookup on it fails with -ENAMETOOLONG. The next patch skips such entries. Fixes: 7751bdb3a095 ("9p: readdir implementation for 9p2000.L") Closes: https://github.com/microsoft/WSL/issues/41192 Signed-off-by: Haobin Wu <853555@gmail.com> Reviewed-by: Christian Schoenebeck Message-ID: <20260918024851.51229-2-853555@gmail.com> Signed-off-by: Dominique Martinet Signed-off-by: Sasha Levin --- fs/9p/vfs_dir.c | 6 +++++- include/net/9p/client.h | 2 +- net/9p/protocol.c | 12 ++---------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c index 323f85352f6a4..733ec42258bc6 100644 --- a/fs/9p/vfs_dir.c +++ b/fs/9p/vfs_dir.c @@ -196,8 +196,12 @@ static int v9fs_dir_readdir_dotl(struct file *file, struct dir_context *ctx) if (!dir_emit(ctx, curdirent.d_name, strlen(curdirent.d_name), QID2INO(&curdirent.qid), - curdirent.d_type)) + curdirent.d_type)) { + kfree(curdirent.d_name); return 0; + } + + kfree(curdirent.d_name); ctx->pos = curdirent.d_off; rdir->head += err; diff --git a/include/net/9p/client.h b/include/net/9p/client.h index 78ebcf782ce57..d0fc8046cbaa5 100644 --- a/include/net/9p/client.h +++ b/include/net/9p/client.h @@ -172,7 +172,7 @@ struct p9_dirent { struct p9_qid qid; u64 d_off; unsigned char d_type; - char d_name[256]; + char *d_name; }; struct iov_iter; diff --git a/net/9p/protocol.c b/net/9p/protocol.c index 0e6603b1ec906..0a97b4de243ab 100644 --- a/net/9p/protocol.c +++ b/net/9p/protocol.c @@ -771,7 +771,7 @@ int p9dirent_read(struct p9_client *clnt, char *buf, int len, { struct p9_fcall fake_pdu; int ret; - char *nameptr; + char *nameptr = NULL; fake_pdu.size = len; fake_pdu.capacity = len; @@ -786,15 +786,7 @@ int p9dirent_read(struct p9_client *clnt, char *buf, int len, return ret; } - ret = strscpy(dirent->d_name, nameptr, sizeof(dirent->d_name)); - if (ret < 0) { - p9_debug(P9_DEBUG_ERROR, - "On the wire dirent name too long: %s\n", - nameptr); - kfree(nameptr); - return ret; - } - kfree(nameptr); + dirent->d_name = nameptr; return fake_pdu.offset; } -- 2.53.0