Skip to content

Commit cdf9941

Browse files
yangerkungregkh
authored andcommitted
ext4: fix check of inode in swap_inode_boot_loader
commit 67a1161 upstream. Before really do swap between inode and boot inode, something need to check to avoid invalid or not permitted operation, like does this inode has inline data. But the condition check should be protected by inode lock to avoid change while swapping. Also some other condition will not change between swapping, but there has no problem to do this under inode lock. Signed-off-by: yangerkun <yangerkun@huawei.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ae228ac commit cdf9941

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

‎fs/ext4/ioctl.c‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,6 @@ static long swap_inode_boot_loader(struct super_block *sb,
116116
struct inode *inode_bl;
117117
struct ext4_inode_info *ei_bl;
118118

119-
if (inode->i_nlink != 1 || !S_ISREG(inode->i_mode) ||
120-
IS_SWAPFILE(inode) || IS_ENCRYPTED(inode) ||
121-
ext4_has_inline_data(inode))
122-
return -EINVAL;
123-
124-
if (IS_RDONLY(inode) || IS_APPEND(inode) || IS_IMMUTABLE(inode) ||
125-
!inode_owner_or_capable(inode) || !capable(CAP_SYS_ADMIN))
126-
return -EPERM;
127-
128119
inode_bl = ext4_iget(sb, EXT4_BOOT_LOADER_INO, EXT4_IGET_SPECIAL);
129120
if (IS_ERR(inode_bl))
130121
return PTR_ERR(inode_bl);
@@ -137,6 +128,19 @@ static long swap_inode_boot_loader(struct super_block *sb,
137128
* that only 1 swap_inode_boot_loader is running. */
138129
lock_two_nondirectories(inode, inode_bl);
139130

131+
if (inode->i_nlink != 1 || !S_ISREG(inode->i_mode) ||
132+
IS_SWAPFILE(inode) || IS_ENCRYPTED(inode) ||
133+
ext4_has_inline_data(inode)) {
134+
err = -EINVAL;
135+
goto journal_err_out;
136+
}
137+
138+
if (IS_RDONLY(inode) || IS_APPEND(inode) || IS_IMMUTABLE(inode) ||
139+
!inode_owner_or_capable(inode) || !capable(CAP_SYS_ADMIN)) {
140+
err = -EPERM;
141+
goto journal_err_out;
142+
}
143+
140144
/* Wait for all existing dio workers */
141145
inode_dio_wait(inode);
142146
inode_dio_wait(inode_bl);

0 commit comments

Comments
 (0)