[PATCH v2 1/3] coda: bound the symlink target in venus_readlink()
From: Mar Dominguez
Date: Sat Dec 05 2026 - 18:33:59 EST
venus_readlink() copies the link target from the reply buffer using
coda_readlink.data as an offset and coda_readlink.count as a length,
without checking either against the reply size returned by Venus.
count is only clamped from above to *length - 1, so a malfunctioning
Venus returning a short reply, a negative count, or an out-of-range
offset would cause venus_readlink() to read past the reply buffer or
pass a negative length to memcpy().
As defensive hardening against a buggy or short reply from Venus,
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.
Signed-off-by: Mar Dominguez <mar@xxxxxxxxxxxx>
---
Changes in v2:
- Reframed as defensive hardening against a buggy or short reply from
Venus and dropped security wording, Fixes:, and Cc: stable.
- No code changes.
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