mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-04-02 12:47:41 +08:00
bpf: Fix key serial argument of bpf_lookup_user_key()
The underlying lookup_user_key() function uses a signed 32 bit integer for key serial numbers because legitimate serial numbers are positive (and > 3) and keyrings are negative. Using a u32 for the keyring in the bpf function doesn't currently cause any conversion problems but will start to trip the signed to unsigned conversion warnings when the kernel enables them, so convert the argument to signed (and update the tests accordingly) before it acquires more users. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com> Reviewed-by: Roberto Sassu <roberto.sassu@huawei.com> Link: https://lore.kernel.org/r/84cdb0775254d297d75e21f577089f64abdfbd28.camel@HansenPartnership.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
committed by
Alexei Starovoitov
parent
f5527f0171
commit
bd07bd12f2
@@ -1270,7 +1270,7 @@ __bpf_kfunc_start_defs();
|
||||
* Return: a bpf_key pointer with a valid key pointer if the key is found, a
|
||||
* NULL pointer otherwise.
|
||||
*/
|
||||
__bpf_kfunc struct bpf_key *bpf_lookup_user_key(u32 serial, u64 flags)
|
||||
__bpf_kfunc struct bpf_key *bpf_lookup_user_key(s32 serial, u64 flags)
|
||||
{
|
||||
key_ref_t key_ref;
|
||||
struct bpf_key *bkey;
|
||||
|
||||
@@ -69,7 +69,7 @@ extern int bpf_get_file_xattr(struct file *file, const char *name,
|
||||
struct bpf_dynptr *value_ptr) __ksym;
|
||||
extern int bpf_get_fsverity_digest(struct file *file, struct bpf_dynptr *digest_ptr) __ksym;
|
||||
|
||||
extern struct bpf_key *bpf_lookup_user_key(__u32 serial, __u64 flags) __ksym;
|
||||
extern struct bpf_key *bpf_lookup_user_key(__s32 serial, __u64 flags) __ksym;
|
||||
extern struct bpf_key *bpf_lookup_system_key(__u64 id) __ksym;
|
||||
extern void bpf_key_put(struct bpf_key *key) __ksym;
|
||||
extern int bpf_verify_pkcs7_signature(struct bpf_dynptr *data_ptr,
|
||||
|
||||
@@ -16,10 +16,11 @@ struct {
|
||||
__type(value, long);
|
||||
} map_a SEC(".maps");
|
||||
|
||||
__u32 user_data, key_serial, target_pid;
|
||||
__u32 user_data, target_pid;
|
||||
__s32 key_serial;
|
||||
__u64 flags, task_storage_val, cgroup_id;
|
||||
|
||||
struct bpf_key *bpf_lookup_user_key(__u32 serial, __u64 flags) __ksym;
|
||||
struct bpf_key *bpf_lookup_user_key(__s32 serial, __u64 flags) __ksym;
|
||||
void bpf_key_put(struct bpf_key *key) __ksym;
|
||||
void bpf_rcu_read_lock(void) __ksym;
|
||||
void bpf_rcu_read_unlock(void) __ksym;
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
||||
__u32 monitored_pid;
|
||||
__u32 key_serial;
|
||||
__s32 key_serial;
|
||||
__u32 key_id;
|
||||
__u64 flags;
|
||||
|
||||
extern struct bpf_key *bpf_lookup_user_key(__u32 serial, __u64 flags) __ksym;
|
||||
extern struct bpf_key *bpf_lookup_user_key(__s32 serial, __u64 flags) __ksym;
|
||||
extern struct bpf_key *bpf_lookup_system_key(__u64 id) __ksym;
|
||||
extern void bpf_key_put(struct bpf_key *key) __ksym;
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ char digest[MAGIC_SIZE + SIZEOF_STRUCT_FSVERITY_DIGEST + SHA256_DIGEST_SIZE];
|
||||
__u32 monitored_pid;
|
||||
char sig[MAX_SIG_SIZE];
|
||||
__u32 sig_size;
|
||||
__u32 user_keyring_serial;
|
||||
__s32 user_keyring_serial;
|
||||
|
||||
SEC("lsm.s/file_open")
|
||||
int BPF_PROG(test_file_open, struct file *f)
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#define MAX_SIG_SIZE 1024
|
||||
|
||||
__u32 monitored_pid;
|
||||
__u32 user_keyring_serial;
|
||||
__s32 user_keyring_serial;
|
||||
__u64 system_keyring_id;
|
||||
|
||||
struct data {
|
||||
|
||||
@@ -27,7 +27,7 @@ struct bpf_key {} __attribute__((preserve_access_index));
|
||||
|
||||
extern void bpf_key_put(struct bpf_key *key) __ksym;
|
||||
extern struct bpf_key *bpf_lookup_system_key(__u64 id) __ksym;
|
||||
extern struct bpf_key *bpf_lookup_user_key(__u32 serial, __u64 flags) __ksym;
|
||||
extern struct bpf_key *bpf_lookup_user_key(__s32 serial, __u64 flags) __ksym;
|
||||
|
||||
/* BTF FUNC records are not generated for kfuncs referenced
|
||||
* from inline assembly. These records are necessary for
|
||||
|
||||
Reference in New Issue
Block a user