Commit 4010a528 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'fixes_for_v5.14-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs

Pull ext2 and reiserfs fixes from Jan Kara:
 "A fix for the ext2 conversion to kmap_local() and two reiserfs
  hardening fixes"

* tag 'fixes_for_v5.14-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs:
  reiserfs: check directory items on read from disk
  fs/ext2: Avoid page_address on pages returned by ext2_get_page
  reiserfs: add check for root_inode in reiserfs_fill_super
parents dfe49536 13d25750
...@@ -106,12 +106,11 @@ static int ext2_commit_chunk(struct page *page, loff_t pos, unsigned len) ...@@ -106,12 +106,11 @@ static int ext2_commit_chunk(struct page *page, loff_t pos, unsigned len)
return err; return err;
} }
static bool ext2_check_page(struct page *page, int quiet) static bool ext2_check_page(struct page *page, int quiet, char *kaddr)
{ {
struct inode *dir = page->mapping->host; struct inode *dir = page->mapping->host;
struct super_block *sb = dir->i_sb; struct super_block *sb = dir->i_sb;
unsigned chunk_size = ext2_chunk_size(dir); unsigned chunk_size = ext2_chunk_size(dir);
char *kaddr = page_address(page);
u32 max_inumber = le32_to_cpu(EXT2_SB(sb)->s_es->s_inodes_count); u32 max_inumber = le32_to_cpu(EXT2_SB(sb)->s_es->s_inodes_count);
unsigned offs, rec_len; unsigned offs, rec_len;
unsigned limit = PAGE_SIZE; unsigned limit = PAGE_SIZE;
...@@ -205,7 +204,8 @@ static struct page * ext2_get_page(struct inode *dir, unsigned long n, ...@@ -205,7 +204,8 @@ static struct page * ext2_get_page(struct inode *dir, unsigned long n,
if (!IS_ERR(page)) { if (!IS_ERR(page)) {
*page_addr = kmap_local_page(page); *page_addr = kmap_local_page(page);
if (unlikely(!PageChecked(page))) { if (unlikely(!PageChecked(page))) {
if (PageError(page) || !ext2_check_page(page, quiet)) if (PageError(page) || !ext2_check_page(page, quiet,
*page_addr))
goto fail; goto fail;
} }
} }
...@@ -584,10 +584,10 @@ int ext2_add_link (struct dentry *dentry, struct inode *inode) ...@@ -584,10 +584,10 @@ int ext2_add_link (struct dentry *dentry, struct inode *inode)
* ext2_delete_entry deletes a directory entry by merging it with the * ext2_delete_entry deletes a directory entry by merging it with the
* previous entry. Page is up-to-date. * previous entry. Page is up-to-date.
*/ */
int ext2_delete_entry (struct ext2_dir_entry_2 * dir, struct page * page ) int ext2_delete_entry (struct ext2_dir_entry_2 *dir, struct page *page,
char *kaddr)
{ {
struct inode *inode = page->mapping->host; struct inode *inode = page->mapping->host;
char *kaddr = page_address(page);
unsigned from = ((char*)dir - kaddr) & ~(ext2_chunk_size(inode)-1); unsigned from = ((char*)dir - kaddr) & ~(ext2_chunk_size(inode)-1);
unsigned to = ((char *)dir - kaddr) + unsigned to = ((char *)dir - kaddr) +
ext2_rec_len_from_disk(dir->rec_len); ext2_rec_len_from_disk(dir->rec_len);
...@@ -607,7 +607,7 @@ int ext2_delete_entry (struct ext2_dir_entry_2 * dir, struct page * page ) ...@@ -607,7 +607,7 @@ int ext2_delete_entry (struct ext2_dir_entry_2 * dir, struct page * page )
de = ext2_next_entry(de); de = ext2_next_entry(de);
} }
if (pde) if (pde)
from = (char*)pde - (char*)page_address(page); from = (char *)pde - kaddr;
pos = page_offset(page) + from; pos = page_offset(page) + from;
lock_page(page); lock_page(page);
err = ext2_prepare_chunk(page, pos, to - from); err = ext2_prepare_chunk(page, pos, to - from);
......
...@@ -740,7 +740,8 @@ extern int ext2_inode_by_name(struct inode *dir, ...@@ -740,7 +740,8 @@ extern int ext2_inode_by_name(struct inode *dir,
extern int ext2_make_empty(struct inode *, struct inode *); extern int ext2_make_empty(struct inode *, struct inode *);
extern struct ext2_dir_entry_2 *ext2_find_entry(struct inode *, const struct qstr *, extern struct ext2_dir_entry_2 *ext2_find_entry(struct inode *, const struct qstr *,
struct page **, void **res_page_addr); struct page **, void **res_page_addr);
extern int ext2_delete_entry (struct ext2_dir_entry_2 *, struct page *); extern int ext2_delete_entry(struct ext2_dir_entry_2 *dir, struct page *page,
char *kaddr);
extern int ext2_empty_dir (struct inode *); extern int ext2_empty_dir (struct inode *);
extern struct ext2_dir_entry_2 *ext2_dotdot(struct inode *dir, struct page **p, void **pa); extern struct ext2_dir_entry_2 *ext2_dotdot(struct inode *dir, struct page **p, void **pa);
extern void ext2_set_link(struct inode *, struct ext2_dir_entry_2 *, struct page *, void *, extern void ext2_set_link(struct inode *, struct ext2_dir_entry_2 *, struct page *, void *,
......
...@@ -293,7 +293,7 @@ static int ext2_unlink(struct inode * dir, struct dentry *dentry) ...@@ -293,7 +293,7 @@ static int ext2_unlink(struct inode * dir, struct dentry *dentry)
goto out; goto out;
} }
err = ext2_delete_entry (de, page); err = ext2_delete_entry (de, page, page_addr);
ext2_put_page(page, page_addr); ext2_put_page(page, page_addr);
if (err) if (err)
goto out; goto out;
...@@ -397,7 +397,7 @@ static int ext2_rename (struct user_namespace * mnt_userns, ...@@ -397,7 +397,7 @@ static int ext2_rename (struct user_namespace * mnt_userns,
old_inode->i_ctime = current_time(old_inode); old_inode->i_ctime = current_time(old_inode);
mark_inode_dirty(old_inode); mark_inode_dirty(old_inode);
ext2_delete_entry(old_de, old_page); ext2_delete_entry(old_de, old_page, old_page_addr);
if (dir_de) { if (dir_de) {
if (old_dir != new_dir) if (old_dir != new_dir)
......
...@@ -387,6 +387,24 @@ void pathrelse(struct treepath *search_path) ...@@ -387,6 +387,24 @@ void pathrelse(struct treepath *search_path)
search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET; search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
} }
static int has_valid_deh_location(struct buffer_head *bh, struct item_head *ih)
{
struct reiserfs_de_head *deh;
int i;
deh = B_I_DEH(bh, ih);
for (i = 0; i < ih_entry_count(ih); i++) {
if (deh_location(&deh[i]) > ih_item_len(ih)) {
reiserfs_warning(NULL, "reiserfs-5094",
"directory entry location seems wrong %h",
&deh[i]);
return 0;
}
}
return 1;
}
static int is_leaf(char *buf, int blocksize, struct buffer_head *bh) static int is_leaf(char *buf, int blocksize, struct buffer_head *bh)
{ {
struct block_head *blkh; struct block_head *blkh;
...@@ -454,11 +472,14 @@ static int is_leaf(char *buf, int blocksize, struct buffer_head *bh) ...@@ -454,11 +472,14 @@ static int is_leaf(char *buf, int blocksize, struct buffer_head *bh)
"(second one): %h", ih); "(second one): %h", ih);
return 0; return 0;
} }
if (is_direntry_le_ih(ih) && (ih_item_len(ih) < (ih_entry_count(ih) * IH_SIZE))) { if (is_direntry_le_ih(ih)) {
reiserfs_warning(NULL, "reiserfs-5093", if (ih_item_len(ih) < (ih_entry_count(ih) * IH_SIZE)) {
"item entry count seems wrong %h", reiserfs_warning(NULL, "reiserfs-5093",
ih); "item entry count seems wrong %h",
return 0; ih);
return 0;
}
return has_valid_deh_location(bh, ih);
} }
prev_location = ih_location(ih); prev_location = ih_location(ih);
} }
......
...@@ -2082,6 +2082,14 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent) ...@@ -2082,6 +2082,14 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
unlock_new_inode(root_inode); unlock_new_inode(root_inode);
} }
if (!S_ISDIR(root_inode->i_mode) || !inode_get_bytes(root_inode) ||
!root_inode->i_size) {
SWARN(silent, s, "", "corrupt root inode, run fsck");
iput(root_inode);
errval = -EUCLEAN;
goto error;
}
s->s_root = d_make_root(root_inode); s->s_root = d_make_root(root_inode);
if (!s->s_root) if (!s->s_root)
goto error; goto error;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment