[PATCH master 4/4] fs: do not skip fs_remove when calling umount ramfs

Ahmad Fatoum a.fatoum at barebox.org
Sun Jun 22 23:20:32 PDT 2025


There's usually only a single ramfs mounted at / and given that the OS
will reclaim the memory anyway, we skip removal of ramfs.

Should further ramfs be mounted though, e.g. by tests, we run into a
use after free: fs_remove is skipped, but the unmount deallocates
the fs_device.

Fix this by only skipping removal for mounted file systems without a
remove callback when barebox_shutdown has been called.

Fixes: cf7b19df6541 ("fs: ramfs: do not bother unmounting ramfs on shutdown")
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
 fs/fs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 763f1b617460..3580bff6f5a6 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -835,9 +835,11 @@ static void fs_remove(struct device *dev)
 	int ret;
 
 	if (fsdev->dev.driver) {
-		if (!dev->driver->remove)
+		if (barebox_system_state == BAREBOX_EXITING
+		    && !dev->driver->remove)
 			return;
-		dev->driver->remove(dev);
+		if (dev->driver->remove)
+			dev->driver->remove(dev);
 		list_del(&fsdev->list);
 	}
 
-- 
2.39.5




More information about the barebox mailing list