* [PATCH 0/3] coda: check and serialize Venus replies
@ 2026-12-05 5:48 Mar Dominguez
2026-12-05 5:50 ` [PATCH 1/3] coda: bound the symlink target in venus_readlink() Mar Dominguez
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Mar Dominguez @ 2026-12-05 5:48 UTC (permalink / raw)
To: Jan Harkes, coda, codalist, Christian Brauner, Alexander Viro,
linux-fsdevel, linux-kernel
Three fixes for the Coda upcall path.
Patches 1 and 2 check the symlink target in venus_readlink() and the
pioctl output in venus_pioctl() against the size of the reply from
Venus, instead of using the offset and length in the reply as given.
Patch 3 makes coda_psdev_write() hold vc_mutex until the reply has been
copied, the request is marked done and the waiter has been woken, as
coda_psdev_read() already does. Until now a waiter that was interrupted
by a signal, or that timed out, in that window unlinked and freed the
request while coda_psdev_write() was still using it.
Tested on x86_64 with KASAN under QEMU using a minimal stand-in Venus
that sends the malformed replies and, for patch 3, interrupts the
waiting process while the reply is copied: KASAN and list-debug reports
before, none after. Not tested with the real Venus userspace, on other
architectures or on a kernel without KASAN. A reproducer is available
privately on request.
Found and written with an LLM coding assistant.
Mar Dominguez (3):
coda: bound the symlink target in venus_readlink()
coda: bound the pioctl output in venus_pioctl()
coda: hold vc_mutex while completing a Venus reply
fs/coda/psdev.c | 21 +++++++++++++++------
fs/coda/upcall.c | 23 +++++++++++++++++++----
2 files changed, 34 insertions(+), 10 deletions(-)
base-commit: 007722b8211f7b34fdf21b1e6a9c32497633ea29
--
2.53.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/3] coda: bound the symlink target in venus_readlink()
2026-12-05 5:48 [PATCH 0/3] coda: check and serialize Venus replies Mar Dominguez
@ 2026-12-05 5:50 ` Mar Dominguez
2026-12-05 5:53 ` [PATCH 2/3] coda: bound the pioctl output in venus_pioctl() Mar Dominguez
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Mar Dominguez @ 2026-12-05 5:50 UTC (permalink / raw)
To: Jan Harkes, coda, codalist, Christian Brauner, Alexander Viro,
linux-fsdevel, linux-kernel
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/3] coda: bound the pioctl output in venus_pioctl()
2026-12-05 5:48 [PATCH 0/3] coda: check and serialize Venus replies Mar Dominguez
2026-12-05 5:50 ` [PATCH 1/3] coda: bound the symlink target in venus_readlink() Mar Dominguez
@ 2026-12-05 5:53 ` 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
3 siblings, 0 replies; 6+ messages in thread
From: Mar Dominguez @ 2026-12-05 5:53 UTC (permalink / raw)
To: Jan Harkes, coda, codalist, Christian Brauner, Alexander Viro,
linux-fsdevel, linux-kernel
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@vger.kernel.org
Signed-off-by: Mar Dominguez <mar@talkjune.com>
---
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/3] coda: hold vc_mutex while completing a Venus reply
2026-12-05 5:48 [PATCH 0/3] coda: check and serialize Venus replies Mar Dominguez
2026-12-05 5:50 ` [PATCH 1/3] coda: bound the symlink target in venus_readlink() Mar Dominguez
2026-12-05 5:53 ` [PATCH 2/3] coda: bound the pioctl output in venus_pioctl() Mar Dominguez
@ 2026-12-05 5:56 ` Mar Dominguez
2026-12-05 23:20 ` [PATCH 0/3] coda: check and serialize Venus replies Jan Harkes
3 siblings, 0 replies; 6+ messages in thread
From: Mar Dominguez @ 2026-12-05 5:56 UTC (permalink / raw)
To: Jan Harkes, coda, codalist, Christian Brauner, Alexander Viro,
linux-fsdevel, linux-kernel
coda_psdev_write() unlinks the request from vc_processing under
vc_mutex, drops the mutex, and only then copies the reply from Venus
into req->uc_data, sets CODA_REQ_WRITE and wakes the waiter.
The waiter in coda_waitfor_upcall() runs under vc_mutex whenever it is
not asleep. If it is woken by a signal (SIGKILL and SIGINT are never
blocked) after the request was unlinked but before CODA_REQ_WRITE is
set, it sees neither CODA_REQ_WRITE nor CODA_REQ_ABORT and calls
list_del() on the already unlinked entry, then coda_upcall() frees req
and its caller frees req->uc_data. coda_psdev_write() then copies the
reply into the freed buffer and writes req->uc_outSize, req->uc_flags
and req->uc_sleep. A waiter whose one-second timeout expires between
the CODA_REQ_WRITE update and wake_up() frees req the same way, and
wake_up() then runs on freed memory. A failed fget() for
CODA_OPEN_BY_FD also returns without waking the waiter at all.
Keep vc_mutex held from the lookup until CODA_REQ_WRITE or
CODA_REQ_ABORT is set and the waiter is woken, as coda_psdev_read()
already does for its copy_to_user(). Set CODA_REQ_WRITE after the
CODA_OPEN_BY_FD file lookup and wake the waiter when that lookup
fails too; it then sees a NULL host file and coda_open() returns -EIO
as before.
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/psdev.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/fs/coda/psdev.c b/fs/coda/psdev.c
index 3c3148588..6af14a87c 100644
--- a/fs/coda/psdev.c
+++ b/fs/coda/psdev.c
@@ -143,7 +143,12 @@ static ssize_t coda_psdev_write(struct file *file, const char __user *buf,
goto out;
}
- /* Look for the message on the processing queue. */
+ /*
+ * Look for the message on the processing queue. Hold vc_mutex until
+ * the reply is in place and the request is marked done: the waiter
+ * in coda_waitfor_upcall() unlinks and frees an interrupted request
+ * under vc_mutex.
+ */
mutex_lock(&vcp->vc_mutex);
list_for_each(lh, &vcp->vc_processing) {
tmp = list_entry(lh, struct upc_req , uc_chain);
@@ -153,9 +158,9 @@ static ssize_t coda_psdev_write(struct file *file, const char __user *buf,
break;
}
}
- mutex_unlock(&vcp->vc_mutex);
if (!req) {
+ mutex_unlock(&vcp->vc_mutex);
pr_warn("%s: msg (%d, %d) not found\n",
__func__, hdr.opcode, hdr.unique);
retval = -ESRCH;
@@ -173,12 +178,11 @@ static ssize_t coda_psdev_write(struct file *file, const char __user *buf,
req->uc_flags |= CODA_REQ_ABORT;
wake_up(&req->uc_sleep);
retval = -EFAULT;
- goto out;
+ goto out_unlock;
}
/* adjust outsize. is this useful ?? */
req->uc_outSize = nbytes;
- req->uc_flags |= CODA_REQ_WRITE;
count = nbytes;
/* Convert filedescriptor into a file handle */
@@ -187,12 +191,17 @@ static ssize_t coda_psdev_write(struct file *file, const char __user *buf,
(struct coda_open_by_fd_out *)req->uc_data;
if (!outp->oh.result) {
outp->fh = fget(outp->fd);
- if (!outp->fh)
- return -EBADF;
+ if (!outp->fh) {
+ count = 0;
+ retval = -EBADF;
+ }
}
}
+ req->uc_flags |= CODA_REQ_WRITE;
wake_up(&req->uc_sleep);
+out_unlock:
+ mutex_unlock(&vcp->vc_mutex);
out:
return(count ? count : retval);
}
--
2.53.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/3] coda: check and serialize Venus replies
2026-12-05 5:48 [PATCH 0/3] coda: check and serialize Venus replies Mar Dominguez
` (2 preceding siblings ...)
2026-12-05 5:56 ` [PATCH 3/3] coda: hold vc_mutex while completing a Venus reply Mar Dominguez
@ 2026-12-05 23:20 ` Jan Harkes
2026-12-05 23:26 ` Mar Dominguez
3 siblings, 1 reply; 6+ messages in thread
From: Jan Harkes @ 2026-12-05 23:20 UTC (permalink / raw)
To: Mar Dominguez
Cc: Christian Brauner, Alexander Viro, linux-fsdevel, linux-kernel
On Sat, Dec 05, 2026 at 12:53:48AM -0500, Mar Dominguez wrote:
> Three fixes for the Coda upcall path.
>
> Patches 1 and 2 check the symlink target in venus_readlink() and the
> pioctl output in venus_pioctl() against the size of the reply from
> Venus, instead of using the offset and length in the reply as given.
These sanitize fields in the reply that Venus, our userspace cache manager
wrote: readlink's count/data and pioctl's len/data. In Coda, Venus is part of
the trusted computing base, it already controls the reply contents and can do
far more damage through the filesystem semantics than by handing the kernel a
bad offset. So these are not security fixes; at best they are robustness checks
against a buggy or short reply from Venus.
The checks themselves look reasonable. But they are not stable/security fixes.
Please reframe them as defensive hardening against a malfunctioning Venus and
drop the security and stable-backport language.
> Patch 3 makes coda_psdev_write() hold vc_mutex until the reply has been
> copied, the request is marked done and the waiter has been woken, as
> coda_psdev_read() already does. Until now a waiter that was interrupted
> by a signal, or that timed out, in that window unlinked and freed the
> request while coda_psdev_write() was still using it.
This is a genuine bug, but your description has some inaccuracies, the
one-second timeout is not the trigger and when CODA_REQ_WRITE is set the
waiter's flag check breaks out, so there is no free window there.
The real trigger is a signal that is handled after the request is unlinked but
before CODA_REQ_WRITE is set. It triggers an oops on a second list_del and an
UAF happens when CONFIG_DEBUG_LIST and BUG_ON_DATA_CORRUPTION=n are both set.
Your patch 3 closes that window by extending the vc_mutex across fget and
copy_from_user. Putting copy_from_user under vc_mutex adds a new lockdep false
positive wrt. mmap_lock, but we already have a similar one like that in
coda_psdev_read with copy_to_user.
It does introduce a new lockdep false positive between vc_mutex and mmap_lock,
but I looked into that and both are in different mm address spaces as long as
our userspace cache manager doesn't try to recurse onto itself by opening files
in /coda, which we obviously avoid doing.
Jan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/3] coda: check and serialize Venus replies
2026-12-05 23:20 ` [PATCH 0/3] coda: check and serialize Venus replies Jan Harkes
@ 2026-12-05 23:26 ` Mar Dominguez
0 siblings, 0 replies; 6+ messages in thread
From: Mar Dominguez @ 2026-12-05 23:26 UTC (permalink / raw)
To: Jan Harkes, Christian Brauner, Alexander Viro, linux-fsdevel,
linux-kernel
Hi Jan,
Thanks for the review and the details on both points.
I will send a v2 that:
- Reframes patches 1 and 2 as defensive checks against a buggy or short
reply from Venus and drops the security and Cc: stable language from
both.
- Fixes patch 3's changelog to describe the actual signal-interrupt
window (after the request is unlinked from vc_processing and before
CODA_REQ_WRITE is set, leading to a double list_del() oops or a UAF
when list debugging is enabled with BUG_ON_DATA_CORRUPTION=n), drops
the inaccurate timeout/post-CODA_REQ_WRITE wording, and notes the
vc_mutex/mmap_lock lockdep relationship with copy_from_user().
Best,
Mar
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-12-05 23:26 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-05 5:48 [PATCH 0/3] coda: check and serialize Venus replies Mar Dominguez
2026-12-05 5:50 ` [PATCH 1/3] coda: bound the symlink target in venus_readlink() Mar Dominguez
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
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®