Skip to content

Commit d36f6ef

Browse files
harshimogalapallimcgrof
authored andcommitted
module: Fix use-after-free bug in read_file_mod_stats()
Smatch warns: kernel/module/stats.c:394 read_file_mod_stats() warn: passing freed memory 'buf' We are passing 'buf' to simple_read_from_buffer() after freeing it. Fix this by changing the order of 'simple_read_from_buffer' and 'kfree'. Fixes: df3e764 ("module: add debug stats to help identify memory pressure") Signed-off-by: Harshit Mogalapalli <[email protected]> Signed-off-by: Luis Chamberlain <[email protected]>
1 parent 44c026a commit d36f6ef

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

kernel/module/stats.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ static ssize_t read_file_mod_stats(struct file *file, char __user *user_buf,
276276
struct mod_fail_load *mod_fail;
277277
unsigned int len, size, count_failed = 0;
278278
char *buf;
279+
int ret;
279280
u32 live_mod_count, fkreads, fdecompress, fbecoming, floads;
280281
unsigned long total_size, text_size, ikread_bytes, ibecoming_bytes,
281282
idecompress_bytes, imod_bytes, total_virtual_lost;
@@ -390,8 +391,9 @@ static ssize_t read_file_mod_stats(struct file *file, char __user *user_buf,
390391
out_unlock:
391392
mutex_unlock(&module_mutex);
392393
out:
394+
ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
393395
kfree(buf);
394-
return simple_read_from_buffer(user_buf, count, ppos, buf, len);
396+
return ret;
395397
}
396398
#undef MAX_PREAMBLE
397399
#undef MAX_FAILED_MOD_PRINT

0 commit comments

Comments
 (0)