diff mbox series

[4/4] fs: ubifs: Add volume mounted check

Message ID 20240703101258.1670825-5-ada@thorsis.com
State Accepted
Commit ca1f11d8c11dacd91c3bfd8e39d41db349e83f8b
Delegated to: Heiko Schocher
Headers show
Series fs: ubifs: Fix crash and add safeguards | expand

Commit Message

Alexander Dahl July 3, 2024, 10:12 a.m. UTC
Safety guard in the U-Boot filesystem glue code, because these functions
are called from different parts of the codebase.  For generic filesystem
handling this should have been checked in blk_get_device_part_str()
already.  Commands from cmd/ubifs.c should also check this before
calling those functions, but you never know?!

Signed-off-by: Alexander Dahl <ada@thorsis.com>
---
 fs/ubifs/ubifs.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
diff mbox series

Patch

diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c
index 506e29958c3..9722cc440ab 100644
--- a/fs/ubifs/ubifs.c
+++ b/fs/ubifs/ubifs.c
@@ -573,6 +573,11 @@  int ubifs_ls(const char *filename)
 	unsigned long inum;
 	int ret = 0;
 
+	if (!ubifs_is_mounted()) {
+		debug("UBIFS not mounted, use ubifsmount to mount volume first!\n");
+		return -1;
+	}
+
 	inum = ubifs_findfile(ubifs_sb, (char *)filename);
 	if (!inum) {
 		ret = -1;
@@ -613,6 +618,11 @@  int ubifs_exists(const char *filename)
 {
 	unsigned long inum;
 
+	if (!ubifs_is_mounted()) {
+		debug("UBIFS not mounted, use ubifsmount to mount volume first!\n");
+		return -1;
+	}
+
 	inum = ubifs_findfile(ubifs_sb, (char *)filename);
 
 	return inum != 0;
@@ -624,6 +634,11 @@  int ubifs_size(const char *filename, loff_t *size)
 	struct inode *inode;
 	int err = 0;
 
+	if (!ubifs_is_mounted()) {
+		debug("UBIFS not mounted, use ubifsmount to mount volume first!\n");
+		return -1;
+	}
+
 	inum = ubifs_findfile(ubifs_sb, (char *)filename);
 	if (!inum) {
 		err = -1;
@@ -827,6 +842,11 @@  int ubifs_read(const char *filename, void *buf, loff_t offset,
 	int count;
 	int last_block_size = 0;
 
+	if (!ubifs_is_mounted()) {
+		debug("UBIFS not mounted, use ubifsmount to mount volume first!\n");
+		return -1;
+	}
+
 	*actread = 0;
 
 	if (offset & (PAGE_SIZE - 1)) {