|
24 | 24 | #include <linux/key.h> |
25 | 25 | #include <linux/verification.h> |
26 | 26 | #include <linux/namei.h> |
27 | | -#include <linux/fileattr.h> |
28 | 27 |
|
29 | 28 | #include <net/bpf_sk_storage.h> |
30 | 29 |
|
@@ -1439,73 +1438,6 @@ static int __init bpf_key_sig_kfuncs_init(void) |
1439 | 1438 | late_initcall(bpf_key_sig_kfuncs_init); |
1440 | 1439 | #endif /* CONFIG_KEYS */ |
1441 | 1440 |
|
1442 | | -/* filesystem kfuncs */ |
1443 | | -__bpf_kfunc_start_defs(); |
1444 | | - |
1445 | | -/** |
1446 | | - * bpf_get_file_xattr - get xattr of a file |
1447 | | - * @file: file to get xattr from |
1448 | | - * @name__str: name of the xattr |
1449 | | - * @value_p: output buffer of the xattr value |
1450 | | - * |
1451 | | - * Get xattr *name__str* of *file* and store the output in *value_ptr*. |
1452 | | - * |
1453 | | - * For security reasons, only *name__str* with prefix "user." is allowed. |
1454 | | - * |
1455 | | - * Return: 0 on success, a negative value on error. |
1456 | | - */ |
1457 | | -__bpf_kfunc int bpf_get_file_xattr(struct file *file, const char *name__str, |
1458 | | - struct bpf_dynptr *value_p) |
1459 | | -{ |
1460 | | - struct bpf_dynptr_kern *value_ptr = (struct bpf_dynptr_kern *)value_p; |
1461 | | - struct dentry *dentry; |
1462 | | - u32 value_len; |
1463 | | - void *value; |
1464 | | - int ret; |
1465 | | - |
1466 | | - if (strncmp(name__str, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) |
1467 | | - return -EPERM; |
1468 | | - |
1469 | | - value_len = __bpf_dynptr_size(value_ptr); |
1470 | | - value = __bpf_dynptr_data_rw(value_ptr, value_len); |
1471 | | - if (!value) |
1472 | | - return -EINVAL; |
1473 | | - |
1474 | | - dentry = file_dentry(file); |
1475 | | - ret = inode_permission(&nop_mnt_idmap, dentry->d_inode, MAY_READ); |
1476 | | - if (ret) |
1477 | | - return ret; |
1478 | | - return __vfs_getxattr(dentry, dentry->d_inode, name__str, value, value_len); |
1479 | | -} |
1480 | | - |
1481 | | -__bpf_kfunc_end_defs(); |
1482 | | - |
1483 | | -BTF_KFUNCS_START(fs_kfunc_set_ids) |
1484 | | -BTF_ID_FLAGS(func, bpf_get_file_xattr, KF_SLEEPABLE | KF_TRUSTED_ARGS) |
1485 | | -BTF_KFUNCS_END(fs_kfunc_set_ids) |
1486 | | - |
1487 | | -static int bpf_get_file_xattr_filter(const struct bpf_prog *prog, u32 kfunc_id) |
1488 | | -{ |
1489 | | - if (!btf_id_set8_contains(&fs_kfunc_set_ids, kfunc_id)) |
1490 | | - return 0; |
1491 | | - |
1492 | | - /* Only allow to attach from LSM hooks, to avoid recursion */ |
1493 | | - return prog->type != BPF_PROG_TYPE_LSM ? -EACCES : 0; |
1494 | | -} |
1495 | | - |
1496 | | -static const struct btf_kfunc_id_set bpf_fs_kfunc_set = { |
1497 | | - .owner = THIS_MODULE, |
1498 | | - .set = &fs_kfunc_set_ids, |
1499 | | - .filter = bpf_get_file_xattr_filter, |
1500 | | -}; |
1501 | | - |
1502 | | -static int __init bpf_fs_kfuncs_init(void) |
1503 | | -{ |
1504 | | - return register_btf_kfunc_id_set(BPF_PROG_TYPE_LSM, &bpf_fs_kfunc_set); |
1505 | | -} |
1506 | | - |
1507 | | -late_initcall(bpf_fs_kfuncs_init); |
1508 | | - |
1509 | 1441 | static const struct bpf_func_proto * |
1510 | 1442 | bpf_tracing_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) |
1511 | 1443 | { |
|
0 commit comments