Skip to content

Commit 946217b

Browse files
dgchinnerBen Myers
authored andcommitted
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>
1 parent 123887e commit 946217b

1 file changed

Lines changed: 5 additions & 14 deletions

File tree

fs/xfs/xfs_attr_remote.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,9 @@ xfs_attr3_rmt_blocks(
5252
struct xfs_mount *mp,
5353
int attrlen)
5454
{
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;
6458
}
6559

6660
static bool
@@ -79,7 +73,7 @@ xfs_attr3_rmt_verify(
7973
if (bp->b_bn != be64_to_cpu(rmt->rm_blkno))
8074
return false;
8175
if (be32_to_cpu(rmt->rm_offset) +
82-
be32_to_cpu(rmt->rm_bytes) >= MAXPATHLEN)
76+
be32_to_cpu(rmt->rm_bytes) >= XATTR_SIZE_MAX)
8377
return false;
8478
if (rmt->rm_owner == 0)
8579
return false;
@@ -183,7 +177,6 @@ xfs_attr3_rmt_hdr_ok(
183177

184178
/* ok */
185179
return true;
186-
187180
}
188181

189182
/*
@@ -367,7 +360,6 @@ xfs_attr_rmtval_set(
367360
* spill for another block every 9 headers we require in this
368361
* loop.
369362
*/
370-
371363
if (crcs && blkcnt == 0) {
372364
int total_len;
373365

@@ -422,9 +414,8 @@ xfs_attr_rmtval_set(
422414

423415
byte_cnt = BBTOB(bp->b_length);
424416
byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, byte_cnt);
425-
if (valuelen < byte_cnt) {
417+
if (valuelen < byte_cnt)
426418
byte_cnt = valuelen;
427-
}
428419

429420
buf = bp->b_addr;
430421
buf += xfs_attr3_rmt_hdr_set(mp, dp->i_ino, offset,

0 commit comments

Comments
 (0)