mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/4] fs: don't free device in remove callback
@ 2020-09-14 13:06 Sascha Hauer
  2020-09-14 13:06 ` [PATCH 2/4] fs: Drop unnecessary dput() Sascha Hauer
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Sascha Hauer @ 2020-09-14 13:06 UTC (permalink / raw)
  To: Barebox List; +Cc: Ahmad Fatoum

From: Ahmad Fatoum <ahmad@a3f.at>

The probe doesn't allocate the device, so remove shouldn't free it
either. This fixes a use-after-free on barebox shutdown:
Iterating over the list of devices requires that remove callbacks
don't remove the devices. This happened to work so far, because
apparently not much new allocations are going on during barebox
shutdown, but let's do it right.

Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
 fs/fs.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index e04cadfe5d..30b835e265 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -679,7 +679,6 @@ static void fs_remove(struct device_d *dev)
 	mntput(fsdev->vfsmount.parent);
 
 	free(fsdev->backingstore);
-	free(fsdev);
 }
 
 struct bus_type fs_bus = {
@@ -759,10 +758,18 @@ static void init_super(struct super_block *sb)
 
 static int fsdev_umount(struct fs_device_d *fsdev)
 {
+	int ret;
+
 	if (fsdev->vfsmount.ref)
 		return -EBUSY;
 
-	return unregister_device(&fsdev->dev);
+	ret = unregister_device(&fsdev->dev);
+	if (ret)
+		return ret;
+
+	free(fsdev);
+
+	return 0;
 }
 
 /**
-- 
2.28.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-09-16 10:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-14 13:06 [PATCH 1/4] fs: don't free device in remove callback Sascha Hauer
2020-09-14 13:06 ` [PATCH 2/4] fs: Drop unnecessary dput() Sascha Hauer
2020-09-14 13:06 ` [PATCH 3/4] fs: Fix use after free Sascha Hauer
2020-09-14 13:06 ` [PATCH 4/4] fs: free unused dentries Sascha Hauer
2020-09-15  5:25   ` Ahmad Fatoum
2020-09-15  7:12     ` Sascha Hauer
2020-09-15  8:01       ` Ahmad Fatoum
2020-09-15 13:12         ` Sascha Hauer
2020-09-15 13:28           ` Ahmad Fatoum
2020-09-16 10:43             ` Ahmad Fatoum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox