]>
Commit | Line | Data |
---|---|---|
5c17fab8 GKH |
1 | From c4a7dc9523b59b3e73fd522c73e95e072f876b16 Mon Sep 17 00:00:00 2001 |
2 | From: Jeongjun Park <aha310510@gmail.com> | |
3 | Date: Tue, 16 Apr 2024 03:20:48 +0900 | |
4 | Subject: nilfs2: fix OOB in nilfs_set_de_type | |
5 | ||
6 | From: Jeongjun Park <aha310510@gmail.com> | |
7 | ||
8 | commit c4a7dc9523b59b3e73fd522c73e95e072f876b16 upstream. | |
9 | ||
10 | The size of the nilfs_type_by_mode array in the fs/nilfs2/dir.c file is | |
11 | defined as "S_IFMT >> S_SHIFT", but the nilfs_set_de_type() function, | |
12 | which uses this array, specifies the index to read from the array in the | |
13 | same way as "(mode & S_IFMT) >> S_SHIFT". | |
14 | ||
15 | static void nilfs_set_de_type(struct nilfs_dir_entry *de, struct inode | |
16 | *inode) | |
17 | { | |
18 | umode_t mode = inode->i_mode; | |
19 | ||
20 | de->file_type = nilfs_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; // oob | |
21 | } | |
22 | ||
23 | However, when the index is determined this way, an out-of-bounds (OOB) | |
24 | error occurs by referring to an index that is 1 larger than the array size | |
25 | when the condition "mode & S_IFMT == S_IFMT" is satisfied. Therefore, a | |
26 | patch to resize the nilfs_type_by_mode array should be applied to prevent | |
27 | OOB errors. | |
28 | ||
29 | Link: https://lkml.kernel.org/r/20240415182048.7144-1-konishi.ryusuke@gmail.com | |
30 | Reported-by: syzbot+2e22057de05b9f3b30d8@syzkaller.appspotmail.com | |
31 | Closes: https://syzkaller.appspot.com/bug?extid=2e22057de05b9f3b30d8 | |
32 | Fixes: 2ba466d74ed7 ("nilfs2: directory entry operations") | |
33 | Signed-off-by: Jeongjun Park <aha310510@gmail.com> | |
34 | Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com> | |
35 | Tested-by: Ryusuke Konishi <konishi.ryusuke@gmail.com> | |
36 | Cc: <stable@vger.kernel.org> | |
37 | Signed-off-by: Andrew Morton <akpm@linux-foundation.org> | |
38 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
39 | --- | |
40 | fs/nilfs2/dir.c | 2 +- | |
41 | 1 file changed, 1 insertion(+), 1 deletion(-) | |
42 | ||
43 | --- a/fs/nilfs2/dir.c | |
44 | +++ b/fs/nilfs2/dir.c | |
45 | @@ -240,7 +240,7 @@ nilfs_filetype_table[NILFS_FT_MAX] = { | |
46 | ||
47 | #define S_SHIFT 12 | |
48 | static unsigned char | |
49 | -nilfs_type_by_mode[S_IFMT >> S_SHIFT] = { | |
50 | +nilfs_type_by_mode[(S_IFMT >> S_SHIFT) + 1] = { | |
51 | [S_IFREG >> S_SHIFT] = NILFS_FT_REG_FILE, | |
52 | [S_IFDIR >> S_SHIFT] = NILFS_FT_DIR, | |
53 | [S_IFCHR >> S_SHIFT] = NILFS_FT_CHRDEV, |