mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH master] fs: smhfs: fix crash when stat'ing file
@ 2025-03-26 16:59 Ahmad Fatoum
  2025-03-27  7:37 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2025-03-26 16:59 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Starting with commit 7d91d564361e ("fs: replace FILE.size by f_inode.i_size"),
struct file no longer had a size member, but instead the inode's i_size
member is used. The inode is populated by the file system core when a
file is first opened.

However, the semihosting file system creates a fake struct file to pass
to smhfs_open, which duly fails, because the inode member is
uninitialized.

Fix this for now, by faking an allocated inode as well.

The better fix would be switching to a non-legacy file system, but
that (remain)s a quest for another day.

Fixes: 7d91d564361e ("fs: replace FILE.size by f_inode.i_size")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 fs/smhfs.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/smhfs.c b/fs/smhfs.c
index e0e98f5213e9..3a3b4bdc1d94 100644
--- a/fs/smhfs.c
+++ b/fs/smhfs.c
@@ -114,12 +114,16 @@ static int smhfs_stat(struct device __always_unused *dev,
 {
 	struct file file;
 
+	file.f_inode = xzalloc(sizeof(*file.f_inode));
+
 	if (smhfs_open(NULL, &file, filename) == 0) {
 		s->st_mode = S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO;
 		s->st_size = file.f_size;
 	}
 	smhfs_close(NULL, &file);
 
+	free(file.f_inode);
+
 	return 0;
 }
 
-- 
2.39.5




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

end of thread, other threads:[~2025-03-27  7:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-26 16:59 [PATCH master] fs: smhfs: fix crash when stat'ing file Ahmad Fatoum
2025-03-27  7:37 ` Sascha Hauer

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