Skip to content

Commit c4a7dc9

Browse files
name2965akpm00
authored andcommitted
nilfs2: fix OOB in nilfs_set_de_type
The size of the nilfs_type_by_mode array in the fs/nilfs2/dir.c file is defined as "S_IFMT >> S_SHIFT", but the nilfs_set_de_type() function, which uses this array, specifies the index to read from the array in the same way as "(mode & S_IFMT) >> S_SHIFT". static void nilfs_set_de_type(struct nilfs_dir_entry *de, struct inode *inode) { umode_t mode = inode->i_mode; de->file_type = nilfs_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; // oob } However, when the index is determined this way, an out-of-bounds (OOB) error occurs by referring to an index that is 1 larger than the array size when the condition "mode & S_IFMT == S_IFMT" is satisfied. Therefore, a patch to resize the nilfs_type_by_mode array should be applied to prevent OOB errors. Link: https://lkml.kernel.org/r/[email protected] Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=2e22057de05b9f3b30d8 Fixes: 2ba466d ("nilfs2: directory entry operations") Signed-off-by: Jeongjun Park <[email protected]> Signed-off-by: Ryusuke Konishi <[email protected]> Tested-by: Ryusuke Konishi <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 8247bf1 commit c4a7dc9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fs/nilfs2/dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ nilfs_filetype_table[NILFS_FT_MAX] = {
240240

241241
#define S_SHIFT 12
242242
static unsigned char
243-
nilfs_type_by_mode[S_IFMT >> S_SHIFT] = {
243+
nilfs_type_by_mode[(S_IFMT >> S_SHIFT) + 1] = {
244244
[S_IFREG >> S_SHIFT] = NILFS_FT_REG_FILE,
245245
[S_IFDIR >> S_SHIFT] = NILFS_FT_DIR,
246246
[S_IFCHR >> S_SHIFT] = NILFS_FT_CHRDEV,

0 commit comments

Comments
 (0)