summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-07-05 00:27:38 +0000
committerIan Moffett <ian@osmora.org>2025-07-05 00:27:38 +0000
commit6856d7533b4cec8d35639578b02578f28f3699bc (patch)
tree6cabb25b5efe509a3b21c2478c011a4b537c27ee /sys
parentac875d0caffd12074e0a7eedac1cadbf204a847a (diff)
kernel: tmpfs: Prevent read() on empty files
If we have never written to a tmpfs file, the buffer for it will have never been allocated and that would lead to NULL pointer issues such as system-wide crashes. Return zero bytes read if nothing was ever written. Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys')
-rw-r--r--sys/fs/tmpfs.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/sys/fs/tmpfs.c b/sys/fs/tmpfs.c
index 21dd7b5..6ae1c38 100644
--- a/sys/fs/tmpfs.c
+++ b/sys/fs/tmpfs.c
@@ -318,6 +318,15 @@ tmpfs_read(struct vnode *vp, struct sio_txn *sio)
return -EIO;
}
+ /*
+ * The node data is only allocated during writes, if
+ * we read this file before a write was ever done to it,
+ * np->data will be NULL. We must handle this.
+ */
+ if (np->data == NULL) {
+ return 0;
+ }
+
/* Is this even a regular file? */
if (np->type != VREG) {
return -EISDIR;