Skip to content

Commit 64fcbb6

Browse files
committed
afs: Fix accessing YFS xattrs on a non-YFS server
If someone attempts to access YFS-related xattrs (e.g. afs.yfs.acl) on a file on a non-YFS AFS server (such as OpenAFS), then the kernel will jump to a NULL function pointer because the afs_fetch_acl_operation descriptor doesn't point to a function for issuing an operation on a non-YFS server[1]. Fix this by making afs_wait_for_operation() check that the issue_afs_rpc method is set before jumping to it and setting -ENOTSUPP if not. This fix also covers other potential operations that also only exist on YFS servers. afs_xattr_get/set_yfs() then need to translate -ENOTSUPP to -ENODATA as the former error is internal to the kernel. The bug shows up as an oops like the following: BUG: kernel NULL pointer dereference, address: 0000000000000000 [...] Code: Unable to access opcode bytes at RIP 0xffffffffffffffd6. [...] Call Trace: afs_wait_for_operation+0x83/0x1b0 [kafs] afs_xattr_get_yfs+0xe6/0x270 [kafs] __vfs_getxattr+0x59/0x80 vfs_getxattr+0x11c/0x140 getxattr+0x181/0x250 ? __check_object_size+0x13f/0x150 ? __fput+0x16d/0x250 __x64_sys_fgetxattr+0x64/0xb0 do_syscall_64+0x49/0xc0 entry_SYSCALL_64_after_hwframe+0x44/0xa9 RIP: 0033:0x7fb120a9defe This was triggered with "cp -a" which attempts to copy xattrs, including afs ones, but is easier to reproduce with getfattr, e.g.: getfattr -d -m ".*" /afs/openafs.org/ Fixes: e49c7b2 ("afs: Build an abstraction around an "operation" concept") Reported-by: Gaja Sophie Peters <[email protected]> Signed-off-by: David Howells <[email protected]> Tested-by: Gaja Sophie Peters <[email protected]> Reviewed-by: Marc Dionne <[email protected]> Reviewed-by: Jeffrey Altman <[email protected]> cc: [email protected] Link: http://lists.infradead.org/pipermail/linux-afs/2021-March/003498.html [1] Link: http://lists.infradead.org/pipermail/linux-afs/2021-March/003566.html # v1 Link: http://lists.infradead.org/pipermail/linux-afs/2021-March/003572.html # v2
1 parent a38fd87 commit 64fcbb6

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

fs/afs/fs_operation.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,13 @@ void afs_wait_for_operation(struct afs_operation *op)
181181
if (test_bit(AFS_SERVER_FL_IS_YFS, &op->server->flags) &&
182182
op->ops->issue_yfs_rpc)
183183
op->ops->issue_yfs_rpc(op);
184-
else
184+
else if (op->ops->issue_afs_rpc)
185185
op->ops->issue_afs_rpc(op);
186+
else
187+
op->ac.error = -ENOTSUPP;
186188

187-
op->error = afs_wait_for_call_to_complete(op->call, &op->ac);
189+
if (op->call)
190+
op->error = afs_wait_for_call_to_complete(op->call, &op->ac);
188191
}
189192

190193
switch (op->error) {

fs/afs/xattr.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ static int afs_xattr_get_yfs(const struct xattr_handler *handler,
231231
else
232232
ret = -ERANGE;
233233
}
234+
} else if (ret == -ENOTSUPP) {
235+
ret = -ENODATA;
234236
}
235237

236238
error_yacl:
@@ -256,6 +258,7 @@ static int afs_xattr_set_yfs(const struct xattr_handler *handler,
256258
{
257259
struct afs_operation *op;
258260
struct afs_vnode *vnode = AFS_FS_I(inode);
261+
int ret;
259262

260263
if (flags == XATTR_CREATE ||
261264
strcmp(name, "acl") != 0)
@@ -270,7 +273,10 @@ static int afs_xattr_set_yfs(const struct xattr_handler *handler,
270273
return afs_put_operation(op);
271274

272275
op->ops = &yfs_store_opaque_acl2_operation;
273-
return afs_do_sync_operation(op);
276+
ret = afs_do_sync_operation(op);
277+
if (ret == -ENOTSUPP)
278+
ret = -ENODATA;
279+
return ret;
274280
}
275281

276282
static const struct xattr_handler afs_xattr_yfs_handler = {

0 commit comments

Comments
 (0)