Skip to content

Commit 70376c7

Browse files
author
Andreas Gruenbacher
committed
gfs2: Always check inode size of inline inodes
Check if the inode size of stuffed (inline) inodes is within the allowed range when reading inodes from disk (gfs2_dinode_in()). This prevents us from on-disk corruption. The two checks in stuffed_readpage() and gfs2_unstuffer_page() that just truncate inline data to the maximum allowed size don't actually make sense, and they can be removed now as well. Reported-by: [email protected] Signed-off-by: Andreas Gruenbacher <[email protected]>
1 parent 7db3544 commit 70376c7

File tree

3 files changed

+3
-5
lines changed

3 files changed

+3
-5
lines changed

fs/gfs2/aops.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,6 @@ static int stuffed_readpage(struct gfs2_inode *ip, struct page *page)
427427
return error;
428428

429429
kaddr = kmap_atomic(page);
430-
if (dsize > gfs2_max_stuffed_size(ip))
431-
dsize = gfs2_max_stuffed_size(ip);
432430
memcpy(kaddr, dibh->b_data + sizeof(struct gfs2_dinode), dsize);
433431
memset(kaddr + dsize, 0, PAGE_SIZE - dsize);
434432
kunmap_atomic(kaddr);

fs/gfs2/bmap.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ static int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh,
6161
void *kaddr = kmap(page);
6262
u64 dsize = i_size_read(inode);
6363

64-
if (dsize > gfs2_max_stuffed_size(ip))
65-
dsize = gfs2_max_stuffed_size(ip);
66-
6764
memcpy(kaddr, dibh->b_data + sizeof(struct gfs2_dinode), dsize);
6865
memset(kaddr + dsize, 0, PAGE_SIZE - dsize);
6966
kunmap(page);

fs/gfs2/glops.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,9 @@ static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)
449449
ip->i_depth = (u8)depth;
450450
ip->i_entries = be32_to_cpu(str->di_entries);
451451

452+
if (gfs2_is_stuffed(ip) && inode->i_size > gfs2_max_stuffed_size(ip))
453+
goto corrupt;
454+
452455
if (S_ISREG(inode->i_mode))
453456
gfs2_set_aops(inode);
454457

0 commit comments

Comments
 (0)