mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/3] coda: check and serialize Venus replies
@ 2026-12-05 23:31 Mar Dominguez
  2026-12-05 23:33 ` [PATCH v2 1/3] coda: bound the symlink target in venus_readlink() Mar Dominguez
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Mar Dominguez @ 2026-12-05 23:31 UTC (permalink / raw)
  To: Jan Harkes, coda, codalist, Christian Brauner, Alexander Viro,
	linux-fsdevel, linux-kernel

Three changes for the Coda upcall path.

Patches 1 and 2 add defensive bounds checks on 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 fixes a race in coda_psdev_write() by holding vc_mutex until
the reply has been copied, any CODA_OPEN_BY_FD file lookup has
finished, the request is marked done, and the waiter has been woken.
Until now a waiter interrupted by a signal after the request was
unlinked from vc_processing and before CODA_REQ_WRITE was set could
call list_del() a second time (causing an oops, or a use-after-free
when list debugging is enabled with BUG_ON_DATA_CORRUPTION=n).

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.

---
Changes in v2:
- Patches 1 and 2: Reframed as defensive hardening against a buggy or
  short reply from Venus; dropped security wording, Fixes, and
  stable-backport tags (per Jan Harkes).
- Patch 3: Corrected the commit description to reflect the actual
  signal-interrupt trigger between unlink and CODA_REQ_WRITE, dropped
  the inaccurate timeout/post-CODA_REQ_WRITE wording, and noted the
  vc_mutex/mmap_lock lockdep relationship with copy_from_user() (per
  Jan Harkes).
- Rebased onto current mainline (0fbf78feb38a); no code changes from v1.

v1: https://lore.kernel.org/linux-fsdevel/4tunabGBgBhPxJPJjae4oObi5JWoQRidatkh@talkjune.com/

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: 0fbf78feb38a18c9eb49f67ad3d3095d11c46295
-- 
2.53.0



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/3] coda: bound the symlink target in venus_readlink()
  2026-12-05 23:31 [PATCH v2 0/3] coda: check and serialize Venus replies Mar Dominguez
@ 2026-12-05 23:33 ` Mar Dominguez
  2026-12-05 23:36 ` [PATCH v2 2/3] coda: bound the pioctl output in venus_pioctl() Mar Dominguez
  2026-12-05 23:39 ` [PATCH v2 3/3] coda: hold vc_mutex while completing a Venus reply Mar Dominguez
  2 siblings, 0 replies; 4+ messages in thread
From: Mar Dominguez @ 2026-12-05 23:33 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 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@talkjune.com>
---
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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 2/3] coda: bound the pioctl output in venus_pioctl()
  2026-12-05 23:31 [PATCH v2 0/3] coda: check and serialize Venus replies Mar Dominguez
  2026-12-05 23:33 ` [PATCH v2 1/3] coda: bound the symlink target in venus_readlink() Mar Dominguez
@ 2026-12-05 23:36 ` Mar Dominguez
  2026-12-05 23:39 ` [PATCH v2 3/3] coda: hold vc_mutex while completing a Venus reply Mar Dominguez
  2 siblings, 0 replies; 4+ messages in thread
From: Mar Dominguez @ 2026-12-05 23:36 UTC (permalink / raw)
  To: Jan Harkes, coda, codalist, Christian Brauner, Alexander Viro,
	linux-fsdevel, linux-kernel

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 <mar@talkjune.com>
---
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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 3/3] coda: hold vc_mutex while completing a Venus reply
  2026-12-05 23:31 [PATCH v2 0/3] coda: check and serialize Venus replies Mar Dominguez
  2026-12-05 23:33 ` [PATCH v2 1/3] coda: bound the symlink target in venus_readlink() Mar Dominguez
  2026-12-05 23:36 ` [PATCH v2 2/3] coda: bound the pioctl output in venus_pioctl() Mar Dominguez
@ 2026-12-05 23:39 ` Mar Dominguez
  2 siblings, 0 replies; 4+ messages in thread
From: Mar Dominguez @ 2026-12-05 23:39 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 a signal is handled after coda_psdev_write() has
unlinked the request from vc_processing and dropped vc_mutex, but
before CODA_REQ_WRITE is set, the waiter sees neither CODA_REQ_WRITE
nor CODA_REQ_ABORT and calls list_del() a second time on the already
unlinked entry. That triggers an oops on the poisoned list pointers,
or -- when CONFIG_DEBUG_LIST or CONFIG_LIST_HARDENED is enabled with
CONFIG_BUG_ON_DATA_CORRUPTION=n -- skips the second list_del() and
lets coda_upcall() free req and its caller free req->uc_data while
coda_psdev_write() is still copying into req->uc_data and updating
req->uc_outSize, req->uc_flags and req->uc_sleep. A failed fget() for
CODA_OPEN_BY_FD also returns without waking the waiter at all.

Keep vc_mutex held from the lookup until copy_from_user(), any
CODA_OPEN_BY_FD fget(), setting CODA_REQ_WRITE or CODA_REQ_ABORT, and
waking the waiter have completed. Holding vc_mutex across
copy_from_user() has the same lockdep relationship with mmap_lock that
coda_psdev_read() already has with copy_to_user(); the locks belong to
separate mm address spaces as long as Venus does not recurse onto
/coda. 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>
---
Changes in v2:
- Corrected the changelog to describe the signal-interrupt trigger
  between unlink and CODA_REQ_WRITE (oops on second list_del() or UAF
  with list debugging and BUG_ON_DATA_CORRUPTION=n), dropped the
  inaccurate timeout/post-CODA_REQ_WRITE wording, and noted the
  vc_mutex/mmap_lock lockdep relationship with copy_from_user().
- No code changes.

 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] 4+ messages in thread

end of thread, other threads:[~2026-12-05 23:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-05 23:31 [PATCH v2 0/3] coda: check and serialize Venus replies Mar Dominguez
2026-12-05 23:33 ` [PATCH v2 1/3] coda: bound the symlink target in venus_readlink() Mar Dominguez
2026-12-05 23:36 ` [PATCH v2 2/3] coda: bound the pioctl output in venus_pioctl() Mar Dominguez
2026-12-05 23:39 ` [PATCH v2 3/3] coda: hold vc_mutex while completing a Venus reply 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®