* [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
* Re: [PATCH master] fs: smhfs: fix crash when stat'ing file
2025-03-26 16:59 [PATCH master] fs: smhfs: fix crash when stat'ing file Ahmad Fatoum
@ 2025-03-27 7:37 ` Sascha Hauer
0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2025-03-27 7:37 UTC (permalink / raw)
To: barebox, Ahmad Fatoum
On Wed, 26 Mar 2025 17:59:49 +0100, Ahmad Fatoum wrote:
> 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.
>
> [...]
Applied, thanks!
[1/1] fs: smhfs: fix crash when stat'ing file
https://git.pengutronix.de/cgit/barebox/commit/?id=3c57263db03b (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ 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