Skip to content

Commit

Permalink
Merge tag 'fixes_for_v5.14-rc4' of git://git.kernel.org/pub/scm/linux…
Browse files Browse the repository at this point in the history
…/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
  • Loading branch information
torvalds committed Jul 28, 2021
2 parents dfe4953 + 13d2575 commit 4010a52
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 14 deletions.
12 changes: 6 additions & 6 deletions fs/ext2/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,11 @@ static int ext2_commit_chunk(struct page *page, loff_t pos, unsigned len)
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 super_block *sb = dir->i_sb;
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);
unsigned offs, rec_len;
unsigned limit = PAGE_SIZE;
Expand Down Expand Up @@ -205,7 +204,8 @@ static struct page * ext2_get_page(struct inode *dir, unsigned long n,
if (!IS_ERR(page)) {
*page_addr = kmap_local_page(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;
}
}
Expand Down Expand Up @@ -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
* 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;
char *kaddr = page_address(page);
unsigned from = ((char*)dir - kaddr) & ~(ext2_chunk_size(inode)-1);
unsigned to = ((char *)dir - kaddr) +
ext2_rec_len_from_disk(dir->rec_len);
Expand All @@ -607,7 +607,7 @@ int ext2_delete_entry (struct ext2_dir_entry_2 * dir, struct page * page )
de = ext2_next_entry(de);
}
if (pde)
from = (char*)pde - (char*)page_address(page);
from = (char *)pde - kaddr;
pos = page_offset(page) + from;
lock_page(page);
err = ext2_prepare_chunk(page, pos, to - from);
Expand Down
3 changes: 2 additions & 1 deletion fs/ext2/ext2.h
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,8 @@ extern int ext2_inode_by_name(struct inode *dir,
extern int ext2_make_empty(struct inode *, struct inode *);
extern struct ext2_dir_entry_2 *ext2_find_entry(struct inode *, const struct qstr *,
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 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 *,
Expand Down
4 changes: 2 additions & 2 deletions fs/ext2/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ static int ext2_unlink(struct inode * dir, struct dentry *dentry)
goto out;
}

err = ext2_delete_entry (de, page);
err = ext2_delete_entry (de, page, page_addr);
ext2_put_page(page, page_addr);
if (err)
goto out;
Expand Down Expand Up @@ -397,7 +397,7 @@ static int ext2_rename (struct user_namespace * mnt_userns,
old_inode->i_ctime = current_time(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 (old_dir != new_dir)
Expand Down
31 changes: 26 additions & 5 deletions fs/reiserfs/stree.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,24 @@ void pathrelse(struct treepath *search_path)
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)
{
struct block_head *blkh;
Expand Down Expand Up @@ -454,11 +472,14 @@ static int is_leaf(char *buf, int blocksize, struct buffer_head *bh)
"(second one): %h", ih);
return 0;
}
if (is_direntry_le_ih(ih) && (ih_item_len(ih) < (ih_entry_count(ih) * IH_SIZE))) {
reiserfs_warning(NULL, "reiserfs-5093",
"item entry count seems wrong %h",
ih);
return 0;
if (is_direntry_le_ih(ih)) {
if (ih_item_len(ih) < (ih_entry_count(ih) * IH_SIZE)) {
reiserfs_warning(NULL, "reiserfs-5093",
"item entry count seems wrong %h",
ih);
return 0;
}
return has_valid_deh_location(bh, ih);
}
prev_location = ih_location(ih);
}
Expand Down
8 changes: 8 additions & 0 deletions fs/reiserfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -2082,6 +2082,14 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
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);
if (!s->s_root)
goto error;
Expand Down

0 comments on commit 4010a52

Please sign in to comment.