[PATCH v2 3/3] coda: hold vc_mutex while completing a Venus reply
From: Mar Dominguez
Date: Sat Dec 05 2026 - 18:39:17 EST
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@xxxxxxxxxxxxxxx
Signed-off-by: Mar Dominguez <mar@xxxxxxxxxxxx>
---
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