Skip to content

Commit 3f00c52

Browse files
Byte-LabAlexei Starovoitov
authored andcommitted
bpf: Allow trusted pointers to be passed to KF_TRUSTED_ARGS kfuncs
Kfuncs currently support specifying the KF_TRUSTED_ARGS flag to signal to the verifier that it should enforce that a BPF program passes it a "safe", trusted pointer. Currently, "safe" means that the pointer is either PTR_TO_CTX, or is refcounted. There may be cases, however, where the kernel passes a BPF program a safe / trusted pointer to an object that the BPF program wishes to use as a kptr, but because the object does not yet have a ref_obj_id from the perspective of the verifier, the program would be unable to pass it to a KF_ACQUIRE | KF_TRUSTED_ARGS kfunc. The solution is to expand the set of pointers that are considered trusted according to KF_TRUSTED_ARGS, so that programs can invoke kfuncs with these pointers without getting rejected by the verifier. There is already a PTR_UNTRUSTED flag that is set in some scenarios, such as when a BPF program reads a kptr directly from a map without performing a bpf_kptr_xchg() call. These pointers of course can and should be rejected by the verifier. Unfortunately, however, PTR_UNTRUSTED does not cover all the cases for safety that need to be addressed to adequately protect kfuncs. Specifically, pointers obtained by a BPF program "walking" a struct are _not_ considered PTR_UNTRUSTED according to BPF. For example, say that we were to add a kfunc called bpf_task_acquire(), with KF_ACQUIRE | KF_TRUSTED_ARGS, to acquire a struct task_struct *. If we only used PTR_UNTRUSTED to signal that a task was unsafe to pass to a kfunc, the verifier would mistakenly allow the following unsafe BPF program to be loaded: SEC("tp_btf/task_newtask") int BPF_PROG(unsafe_acquire_task, struct task_struct *task, u64 clone_flags) { struct task_struct *acquired, *nested; nested = task->last_wakee; /* Would not be rejected by the verifier. */ acquired = bpf_task_acquire(nested); if (!acquired) return 0; bpf_task_release(acquired); return 0; } To address this, this patch defines a new type flag called PTR_TRUSTED which tracks whether a PTR_TO_BTF_ID pointer is safe to pass to a KF_TRUSTED_ARGS kfunc or a BPF helper function. PTR_TRUSTED pointers are passed directly from the kernel as a tracepoint or struct_ops callback argument. Any nested pointer that is obtained from walking a PTR_TRUSTED pointer is no longer PTR_TRUSTED. From the example above, the struct task_struct *task argument is PTR_TRUSTED, but the 'nested' pointer obtained from 'task->last_wakee' is not PTR_TRUSTED. A subsequent patch will add kfuncs for storing a task kfunc as a kptr, and then another patch will add selftests to validate. Signed-off-by: David Vernet <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent ef66c54 commit 3f00c52

File tree

10 files changed

+164
-57
lines changed

10 files changed

+164
-57
lines changed

Documentation/bpf/kfuncs.rst

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -161,22 +161,20 @@ KF_ACQUIRE and KF_RET_NULL flags.
161161
--------------------------
162162

163163
The KF_TRUSTED_ARGS flag is used for kfuncs taking pointer arguments. It
164-
indicates that the all pointer arguments will always have a guaranteed lifetime,
165-
and pointers to kernel objects are always passed to helpers in their unmodified
166-
form (as obtained from acquire kfuncs).
167-
168-
It can be used to enforce that a pointer to a refcounted object acquired from a
169-
kfunc or BPF helper is passed as an argument to this kfunc without any
170-
modifications (e.g. pointer arithmetic) such that it is trusted and points to
171-
the original object.
172-
173-
Meanwhile, it is also allowed pass pointers to normal memory to such kfuncs,
174-
but those can have a non-zero offset.
175-
176-
This flag is often used for kfuncs that operate (change some property, perform
177-
some operation) on an object that was obtained using an acquire kfunc. Such
178-
kfuncs need an unchanged pointer to ensure the integrity of the operation being
179-
performed on the expected object.
164+
indicates that the all pointer arguments are valid, and that all pointers to
165+
BTF objects have been passed in their unmodified form (that is, at a zero
166+
offset, and without having been obtained from walking another pointer).
167+
168+
There are two types of pointers to kernel objects which are considered "valid":
169+
170+
1. Pointers which are passed as tracepoint or struct_ops callback arguments.
171+
2. Pointers which were returned from a KF_ACQUIRE or KF_KPTR_GET kfunc.
172+
173+
Pointers to non-BTF objects (e.g. scalar pointers) may also be passed to
174+
KF_TRUSTED_ARGS kfuncs, and may have a non-zero offset.
175+
176+
The definition of "valid" pointers is subject to change at any time, and has
177+
absolutely no ABI stability guarantees.
180178

