[PATCH master] fs: smhfs: fix crash when stat'ing file
Ahmad Fatoum
a.fatoum at pengutronix.de
Wed Mar 26 09:59:49 PDT 2025
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 at 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
More information about the barebox
mailing list