mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Mar Dominguez" <mar@talkjune.com>
To: "Jan Harkes" <jaharkes@cs.cmu.edu>,
	coda@cs.cmu.edu, codalist@coda.cs.cmu.edu,
	"Christian Brauner" <brauner@kernel.org>,
	"Alexander Viro" <viro@zeniv.linux.org.uk>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/3] coda: bound the symlink target in venus_readlink()
Date: Sat, 05 Dec 2026 05:50:46 +0000	[thread overview]
Message-ID: <CAtD15okso9TXEZK8vrRecPdmQxfOYaArhfY@talkjune.com> (raw)
In-Reply-To: <4tunabGBgBhPxJPJjae4oObi5JWoQRidatkh@talkjune.com>

venus_readlink() copies the link target from the reply Venus wrote at
the offset Venus put in coda_readlink.data, for coda_readlink.count
bytes. Neither is checked against the size of the reply. count is
only clamped from above, to the PAGE_SIZE - 1 the folio can hold, so
a negative count turns into a huge memcpy() length, and data is used
as an arbitrary 64-bit offset from the reply buffer, so the folio
receives whatever kernel memory that offset points at. readlink() then
returns it to any user who can read the symlink.

Reject a reply that is shorter than struct coda_readlink_out, has a
negative count, or whose target does not lie within the reply.

Found and written with an LLM coding assistant.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Mar Dominguez <mar@talkjune.com>
---
 fs/coda/upcall.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/fs/coda/upcall.c b/fs/coda/upcall.c
index 3438119b5..8cf688a04 100644
--- a/fs/coda/upcall.c
+++ b/fs/coda/upcall.c
@@ -361,15 +361,25 @@ int venus_readlink(struct super_block *sb, struct CodaFid *fid,
 
 	error = coda_upcall(coda_vcp(sb), insize, &outsize, inp);
 	if (!error) {
+		size_t replen = outsize;
+		size_t offset = (unsigned long)outp->coda_readlink.data;
+
 		retlen = outp->coda_readlink.count;
+		/* The link target must lie within the reply Venus wrote. */
+		if (replen < sizeof(struct coda_readlink_out) || retlen < 0 ||
+		    offset > replen || retlen > replen - offset) {
+			error = -EINVAL;
+			goto exit;
+		}
 		if (retlen >= *length)
 			retlen = *length - 1;
 		*length = retlen;
-		result =  (char *)outp + (long)outp->coda_readlink.data;
+		result =  (char *)outp + offset;
 		memcpy(buffer, result, retlen);
 		*(buffer + retlen) = '\0';
 	}
 
+exit:
 	kvfree(inp);
         return error;
 }
-- 
2.53.0



  reply	other threads:[~2026-12-05  5:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  5:48 [PATCH 0/3] coda: check and serialize Venus replies Mar Dominguez
2026-12-05  5:50 ` Mar Dominguez [this message]
2026-12-05  5:53 ` [PATCH 2/3] coda: bound the pioctl output in venus_pioctl() Mar Dominguez
2026-12-05  5:56 ` [PATCH 3/3] coda: hold vc_mutex while completing a Venus reply Mar Dominguez
2026-12-05 23:20 ` [PATCH 0/3] coda: check and serialize Venus replies Jan Harkes
2026-12-05 23:26   ` Mar Dominguez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAtD15okso9TXEZK8vrRecPdmQxfOYaArhfY@talkjune.com \
    --to=mar@talkjune.com \
    --cc=brauner@kernel.org \
    --cc=coda@cs.cmu.edu \
    --cc=codalist@coda.cs.cmu.edu \
    --cc=jaharkes@cs.cmu.edu \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®