Skip to content

Commit 6c83822

Browse files
jejbKernel Patches Daemon
authored andcommitted
bpf: remove bpf_key reference
bpf_key.has_ref is used to distinguish between real key pointers and the fake key pointers that are used for system keyrings (to ensure the actual pointers to system keyrings are never visible outside certs/system_keyring.c). The keyrings subsystem has an exported function to do this, so use that in the bpf keyring code eliminating the need to store has_ref. Signed-off-by: James Bottomley <[email protected]>
1 parent 353b190 commit 6c83822

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

kernel/trace/bpf_trace.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,6 @@ static const struct bpf_func_proto bpf_get_func_arg_cnt_proto = {
12441244
#ifdef CONFIG_KEYS
12451245
struct bpf_key {
12461246
struct key *key;
1247-
bool has_ref;
12481247
};
12491248

12501249
__bpf_kfunc_start_defs();
@@ -1297,7 +1296,6 @@ __bpf_kfunc struct bpf_key *bpf_lookup_user_key(s32 serial, u64 flags)
12971296
}
12981297

12991298
bkey->key = key_ref_to_ptr(key_ref);
1300-
bkey->has_ref = true;
13011299

13021300
return bkey;
13031301
}
@@ -1335,7 +1333,6 @@ __bpf_kfunc struct bpf_key *bpf_lookup_system_key(u64 id)
13351333
return NULL;
13361334

13371335
bkey->key = (struct key *)(unsigned long)id;
1338-
bkey->has_ref = false;
13391336

13401337
return bkey;
13411338
}
@@ -1349,7 +1346,7 @@ __bpf_kfunc struct bpf_key *bpf_lookup_system_key(u64 id)
13491346
*/
13501347
__bpf_kfunc void bpf_key_put(struct bpf_key *bkey)
13511348
{
1352-
if (bkey->has_ref)
1349+
if (system_keyring_id_check((unsigned long)bkey->key) < 0)
13531350
key_put(bkey->key);
13541351

13551352
kfree(bkey);
@@ -1377,7 +1374,7 @@ __bpf_kfunc int bpf_verify_pkcs7_signature(struct bpf_dynptr *data_p,
13771374
u32 data_len, sig_len;
13781375
int ret;
13791376

1380-
if (trusted_keyring->has_ref) {
1377+
if (system_keyring_id_check((unsigned long)trusted_keyring->key) < 0) {
13811378
/*
13821379
* Do the permission check deferred in bpf_lookup_user_key().
13831380
* See bpf_lookup_user_key() for more details.

0 commit comments

Comments
 (0)