Skip to content

Commit 339e1a3

Browse files
Eric Sandeendchinner
Eric Sandeen
authored andcommitted
xfs: validate inode di_forkoff
Verify the inode di_forkoff, lifted from xfs_repair's process_check_inode_forkoff(). Signed-off-by: Eric Sandeen <[email protected]> Reviewed-by: Brian Foster <[email protected]> Signed-off-by: Dave Chinner <[email protected]>
1 parent f5f3f95 commit 339e1a3

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

fs/xfs/libxfs/xfs_inode_buf.c

+30
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,31 @@ xfs_dinode_verify_fork(
415415
return NULL;
416416
}
417417

418+
static xfs_failaddr_t
419+
xfs_dinode_verify_forkoff(
420+
struct xfs_dinode *dip,
421+
struct xfs_mount *mp)
422+
{
423+
if (!XFS_DFORK_Q(dip))
424+
return NULL;
425+
426+
switch (dip->di_format) {
427+
case XFS_DINODE_FMT_DEV:
428+
if (dip->di_forkoff != (roundup(sizeof(xfs_dev_t), 8) >> 3))
429+
return __this_address;
430+
break;
431+
case XFS_DINODE_FMT_LOCAL: /* fall through ... */
432+
case XFS_DINODE_FMT_EXTENTS: /* fall through ... */
433+
case XFS_DINODE_FMT_BTREE:
434+
if (dip->di_forkoff >= (XFS_LITINO(mp, dip->di_version) >> 3))
435+
return __this_address;
436+
break;
437+
default:
438+
return __this_address;
439+
}
440+
return NULL;
441+
}
442+
418443
xfs_failaddr_t
419444
xfs_dinode_verify(
420445
struct xfs_mount *mp,
@@ -470,6 +495,11 @@ xfs_dinode_verify(
470495
if (mode && (flags & XFS_DIFLAG_REALTIME) && !mp->m_rtdev_targp)
471496
return __this_address;
472497

498+
/* check for illegal values of forkoff */
499+
fa = xfs_dinode_verify_forkoff(dip, mp);
500+
if (fa)
501+
return fa;
502+
473503
/* Do we have appropriate data fork formats for the mode? */
474504
switch (mode & S_IFMT) {
475505
case S_IFIFO:

0 commit comments

Comments
 (0)