181179
2.4.6 KF_SLEEPABLE flag
182180
-----------------------

include/linux/bpf.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,35 @@ enum bpf_type_flag {
543543
*/
544544
MEM_ALLOC = BIT(11 + BPF_BASE_TYPE_BITS),
545545

546+
/* PTR was passed from the kernel in a trusted context, and may be
547+
* passed to KF_TRUSTED_ARGS kfuncs or BPF helper functions.
548+
* Confusingly, this is _not_ the opposite of PTR_UNTRUSTED above.
549+
* PTR_UNTRUSTED refers to a kptr that was read directly from a map
550+
* without invoking bpf_kptr_xchg(). What we really need to know is
551+
* whether a pointer is safe to pass to a kfunc or BPF helper function.
552+
* While PTR_UNTRUSTED pointers are unsafe to pass to kfuncs and BPF
553+
* helpers, they do not cover all possible instances of unsafe
554+
* pointers. For example, a pointer that was obtained from walking a
555+
* struct will _not_ get the PTR_UNTRUSTED type modifier, despite the
556+
* fact that it may be NULL, invalid, etc. This is due to backwards
557+
* compatibility requirements, as this was the behavior that was first
558+
* introduced when kptrs were added. The behavior is now considered
559+
* deprecated, and PTR_UNTRUSTED will eventually be removed.
560+
*
561+
* PTR_TRUSTED, on the other hand, is a pointer that the kernel
562+
* guarantees to be valid and safe to pass to kfuncs and BPF helpers.
563+
* For example, pointers passed to tracepoint arguments are considered
564+
* PTR_TRUSTED, as are pointers that are passed to struct_ops
565+
* callbacks. As alluded to above, pointers that are obtained from
566+
* walking PTR_TRUSTED pointers are _not_ trusted. For example, if a
567+
* struct task_struct *task is PTR_TRUSTED, then accessing
568+
* task->last_wakee will lose the PTR_TRUSTED modifier when it's stored
569+
* in a BPF register. Similarly, pointers passed to certain programs
570+
* types such as kretprobes are not guaranteed to be valid, as they may
571+
* for example contain an object that was recently freed.
572+
*/
573+
PTR_TRUSTED = BIT(12 + BPF_BASE_TYPE_BITS),
574+
546575
__BPF_TYPE_FLAG_MAX,
547576
__BPF_TYPE_LAST_FLAG = __BPF_TYPE_FLAG_MAX - 1,
548577
};
@@ -636,6 +665,7 @@ enum bpf_return_type {
636665
RET_PTR_TO_RINGBUF_MEM_OR_NULL = PTR_MAYBE_NULL | MEM_RINGBUF | RET_PTR_TO_MEM,
637666
RET_PTR_TO_DYNPTR_MEM_OR_NULL = PTR_MAYBE_NULL | RET_PTR_TO_MEM,
638667
RET_PTR_TO_BTF_ID_OR_NULL = PTR_MAYBE_NULL | RET_PTR_TO_BTF_ID,
668+
RET_PTR_TO_BTF_ID_TRUSTED = PTR_TRUSTED | RET_PTR_TO_BTF_ID,
639669

640670
/* This must be the last entry. Its purpose is to ensure the enum is
641671
* wide enough to hold the higher bits reserved for bpf_type_flag.

include/linux/bpf_verifier.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,4 +680,11 @@ static inline bool bpf_prog_check_recur(const struct bpf_prog *prog)
680680
}
681681
}
682682

683+
#define BPF_REG_TRUSTED_MODIFIERS (MEM_ALLOC | PTR_TRUSTED)
684+
685+
static inline bool bpf_type_has_unsafe_modifiers(u32 type)
686+
{
687+
return type_flag(type) & ~BPF_REG_TRUSTED_MODIFIERS;
688+
}
689+
683690
#endif /* _LINUX_BPF_VERIFIER_H */

include/linux/btf.h

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,53 @@
1919
#define KF_RELEASE (1 << 1) /* kfunc is a release function */
2020
#define KF_RET_NULL (1 << 2) /* kfunc returns a pointer that may be NULL */
2121
#define KF_KPTR_GET (1 << 3) /* kfunc returns reference to a kptr */
22-
/* Trusted arguments are those which are meant to be referenced arguments with
23-
* unchanged offset. It is used to enforce that pointers obtained from acquire
24-
* kfuncs remain unmodified when being passed to helpers taking trusted args.
22+
/* Trusted arguments are those which are guaranteed to be valid when passed to
23+
* the kfunc. It is used to enforce that pointers obtained from either acquire
24+
* kfuncs, or from the main kernel on a tracepoint or struct_ops callback
25+
* invocation, remain unmodified when being passed to helpers taking trusted
26+
* args.
2527
*
26-
* Consider
27-
* struct foo {
28-
* int data;
29-
* struct foo *next;
30-
* };
28+
* Consider, for example, the following new task tracepoint:
3129
*
32-
* struct bar {
33-
* int data;
34-
* struct foo f;
35-
* };
30+
* SEC("tp_btf/task_newtask")
31+
* int BPF_PROG(new_task_tp, struct task_struct *task, u64 clone_flags)
32+
* {
33+
* ...
34+
* }
3635
*
37-
* struct foo *f = alloc_foo(); // Acquire kfunc
38-
* struct bar *b = alloc_bar(); // Acquire kfunc
36+
* And the following kfunc:
3937
*
40-
* If a kfunc set_foo_data() wants to operate only on the allocated object, it
41-
* will set the KF_TRUSTED_ARGS flag, which will prevent unsafe usage like:
38+
* BTF_ID_FLAGS(func, bpf_task_acquire, KF_ACQUIRE | KF_TRUSTED_ARGS)
4239
*
43-
* set_foo_data(f, 42); // Allowed
44-
* set_foo_data(f->next, 42); // Rejected, non-referenced pointer
45-
* set_foo_data(&f->next, 42);// Rejected, referenced, but wrong type
46-
* set_foo_data(&b->f, 42); // Rejected, referenced, but bad offset
40+
* All invocations to the kfunc must pass the unmodified, unwalked task:
4741
*
48-
* In the final case, usually for the purposes of type matching, it is deduced
49-
* by looking at the type of the member at the offset, but due to the
50-
* requirement of trusted argument, this deduction will be strict and not done
51-
* for this case.
42+
* bpf_task_acquire(task); // Allowed
43+
* bpf_task_acquire(task->last_wakee); // Rejected, walked task
44+
*
45+
* Programs may also pass referenced tasks directly to the kfunc:
46+
*
47+
* struct task_struct *acquired;
48+
*
49+
* acquired = bpf_task_acquire(task); // Allowed, same as above
50+
* bpf_task_acquire(acquired); // Allowed
51+
* bpf_task_acquire(task); // Allowed
52+
* bpf_task_acquire(acquired->last_wakee); // Rejected, walked task
53+
*
54+
* Programs may _not_, however, pass a task from an arbitrary fentry/fexit, or
55+
* kprobe/kretprobe to the kfunc, as BPF cannot guarantee that all of these
56+
* pointers are guaranteed to be safe. For example, the following BPF program
57+
* would be rejected:
58+
*
59+
* SEC("kretprobe/free_task")
60+
* int BPF_PROG(free_task_probe, struct task_struct *tsk)
61+
* {
62+
* struct task_struct *acquired;
63+
*
64+
* acquired = bpf_task_acquire(acquired); // Rejected, not a trusted pointer
65+
* bpf_task_release(acquired);
66+
*
67+
* return 0;
68+
* }
5269
*/
5370
#define KF_TRUSTED_ARGS (1 << 4) /* kfunc only takes trusted pointer arguments */
5471
#define KF_SLEEPABLE (1 << 5) /* kfunc may sleep */

kernel/bpf/btf.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5799,6 +5799,11 @@ static u32 get_ctx_arg_idx(struct btf *btf, const struct btf_type *func_proto,
57995799
return nr_args + 1;
58005800
}
58015801

5802+
static bool prog_type_args_trusted(enum bpf_prog_type prog_type)
5803+
{
5804+
return prog_type == BPF_PROG_TYPE_TRACING || prog_type == BPF_PROG_TYPE_STRUCT_OPS;
5805+
}
5806+
58025807
bool btf_ctx_access(int off, int size, enum bpf_access_type type,
58035808
const struct bpf_prog *prog,
58045809
struct bpf_insn_access_aux *info)
@@ -5942,6 +5947,9 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type,
59425947
}
59435948

