[PATCH 2/3] coda: bound the pioctl output in venus_pioctl()
From: Mar Dominguez
Date: Sat Dec 05 2026 - 00:53:32 EST
venus_pioctl() checks the OUT data Venus returned with
if (outsize < (long)outp->coda_ioctl.data + outp->coda_ioctl.len)
in signed arithmetic. A negative data offset passes it, and so does a
large one whose sum with len wraps negative. copy_to_user() then copies
len bytes from that offset relative to the reply buffer, which can be
any kernel address, to the caller's buffer.
Check the offset and length as unsigned values against the size of the
reply, as venus_readlink() now does.
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 | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/fs/coda/upcall.c b/fs/coda/upcall.c
index 8cf688a04..d3c60017f 100644
--- a/fs/coda/upcall.c
+++ b/fs/coda/upcall.c
@@ -489,6 +489,7 @@ int venus_pioctl(struct super_block *sb, struct CodaFid *fid,
union outputArgs *outp;
int insize, outsize, error;
int iocsize;
+ size_t replen, offset;
insize = VC_MAXMSGSIZE;
UPARG(CODA_IOCTL);
@@ -533,7 +534,12 @@ int venus_pioctl(struct super_block *sb, struct CodaFid *fid,
goto exit;
}
- if (outsize < (long)outp->coda_ioctl.data + outp->coda_ioctl.len) {
+ /* The OUT data must lie within the reply Venus wrote. */
+ replen = outsize;
+ offset = (unsigned long)outp->coda_ioctl.data;
+ if (replen < sizeof(struct coda_ioctl_out) ||
+ outp->coda_ioctl.len < 0 || offset > replen ||
+ outp->coda_ioctl.len > replen - offset) {
error = -EINVAL;
goto exit;
}
@@ -545,8 +551,7 @@ int venus_pioctl(struct super_block *sb, struct CodaFid *fid,
}
/* Copy out the OUT buffer. */
- if (copy_to_user(data->vi.out,
- (char *)outp + (long)outp->coda_ioctl.data,
+ if (copy_to_user(data->vi.out, (char *)outp + offset,
outp->coda_ioctl.len)) {
error = -EFAULT;
goto exit;
--
2.53.0