[PATCH 1/3] coda: bound the symlink target in venus_readlink()
From: Mar Dominguez
Date: Sat Dec 05 2026 - 00:50:55 EST
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@xxxxxxxxxxxxxxx
Signed-off-by: Mar Dominguez <mar@xxxxxxxxxxxx>
---
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