Skip to contentSkip to conversation

cobalt/vfile: Plug race while opening

PATCH New Jan Kiszka 1 participant 1 message Feb 24, 2025

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 cobalt/vfile: Plug race while opening

From: Jan Kiszka <[email protected]>

The procfs does not ensure atomicity of the open handlers. Therefore, it is possible that two instances enter successfully because we check for concurrency early but only mark a vfile as used at the end of the handler. When we run into that, the refcnt may underflow on cleanup:

kernel BUG at ../kernel/xenomai/vfile.c:555!

Protect that path via a regular Linux mutex.

---
 include/cobalt/kernel/vfile.h |  1 +
 kernel/cobalt/vfile.c         | 61 ++++++++++++++++++++++++-----------
 2 files changed, 43 insertions(+), 19 deletions(-)
include/cobalt/kernel/vfile.h +1 -0
index a53c237759..b0a5dce7bf 100644
@@ -39,6 +39,7 @@ struct xnvfile {
 	struct proc_dir_entry *pde;
 	struct file *file;
 	struct xnvfile_lock_ops *lockops;
+	struct mutex mutex;
 	int refcnt;
 	void *private;
 };
kernel/cobalt/vfile.c +42 -19

130 lines not on this page · raw message

Signature · 1 line
2.43.0