venus_pioctl() checks the OUT data returned by Venus with if (outsize < (long)outp->coda_ioctl.data + outp->coda_ioctl.len) in signed arithmetic. A malfunctioning Venus returning a negative offset or an offset whose sum with len wraps signed long bypasses the check and causes copy_to_user() to read outside the reply buffer. As defensive hardening against a buggy or short reply from Venus, check that the reply holds struct coda_ioctl_out and validate the offset and length as unsigned values against the reply size, as venus_readlink() now does. Found and written with an LLM coding assistant. Signed-off-by: Mar Dominguez --- 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 | 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