aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs
diff options
context:
space:
mode:
authorCarlos Maiolino <cmaiolino@redhat.com>2011-11-19 13:13:44 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2011-11-26 12:10:06 -0500
commit626ff2d51fc1127814fa28bdfb1df761ea894755 (patch)
tree885735d33631ba30e562ffa4a83d5c0417fec71b /fs/xfs
parent70f589ceb96bbf1d4c2c2f5b6c3d6dff19ddd31d (diff)
xfs: Fix possible memory corruption in xfs_readlink
commit b52a360b2aa1c59ba9970fb0f52bbb093fcc7a24 upstream. Fixes a possible memory corruption when the link is larger than MAXPATHLEN and XFS_DEBUG is not enabled. This also remove the S_ISLNK assert, since the inode mode is checked previously in xfs_readlink_by_handle() and via VFS. Updated to address concerns raised by Ben Hutchings about the loose attention paid to 32- vs 64-bit values, and the lack of handling a potentially negative pathlen value: - Changed type of "pathlen" to be xfs_fsize_t, to match that of ip->i_d.di_size - Added checking for a negative pathlen to the too-long pathlen test, and generalized the message that gets reported in that case to reflect the change As a result, if a negative pathlen were encountered, this function would return EFSCORRUPTED (and would fail an assertion for a debug build)--just as would a too-long pathlen. Signed-off-by: Alex Elder <aelder@sgi.com> Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'fs/xfs')
-rw-r--r--fs/xfs/xfs_vnodeops.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/fs/xfs/xfs_vnodeops.c b/fs/xfs/xfs_vnodeops.c
index 619720705bc..6cc4d41fb0d 100644
--- a/fs/xfs/xfs_vnodeops.c
+++ b/fs/xfs/xfs_vnodeops.c
@@ -535,7 +535,7 @@ xfs_readlink(
535 char *link) 535 char *link)
536{ 536{
537 xfs_mount_t *mp = ip->i_mount; 537 xfs_mount_t *mp = ip->i_mount;
538 int pathlen; 538 xfs_fsize_t pathlen;
539 int error = 0; 539 int error = 0;
540 540
541 trace_xfs_readlink(ip); 541 trace_xfs_readlink(ip);
@@ -545,13 +545,19 @@ xfs_readlink(
545 545
546 xfs_ilock(ip, XFS_ILOCK_SHARED); 546 xfs_ilock(ip, XFS_ILOCK_SHARED);
547 547
548 ASSERT((ip->i_d.di_mode & S_IFMT) == S_IFLNK);
549 ASSERT(ip->i_d.di_size <= MAXPATHLEN);
550
551 pathlen = ip->i_d.di_size; 548 pathlen = ip->i_d.di_size;
552 if (!pathlen) 549 if (!pathlen)
553 goto out; 550 goto out;
554 551
552 if (pathlen < 0 || pathlen > MAXPATHLEN) {
553 xfs_alert(mp, "%s: inode (%llu) bad symlink length (%lld)",
554 __func__, (unsigned long long) ip->i_ino,
555 (long long) pathlen);
556 ASSERT(0);
557 return XFS_ERROR(EFSCORRUPTED);
558 }
559
560
555 if (ip->i_df.if_flags & XFS_IFINLINE) { 561 if (ip->i_df.if_flags & XFS_IFINLINE) {
556 memcpy(link, ip->i_df.if_u1.if_data, pathlen); 562 memcpy(link, ip->i_df.if_u1.if_data, pathlen);
557 link[pathlen] = '\0'; 563 link[pathlen] = '\0';