Skip to content

Commit a2f611a

Browse files
committed
afs: Fix getting the afs.fid xattr
The AFS3 FID is three 32-bit unsigned numbers and is represented as three up-to-8-hex-digit numbers separated by colons to the afs.fid xattr. However, with the advent of support for YFS, the FID is now a 64-bit volume number, a 96-bit vnode/inode number and a 32-bit uniquifier (as before). Whilst the sprintf in afs_xattr_get_fid() has been partially updated (it currently ignores the upper 32 bits of the 96-bit vnode number), the size of the stack-based buffer has not been increased to match, thereby allowing stack corruption to occur. Fix this by increasing the buffer size appropriately and conditionally including the upper part of the vnode number if it is non-zero. The latter requires the lower part to be zero-padded if the upper part is non-zero. Fixes: 3b6492d ("afs: Increase to 64-bit volume ID and 96-bit vnode ID for YFS") Signed-off-by: David Howells <[email protected]>
1 parent c73aa41 commit a2f611a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

fs/afs/xattr.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,20 @@ static int afs_xattr_get_fid(const struct xattr_handler *handler,
6969
void *buffer, size_t size)
7070
{
7171
struct afs_vnode *vnode = AFS_FS_I(inode);
72-
char text[8 + 1 + 8 + 1 + 8 + 1];
72+
char text[16 + 1 + 24 + 1 + 8 + 1];
7373
size_t len;
7474

75-
len = sprintf(text, "%llx:%llx:%x",
76-
vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique);
75+
/* The volume ID is 64-bit, the vnode ID is 96-bit and the
76+
* uniquifier is 32-bit.
77+
*/
78+
len = sprintf(text, "%llx:", vnode->fid.vid);
79+
if (vnode->fid.vnode_hi)
80+
len += sprintf(text + len, "%x%016llx",
81+
vnode->fid.vnode_hi, vnode->fid.vnode);
82+
else
83+
len += sprintf(text + len, "%llx", vnode->fid.vnode);
84+
len += sprintf(text + len, ":%x", vnode->fid.unique);
85+
7786
if (size == 0)
7887
return len;
7988
if (len > size)

0 commit comments

Comments
 (0)