Skip to content

Commit bcf85fc

Browse files
thejhtorvalds
authored andcommitted
romfs: fix uninitialized memory leak in romfs_dev_read()
romfs has a superblock field that limits the size of the filesystem; data beyond that limit is never accessed. romfs_dev_read() fetches a caller-supplied number of bytes from the backing device. It returns 0 on success or an error code on failure; therefore, its API can't represent short reads, it's all-or-nothing. However, when romfs_dev_read() detects that the requested operation would cross the filesystem size limit, it currently silently truncates the requested number of bytes. This e.g. means that when the content of a file with size 0x1000 starts one byte before the filesystem size limit, ->readpage() will only fill a single byte of the supplied page while leaving the rest uninitialized, leaking that uninitialized memory to userspace. Fix it by returning an error code instead of truncating the read when the requested read operation would go beyond the end of the filesystem. Fixes: da4458b ("NOMMU: Make it possible for RomFS to use MTD devices directly") Signed-off-by: Jann Horn <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Reviewed-by: Greg Kroah-Hartman <[email protected]> Cc: David Howells <[email protected]> Cc: <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent 86f54bb commit bcf85fc

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

fs/romfs/storage.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,8 @@ int romfs_dev_read(struct super_block *sb, unsigned long pos,
217217
size_t limit;
218218

219219
limit = romfs_maxsize(sb);
220-
if (pos >= limit)
220+
if (pos >= limit || buflen > limit - pos)
221221
return -EIO;
222-
if (buflen > limit - pos)
223-
buflen = limit - pos;
224222

225223
#ifdef CONFIG_ROMFS_ON_MTD
226224
if (sb->s_mtd)

0 commit comments

Comments
 (0)