59445949
info->reg_type = PTR_TO_BTF_ID;
5950+
if (prog_type_args_trusted(prog->type))
5951+
info->reg_type |= PTR_TRUSTED;
5952+
59455953
if (tgt_prog) {
59465954
enum bpf_prog_type tgt_type;
59475955

kernel/bpf/verifier.c

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -589,12 +589,13 @@ static const char *reg_type_str(struct bpf_verifier_env *env,
589589
strncpy(postfix, "_or_null", 16);
590590
}
591591

592-
snprintf(prefix, sizeof(prefix), "%s%s%s%s%s",
592+
snprintf(prefix, sizeof(prefix), "%s%s%s%s%s%s",
593593
type & MEM_RDONLY ? "rdonly_" : "",
594594
type & MEM_RINGBUF ? "ringbuf_" : "",
595595
type & MEM_USER ? "user_" : "",
596596
type & MEM_PERCPU ? "percpu_" : "",
597-
type & PTR_UNTRUSTED ? "untrusted_" : ""
597+
type & PTR_UNTRUSTED ? "untrusted_" : "",
598+
type & PTR_TRUSTED ? "trusted_" : ""
598599
);
599600

600601
snprintf(env->type_str_buf, TYPE_STR_BUF_LEN, "%s%s%s",
@@ -3856,7 +3857,7 @@ static int map_kptr_match_type(struct bpf_verifier_env *env,
38563857
struct bpf_reg_state *reg, u32 regno)
38573858
{
38583859
const char *targ_name = kernel_type_name(kptr_field->kptr.btf, kptr_field->kptr.btf_id);
3859-
int perm_flags = PTR_MAYBE_NULL;
3860+
int perm_flags = PTR_MAYBE_NULL | PTR_TRUSTED;
38603861
const char *reg_name = "";
38613862

38623863
/* Only unreferenced case accepts untrusted pointers */
@@ -4732,6 +4733,9 @@ static int check_ptr_to_btf_access(struct bpf_verifier_env *env,
47324733
if (type_flag(reg->type) & PTR_UNTRUSTED)
47334734
flag |= PTR_UNTRUSTED;
47344735

4736+
/* Any pointer obtained from walking a trusted pointer is no longer trusted. */
4737+
flag &= ~PTR_TRUSTED;
4738+
47354739
if (atype == BPF_READ && value_regno >= 0)
47364740
mark_btf_ld_reg(env, regs, value_regno, ret, reg->btf, btf_id, flag);
47374741

@@ -5844,6 +5848,7 @@ static const struct bpf_reg_types btf_id_sock_common_types = {
58445848
PTR_TO_TCP_SOCK,
58455849
PTR_TO_XDP_SOCK,
58465850
PTR_TO_BTF_ID,
5851+
PTR_TO_BTF_ID | PTR_TRUSTED,
58475852
},
58485853
.btf_id = &btf_sock_ids[BTF_SOCK_TYPE_SOCK_COMMON],
58495854
};
@@ -5884,8 +5889,18 @@ static const struct bpf_reg_types scalar_types = { .types = { SCALAR_VALUE } };
58845889
static const struct bpf_reg_types context_types = { .types = { PTR_TO_CTX } };
58855890
static const struct bpf_reg_types ringbuf_mem_types = { .types = { PTR_TO_MEM | MEM_RINGBUF } };
58865891
static const struct bpf_reg_types const_map_ptr_types = { .types = { CONST_PTR_TO_MAP } };
5887-
static const struct bpf_reg_types btf_ptr_types = { .types = { PTR_TO_BTF_ID } };
5888-
static const struct bpf_reg_types percpu_btf_ptr_types = { .types = { PTR_TO_BTF_ID | MEM_PERCPU } };
5892+
static const struct bpf_reg_types btf_ptr_types = {
5893+
.types = {
5894+
PTR_TO_BTF_ID,
5895+
PTR_TO_BTF_ID | PTR_TRUSTED,
5896+
},
5897+
};
5898+
static const struct bpf_reg_types percpu_btf_ptr_types = {
5899+
.types = {
5900+
PTR_TO_BTF_ID | MEM_PERCPU,
5901+
PTR_TO_BTF_ID | MEM_PERCPU | PTR_TRUSTED,
5902+
}
5903+
};
58895904
static const struct bpf_reg_types func_ptr_types = { .types = { PTR_TO_FUNC } };
58905905
static const struct bpf_reg_types stack_ptr_types = { .types = { PTR_TO_STACK } };
58915906
static const struct bpf_reg_types const_str_ptr_types = { .types = { PTR_TO_MAP_VALUE } };
@@ -5973,7 +5988,7 @@ static int check_reg_type(struct bpf_verifier_env *env, u32 regno,
59735988
return -EACCES;
59745989

59755990
found:
5976-
if (reg->type == PTR_TO_BTF_ID) {
5991+
if (reg->type == PTR_TO_BTF_ID || reg->type & PTR_TRUSTED) {
59775992
/* For bpf_sk_release, it needs to match against first member
59785993
* 'struct sock_common', hence make an exception for it. This
59795994
* allows bpf_sk_release to work for multiple socket types.
@@ -6055,6 +6070,8 @@ int check_func_arg_reg_off(struct bpf_verifier_env *env,
60556070
*/
60566071
case PTR_TO_BTF_ID:
60576072
case PTR_TO_BTF_ID | MEM_ALLOC:
6073+
case PTR_TO_BTF_ID | PTR_TRUSTED:
6074+
case PTR_TO_BTF_ID | MEM_ALLOC | PTR_TRUSTED:
60586075
/* When referenced PTR_TO_BTF_ID is passed to release function,
60596076
* it's fixed offset must be 0. In the other cases, fixed offset
60606077
* can be non-zero.
@@ -7939,6 +7956,25 @@ static bool is_kfunc_arg_kptr_get(struct bpf_kfunc_call_arg_meta *meta, int arg)
79397956
return arg == 0 && (meta->kfunc_flags & KF_KPTR_GET);
79407957
}
79417958

7959+
static bool is_trusted_reg(const struct bpf_reg_state *reg)
7960+
{
7961+
/* A referenced register is always trusted. */
7962+
if (reg->ref_obj_id)
7963+
return true;
7964+
7965+
/* If a register is not referenced, it is trusted if it has either the
7966+
* MEM_ALLOC or PTR_TRUSTED type modifiers, and no others. Some of the
7967+
* other type modifiers may be safe, but we elect to take an opt-in
7968+
* approach here as some (e.g. PTR_UNTRUSTED and PTR_MAYBE_NULL) are
7969+
* not.
7970+
*
7971+
* Eventually, we should make PTR_TRUSTED the single source of truth
7972+
* for whether a register is trusted.
7973+
*/
7974+
return type_flag(reg->type) & BPF_REG_TRUSTED_MODIFIERS &&
7975+
!bpf_type_has_unsafe_modifiers(reg->type);
7976+
}
7977+
79427978
static bool __kfunc_param_match_suffix(const struct btf *btf,
79437979
const struct btf_param *arg,
79447980
const char *suffix)
@@ -8220,7 +8256,7 @@ static int process_kf_arg_ptr_to_btf_id(struct bpf_verifier_env *env,
82208256
const char *reg_ref_tname;
82218257
u32 reg_ref_id;
82228258

8223-
if (reg->type == PTR_TO_BTF_ID) {
8259+
if (base_type(reg->type) == PTR_TO_BTF_ID) {
82248260
reg_btf = reg->btf;
82258261
reg_ref_id = reg->btf_id;
82268262
} else {
@@ -8366,6 +8402,7 @@ static int check_reg_allocation_locked(struct bpf_verifier_env *env, struct bpf_
83668402
ptr = reg->map_ptr;
83678403
break;
83688404
case PTR_TO_BTF_ID | MEM_ALLOC:
8405+
case PTR_TO_BTF_ID | MEM_ALLOC | PTR_TRUSTED:
83698406
ptr = reg->btf;
83708407
break;
83718408
default:
@@ -8596,8 +8633,9 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_
85968633
case KF_ARG_PTR_TO_BTF_ID:
85978634
if (!is_kfunc_trusted_args(meta))
85988635
break;
8599-
if (!reg->ref_obj_id) {
8600-
verbose(env, "R%d must be referenced\n", regno);
8636+
8637+
if (!is_trusted_reg(reg)) {
8638+
verbose(env, "R%d must be referenced or trusted\n", regno);
86018639
return -EINVAL;
86028640
}
86038641
fallthrough;
@@ -8702,9 +8740,13 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_
87028740
break;
87038741
case KF_ARG_PTR_TO_BTF_ID:
87048742
/* Only base_type is checked, further checks are done here */
8705-
if (reg->type != PTR_TO_BTF_ID &&
8706-
(!reg2btf_ids[base_type(reg->type)] || type_flag(reg->type))) {
8707-
verbose(env, "arg#%d expected pointer to btf or socket\n", i);
8743+
if ((base_type(reg->type) != PTR_TO_BTF_ID ||
8744+
bpf_type_has_unsafe_modifiers(reg->type)) &&
8745+
!reg2btf_ids[base_type(reg->type)]) {
8746+
verbose(env, "arg#%d is %s ", i, reg_type_str(env, reg->type));
8747+
verbose(env, "expected %s or socket\n",
8748+
reg_type_str(env, base_type(reg->type) |
8749+
(type_flag(reg->type) & BPF_REG_TRUSTED_MODIFIERS)));
87088750
return -EINVAL;
87098751
}
87108752
ret = process_kf_arg_ptr_to_btf_id(env, reg, ref_t, ref_tname, ref_id, meta, i);
@@ -14713,13 +14755,16 @@ static int convert_ctx_accesses(struct bpf_verifier_env *env)
1471314755
break;
1471414756
case PTR_TO_BTF_ID:
1471514757
case PTR_TO_BTF_ID | PTR_UNTRUSTED:
14758+
case PTR_TO_BTF_ID | PTR_TRUSTED:
1471614759
/* PTR_TO_BTF_ID | MEM_ALLOC always has a valid lifetime, unlike
1471714760
* PTR_TO_BTF_ID, and an active ref_obj_id, but the same cannot
1471814761
* be said once it is marked PTR_UNTRUSTED, hence we must handle
1471914762
* any faults for loads into such types. BPF_WRITE is disallowed
1472014763
* for this case.
1472114764
*/
1472214765
case PTR_TO_BTF_ID | MEM_ALLOC | PTR_UNTRUSTED:
14766+
case PTR_TO_BTF_ID | PTR_UNTRUSTED | PTR_TRUSTED:
14767+
case PTR_TO_BTF_ID | PTR_UNTRUSTED | MEM_ALLOC | PTR_TRUSTED:
1472314768
if (type == BPF_READ) {
1472414769
insn->code = BPF_LDX | BPF_PROBE_MEM |
1472514770
BPF_SIZE((insn)->code);

kernel/trace/bpf_trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ BPF_CALL_0(bpf_get_current_task_btf)
774774
const struct bpf_func_proto bpf_get_current_task_btf_proto = {
775775
.func = bpf_get_current_task_btf,
776776
.gpl_only = true,
777-
.ret_type = RET_PTR_TO_BTF_ID,
777+
.ret_type = RET_PTR_TO_BTF_ID_TRUSTED,
778778
.ret_btf_id = &btf_tracing_ids[BTF_TRACING_TYPE_TASK],
779779
};
780780

net/ipv4/bpf_tcp_ca.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ static bool bpf_tcp_ca_is_valid_access(int off, int size,
6161
if (!bpf_tracing_btf_ctx_access(off, size, type, prog, info))
6262
return false;
6363

64-
if (info->reg_type == PTR_TO_BTF_ID && info->btf_id == sock_id)
64+
if (base_type(info->reg_type) == PTR_TO_BTF_ID &&
65+
!bpf_type_has_unsafe_modifiers(info->reg_type) &&
66+
info->btf_id == sock_id)
6567
/* promote it to tcp_sock */
6668
info->btf_id = tcp_sock_id;
6769

tools/testing/selftests/bpf/verifier/calls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
},
110110
.prog_type = BPF_PROG_TYPE_SCHED_CLS,
111111
.result = REJECT,
112-
.errstr = "arg#0 expected pointer to btf or socket",
112+
.errstr = "arg#0 is ptr_or_null_ expected ptr_ or socket",
113113
.fixup_kfunc_btf_id = {
114114
{ "bpf_kfunc_call_test_acquire", 3 },
115115
{ "bpf_kfunc_call_test_release", 5 },

0 commit comments

Comments
 (0)