Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xfs: Remote attr validation fixes and optimisations

- optimise the calcuation for the number of blocks in a remote
xattr.
- check attribute length against MAX_XATTR_SIZE, not MAXPATHLEN
- whitespace fixes

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Ben Myers <bpm@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>

authored by

Dave Chinner and committed by
Ben Myers
946217ba 123887e8

+5 -14
+5 -14
fs/xfs/xfs_attr_remote.c
··· 52 52 struct xfs_mount *mp, 53 53 int attrlen) 54 54 { 55 - int fsblocks = 0; 56 - int len = attrlen; 57 - 58 - do { 59 - fsblocks++; 60 - len -= XFS_ATTR3_RMT_BUF_SPACE(mp, mp->m_sb.sb_blocksize); 61 - } while (len > 0); 62 - 63 - return fsblocks; 55 + int buflen = XFS_ATTR3_RMT_BUF_SPACE(mp, 56 + mp->m_sb.sb_blocksize); 57 + return (attrlen + buflen - 1) / buflen; 64 58 } 65 59 66 60 static bool ··· 73 79 if (bp->b_bn != be64_to_cpu(rmt->rm_blkno)) 74 80 return false; 75 81 if (be32_to_cpu(rmt->rm_offset) + 76 - be32_to_cpu(rmt->rm_bytes) >= MAXPATHLEN) 82 + be32_to_cpu(rmt->rm_bytes) >= XATTR_SIZE_MAX) 77 83 return false; 78 84 if (rmt->rm_owner == 0) 79 85 return false; ··· 177 183 178 184 /* ok */ 179 185 return true; 180 - 181 186 } 182 187 183 188 /* ··· 360 367 * spill for another block every 9 headers we require in this 361 368 * loop. 362 369 */ 363 - 364 370 if (crcs && blkcnt == 0) { 365 371 int total_len; 366 372 ··· 414 422 415 423 byte_cnt = BBTOB(bp->b_length); 416 424 byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, byte_cnt); 417 - if (valuelen < byte_cnt) { 425 + if (valuelen < byte_cnt) 418 426 byte_cnt = valuelen; 419 - } 420 427 421 428 buf = bp->b_addr; 422 429 buf += xfs_attr3_rmt_hdr_set(mp, dp->i_ino, offset,