Skip to content

Commit 4010a52

Browse files
committed
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
2 parents dfe4953 + 13d2575 commit 4010a52

File tree

5 files changed

+44
-14
lines changed

5 files changed

+44
-14
lines changed

fs/ext2/dir.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,11 @@ static int ext2_commit_chunk(struct page *page, loff_t pos, unsigned len)
106106
return err;
107107
}
108108

109-
static bool ext2_check_page(struct page *page, int quiet)
109+
static bool ext2_check_page(struct page *page, int quiet, char *kaddr)
110110
{
111111
struct inode *dir = page->mapping->host;
112112
struct super_block *sb = dir->i_sb;
113113
unsigned chunk_size = ext2_chunk_size(dir);
114-
char *kaddr = page_address(page);
115114
u32 max_inumber = le32_to_cpu(EXT2_SB(sb)->s_es->s_inodes_count);
116115
unsigned offs, rec_len;
117116
unsigned limit = PAGE_SIZE;
@@ -205,7 +204,8 @@ static struct page * ext2_get_page(struct inode *dir, unsigned long n,
205204
if (!IS_ERR(page)) {
206205
*page_addr = kmap_local_page(page);
207206
if (unlikely(!PageChecked(page))) {
208-
if (PageError(page) || !ext2_check_page(page, quiet))
207+
if (PageError(page) || !ext2_check_page(page, quiet,
208+
*page_addr))
209209
goto fail;
210210
}
211211
}
@@ -584,10 +584,10 @@ int ext2_add_link (struct dentry *dentry, struct inode *inode)
584584
* ext2_delete_entry deletes a directory entry by merging it with the
585585
* previous entry. Page is up-to-date.
586586
*/
587-
int ext2_delete_entry (struct ext2_dir_entry_2 * dir, struct page * page )
587+
int ext2_delete_entry (struct ext2_dir_entry_2 *dir, struct page *page,
588+
char *kaddr)
588589
{
589590
struct inode *inode = page->mapping->host;
590-
char *kaddr = page_address(page);
591591
unsigned from = ((char*)dir - kaddr) & ~(ext2_chunk_size(inode)-1);
592592
unsigned to = ((char *)dir - kaddr) +
593593
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 )
607607
de = ext2_next_entry(de);
608608
}
609609
if (pde)
610-
from = (char*)pde - (char*)page_address(page);
610+
from = (char *)pde - kaddr;
611611
pos = page_offset(page) + from;
612612
lock_page(page);
613613
err = ext2_prepare_chunk(page, pos, to - from);

fs/ext2/ext2.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,8 @@ extern int ext2_inode_by_name(struct inode *dir,
740740
extern int ext2_make_empty(struct inode *, struct inode *);
741741
extern struct ext2_dir_entry_2 *ext2_find_entry(struct inode *, const struct qstr *,
742742
struct page **, void **res_page_addr);
743-
extern int ext2_delete_entry (struct ext2_dir_entry_2 *, struct page *);
743+
extern int ext2_delete_entry(struct ext2_dir_entry_2 *dir, struct page *page,
744+
char *kaddr);
744745
extern int ext2_empty_dir (struct inode *);
745746
extern struct ext2_dir_entry_2 *ext2_dotdot(struct inode *dir, struct page **p, void **pa);
746747
extern void ext2_set_link(struct inode *, struct ext2_dir_entry_2 *, struct page *, void *,

fs/ext2/namei.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ static int ext2_unlink(struct inode * dir, struct dentry *dentry)
293293
goto out;
294294
}
295295

296-
err = ext2_delete_entry (de, page);
296+
err = ext2_delete_entry (de, page, page_addr);
297297
ext2_put_page(page, page_addr);
298298
if (err)
299299
goto out;
@@ -397,7 +397,7 @@ static int ext2_rename (struct user_namespace * mnt_userns,
397397
old_inode->i_ctime = current_time(old_inode);
398398
mark_inode_dirty(old_inode);
399399

400-
ext2_delete_entry(old_de, old_page);
400+
ext2_delete_entry(old_de, old_page, old_page_addr);
401401

402402
if (dir_de) {
403403
if (old_dir != new_dir)

fs/reiserfs/stree.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,24 @@ void pathrelse(struct treepath *search_path)
387387
search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
388388
}
389389

390+
static int has_valid_deh_location(struct buffer_head *bh, struct item_head *ih)
391+
{
392+
struct reiserfs_de_head *deh;
393+
int i;
394+
395+
deh = B_I_DEH(bh, ih);
396+
for (i = 0; i < ih_entry_count(ih); i++) {
397+
if (deh_location(&deh[i]) > ih_item_len(ih)) {
398+
reiserfs_warning(NULL, "reiserfs-5094",
399+
"directory entry location seems wrong %h",
400+
&deh[i]);
401+
return 0;
402+
}
403+
}
404+
405+
return 1;
406+
}
407+
390408
static int is_leaf(char *buf, int blocksize, struct buffer_head *bh)
391409
{
392410
struct block_head *blkh;
@@ -454,11 +472,14 @@ static int is_leaf(char *buf, int blocksize, struct buffer_head *bh)
454472
"(second one): %h", ih);
455473
return 0;
456474
}
457-
if (is_direntry_le_ih(ih) && (ih_item_len(ih) < (ih_entry_count(ih) * IH_SIZE))) {
458-
reiserfs_warning(NULL, "reiserfs-5093",
459-
"item entry count seems wrong %h",
460-
ih);
461-
return 0;
475+
if (is_direntry_le_ih(ih)) {
476+
if (ih_item_len(ih) < (ih_entry_count(ih) * IH_SIZE)) {
477+
reiserfs_warning(NULL, "reiserfs-5093",
478+
"item entry count seems wrong %h",
479+
ih);
480+
return 0;
481+
}
482+
return has_valid_deh_location(bh, ih);
462483
}
463484
prev_location = ih_location(ih);
464485
}

fs/reiserfs/super.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,6 +2082,14 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
20822082
unlock_new_inode(root_inode);
20832083
}
20842084

2085+
if (!S_ISDIR(root_inode->i_mode) || !inode_get_bytes(root_inode) ||
2086+
!root_inode->i_size) {
2087+
SWARN(silent, s, "", "corrupt root inode, run fsck");
2088+
iput(root_inode);
2089+
errval = -EUCLEAN;
2090+
goto error;
2091+
}
2092+
20852093
s->s_root = d_make_root(root_inode);
20862094
if (!s->s_root)
20872095
goto error;

0 commit comments

Comments
 (0)