diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2021-05-03 13:49:01 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2021-05-12 08:00:00 +0200 |
commit | 7ef2912d40b52202f563806fbffb9f615d2d2220 (patch) | |
tree | 5d68688c15dd1703e362903963b3106038a7ec4c | |
parent | 00e5e596df0b6db478bad982fd38867bd5582e76 (diff) | |
download | barebox-7ef2912d40b52202f563806fbffb9f615d2d2220.tar.gz barebox-7ef2912d40b52202f563806fbffb9f615d2d2220.tar.xz |
fs: error out when writing on read-only file system
On an ext4 partition, Running
echo -a /mnt/disk0.0/file test
will crash barebox because fsdrv->truncate in __write is NULL.
Don't let it come to this and verify earlier that the FS implements
->write. While at it, explicitly compare with O_RDONLY (== 0) for
clarity.
Fixes: b3fbfad7aeaf ("fs: dentry cache implementation")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Link: https://lore.barebox.org/20210503114901.13095-17-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | fs/fs.c | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -321,13 +321,13 @@ static ssize_t __write(FILE *f, const void *buf, size_t count) struct fs_driver_d *fsdrv; int ret; - if (!(f->flags & O_ACCMODE)) { + fsdrv = f->fsdev->driver; + + if ((f->flags & O_ACCMODE) == O_RDONLY || !fsdrv->write) { ret = -EBADF; goto out; } - fsdrv = f->fsdev->driver; - if (fsdrv != ramfs_driver) assert_command_context(); |