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=1794590675; b=OdzTT0nZtU6uWXDNNQKYmT8vj0xPT9qwv0ZeGzu/jjoIjcue8oCCjnReLoIKyoUnbPJw M/zMQ9Y6Xtq6XWPOFgWayqYuGGsTfwXawkcMQycoOeTr41iC8/HN83fJeDO6VdJCjlUDH TMclab3WwN68RvqxaAyZgfPWWn0bpOz1V10yvKJ+a2dgMatoAQa6MncCtqTSaY8zffTFr YUBZsUQ1qqAwbUXF4hajKG5fA9q8X8CRZKn/2w65sesfelqE8zQgo3YSoh9fdT813plKo sYAD6xbE1/urWlhHjPiqXp2WQCsPnbaZFbODyW2xeG9EWjdd3buvOzrZ+NfBPYIskUA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794590675; 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=adavp3ZOB7hy+FC5oWoRL4yQ8NjAonvH1oiuBwtHqDA=; b=A6E+QlT6MQ8uIKoMWrqLGYZsnDbP6ncFT9+jYEHkQ4IQAeNaIJbEOaxD0O7jfkhgThGL k2Et7XBDvkbGqHpI75aFPP7QQ1+wgpZ2rXzH9mlcJpxo+yxODiPwLgXHW+KyIcj5jHww/ sEYYykyNu03rGVUNhrOOHVYy5XjuPoXrAj/AdtCoYkMuwuaTqxhldVxRbXR+5DOypAk1V q7CuZLttj/o9IVBM7llVW1Ta3fN8Kv/ugFtQj0Y7AYVtFhUS5K324kvoW+qy1R8VldxX/ OoJ1r0SIi8TiYqiT9Wew31w+soyUcIgjBsBZsW3LpWNIrUC6dMVp/aI9rJz5UL7I0mw== 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="pKeS/igT"; 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 6AC8E606B223; Fri, 13 Nov 2026 17:24:35 +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=pKeS/igT Received: by smtp.kernel.org (Postfix) with ESMTPSA id 168FC1F000C4; Fri, 13 Nov 2026 17:24:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794590675; bh=adavp3ZOB7hy+FC5oWoRL4yQ8NjAonvH1oiuBwtHqDA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=pKeS/igTHl8DvcAKZt/IqyRve/jyCtLXUxiluzHtmsRwMFp8/RGwmMg7UiAHXmxTk NHXlUAM80CnMFIPRnS1BFDI2Sna99T3OlpNjIK5Zy81Ab+672A9sX2DiQRnOxNkRTI jnL88wvScpNsHPbMyMBbxLyDWygIXcK5sktWl54E= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sung Byeongchan , Miklos Szeredi , Sasha Levin Subject: [PATCH 6.18 589/686] virtiofs: validate fixed-output response length Date: Fri, 13 Nov 2026 10:52:02 -0500 Message-ID: <20261113153841.821305411@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261113153820.902362109@linuxfoundation.org> References: <20261113153820.902362109@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sung Byeongchan [ Upstream commit 5364d081125a34e90851fbb46ecc93f79339ce78 ] A short successful virtiofs response can leave the fixed-output portion of the request argument buffer unwritten. The completion path nevertheless copies the full declared output to the request destination, allowing stale allocator contents to reach callers such as fuse_statfs(). Require successful fixed-output responses to contain their complete declared output. Continue to permit a shorter final argument only for out_argvar requests. Reject positive and internal restart error values and require valid error replies to be header-only. The error already stored in the FUSE output header is returned by fuse_request_end(), so do not copy output arguments from an error reply. This was found by source review with AI assistance. A header-only successful FUSE_STATFS reply returned stale fields in nine of nine calls across three boots. The fixed kernel rejected the short response and preserved complete replies, valid negative-error replies, and variable-output replies. Fixes: a62a8ef9d97d ("virtio-fs: add virtiofs filesystem") Cc: stable@vger.kernel.org Assisted-by: LLM Signed-off-by: Sung Byeongchan Signed-off-by: Miklos Szeredi Signed-off-by: Sasha Levin --- fs/fuse/virtio_fs.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c index 33962e1ad8c12..7075984a89aad 100644 --- a/fs/fuse/virtio_fs.c +++ b/fs/fuse/virtio_fs.c @@ -726,6 +726,10 @@ static void copy_args_from_argbuf(struct fuse_args *args, struct fuse_req *req) unsigned int num_out; unsigned int i; + /* fuse_request_end() returns this error; there are no args to copy. */ + if (req->out.h.error) + goto out; + remaining = req->out.h.len - sizeof(req->out.h); num_in = args->in_numargs - args->in_pages; num_out = args->out_numargs - args->out_pages; @@ -751,6 +755,7 @@ static void copy_args_from_argbuf(struct fuse_args *args, struct fuse_req *req) if (args->out_argvar) args->out_args[args->out_numargs - 1].size = remaining; +out: kfree(req->argbuf); req->argbuf = NULL; } @@ -758,7 +763,9 @@ static void copy_args_from_argbuf(struct fuse_args *args, struct fuse_req *req) /* Verify that the server properly follows the FUSE protocol */ static bool virtio_fs_verify_response(struct fuse_req *req, unsigned int len) { + struct fuse_args *args = req->args; struct fuse_out_header *oh = &req->out.h; + unsigned int expected; if (len < sizeof(*oh)) { pr_warn("virtio-fs: response too short (%u)\n", len); @@ -773,6 +780,29 @@ static bool virtio_fs_verify_response(struct fuse_req *req, unsigned int len) oh->unique, req->in.h.unique); return false; } + if (oh->error <= -ERESTARTSYS || oh->error > 0) { + pr_warn("virtio-fs: invalid error value (%d)\n", oh->error); + return false; + } + + if (oh->error) { + if (len != sizeof(*oh)) { + pr_warn("virtio-fs: error response too long (%u)\n", len); + return false; + } + return true; + } + + expected = sizeof(*oh) + + fuse_len_args(args->out_numargs, args->out_args); + if (len > expected || + (len < expected && + (!args->out_argvar || + expected - len > args->out_args[args->out_numargs - 1].size))) { + pr_warn("virtio-fs: invalid response length (%u, expected %u)\n", + len, expected); + return false; + } return true; } -- 2.53.0