Skip to content

Commit 39f19eb

Browse files
4astdavem330
authored andcommitted
bpf: rename ARG_PTR_TO_STACK
since ARG_PTR_TO_STACK is no longer just pointer to stack rename it to ARG_PTR_TO_MEM and adjust comment. Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 06c1c04 commit 39f19eb

File tree

5 files changed

+52
-52
lines changed

5 files changed

+52
-52
lines changed

include/linux/bpf.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ enum bpf_arg_type {
6969
/* the following constraints used to prototype bpf_memcmp() and other
7070
* functions that access data on eBPF program stack
7171
*/
72-
ARG_PTR_TO_STACK, /* any pointer to eBPF program stack */
73-
ARG_PTR_TO_RAW_STACK, /* any pointer to eBPF program stack, area does not
74-
* need to be initialized, helper function must fill
75-
* all bytes or clear them in error case.
72+
ARG_PTR_TO_MEM, /* pointer to valid memory (stack, packet, map value) */
73+
ARG_PTR_TO_UNINIT_MEM, /* pointer to memory does not need to be initialized,
74+
* helper function must fill all bytes or clear
75+
* them in error case.
7676
*/
7777

78-
ARG_CONST_STACK_SIZE, /* number of bytes accessed from stack */
79-
ARG_CONST_STACK_SIZE_OR_ZERO, /* number of bytes accessed from stack or 0 */
78+
ARG_CONST_SIZE, /* number of bytes accessed from memory */
79+
ARG_CONST_SIZE_OR_ZERO, /* number of bytes accessed from memory or 0 */
8080

8181
ARG_PTR_TO_CTX, /* pointer to context */
8282
ARG_ANYTHING, /* any (initialized) argument is ok */

kernel/bpf/helpers.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,6 @@ const struct bpf_func_proto bpf_get_current_comm_proto = {
176176
.func = bpf_get_current_comm,
177177
.gpl_only = false,
178178
.ret_type = RET_INTEGER,
179-
.arg1_type = ARG_PTR_TO_RAW_STACK,
180-
.arg2_type = ARG_CONST_STACK_SIZE,
179+
.arg1_type = ARG_PTR_TO_UNINIT_MEM,
180+
.arg2_type = ARG_CONST_SIZE,
181181
};

kernel/bpf/verifier.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,8 +1034,8 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 regno,
10341034
expected_type = PTR_TO_STACK;
10351035
if (type != PTR_TO_PACKET && type != expected_type)
10361036
goto err_type;
1037-
} else if (arg_type == ARG_CONST_STACK_SIZE ||
1038-
arg_type == ARG_CONST_STACK_SIZE_OR_ZERO) {
1037+
} else if (arg_type == ARG_CONST_SIZE ||
1038+
arg_type == ARG_CONST_SIZE_OR_ZERO) {
10391039
expected_type = CONST_IMM;
10401040
/* One exception. Allow UNKNOWN_VALUE registers when the
10411041
* boundaries are known and don't cause unsafe memory accesses
@@ -1050,8 +1050,8 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 regno,
10501050
expected_type = PTR_TO_CTX;
10511051
if (type != expected_type)
10521052
goto err_type;
1053-
} else if (arg_type == ARG_PTR_TO_STACK ||
1054-
arg_type == ARG_PTR_TO_RAW_STACK) {
1053+
} else if (arg_type == ARG_PTR_TO_MEM ||
1054+
arg_type == ARG_PTR_TO_UNINIT_MEM) {
10551055
expected_type = PTR_TO_STACK;
10561056
/* One exception here. In case function allows for NULL to be
10571057
* passed in as argument, it's a CONST_IMM type. Final test
@@ -1062,7 +1062,7 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 regno,
10621062
else if (type != PTR_TO_PACKET && type != PTR_TO_MAP_VALUE &&
10631063
type != PTR_TO_MAP_VALUE_ADJ && type != expected_type)
10641064
goto err_type;
1065-
meta->raw_mode = arg_type == ARG_PTR_TO_RAW_STACK;
1065+
meta->raw_mode = arg_type == ARG_PTR_TO_UNINIT_MEM;
10661066
} else {
10671067
verbose("unsupported arg_type %d\n", arg_type);
10681068
return -EFAULT;
@@ -1108,17 +1108,17 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 regno,
11081108
err = check_stack_boundary(env, regno,
11091109
meta->map_ptr->value_size,
11101110
false, NULL);
1111-
} else if (arg_type == ARG_CONST_STACK_SIZE ||
1112-
arg_type == ARG_CONST_STACK_SIZE_OR_ZERO) {
1113-
bool zero_size_allowed = (arg_type == ARG_CONST_STACK_SIZE_OR_ZERO);
1111+
} else if (arg_type == ARG_CONST_SIZE ||
1112+
arg_type == ARG_CONST_SIZE_OR_ZERO) {
1113+
bool zero_size_allowed = (arg_type == ARG_CONST_SIZE_OR_ZERO);
11141114

11151115
/* bpf_xxx(..., buf, len) call will access 'len' bytes
11161116
* from stack pointer 'buf'. Check it
11171117
* note: regno == len, regno - 1 == buf
11181118
*/
11191119
if (regno == 0) {
11201120
/* kernel subsystem misconfigured verifier */
1121-
verbose("ARG_CONST_STACK_SIZE cannot be first argument\n");
1121+
verbose("ARG_CONST_SIZE cannot be first argument\n");
11221122
return -EACCES;
11231123
}
11241124

@@ -1235,15 +1235,15 @@ static int check_raw_mode(const struct bpf_func_proto *fn)
12351235
{
12361236
int count = 0;
12371237

1238-
if (fn->arg1_type == ARG_PTR_TO_RAW_STACK)
1238+
if (fn->arg1_type == ARG_PTR_TO_UNINIT_MEM)
12391239
count++;
1240-
if (fn->arg2_type == ARG_PTR_TO_RAW_STACK)
1240+
if (fn->arg2_type == ARG_PTR_TO_UNINIT_MEM)
12411241
count++;
1242-
if (fn->arg3_type == ARG_PTR_TO_RAW_STACK)
1242+
if (fn->arg3_type == ARG_PTR_TO_UNINIT_MEM)
12431243
count++;
1244-
if (fn->arg4_type == ARG_PTR_TO_RAW_STACK)
1244+
if (fn->arg4_type == ARG_PTR_TO_UNINIT_MEM)
12451245
count++;
1246-
if (fn->arg5_type == ARG_PTR_TO_RAW_STACK)
1246+
if (fn->arg5_type == ARG_PTR_TO_UNINIT_MEM)
12471247
count++;
12481248

12491249
return count > 1 ? -EINVAL : 0;

kernel/trace/bpf_trace.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ static const struct bpf_func_proto bpf_probe_read_proto = {
7676
.func = bpf_probe_read,
7777
.gpl_only = true,
7878
.ret_type = RET_INTEGER,
79-
.arg1_type = ARG_PTR_TO_RAW_STACK,
80-
.arg2_type = ARG_CONST_STACK_SIZE,
79+
.arg1_type = ARG_PTR_TO_UNINIT_MEM,
80+
.arg2_type = ARG_CONST_SIZE,
8181
.arg3_type = ARG_ANYTHING,
8282
};
8383

@@ -109,8 +109,8 @@ static const struct bpf_func_proto bpf_probe_write_user_proto = {
109109
.gpl_only = true,
110110
.ret_type = RET_INTEGER,
111111
.arg1_type = ARG_ANYTHING,
112-
.arg2_type = ARG_PTR_TO_STACK,
113-
.arg3_type = ARG_CONST_STACK_SIZE,
112+
.arg2_type = ARG_PTR_TO_MEM,
113+
.arg3_type = ARG_CONST_SIZE,
114114
};
115115

116116
static const struct bpf_func_proto *bpf_get_probe_write_proto(void)
@@ -213,8 +213,8 @@ static const struct bpf_func_proto bpf_trace_printk_proto = {
213213
.func = bpf_trace_printk,
214214
.gpl_only = true,
215215
.ret_type = RET_INTEGER,
216-
.arg1_type = ARG_PTR_TO_STACK,
217-
.arg2_type = ARG_CONST_STACK_SIZE,
216+
.arg1_type = ARG_PTR_TO_MEM,
217+
.arg2_type = ARG_CONST_SIZE,
218218
};
219219

220220
const struct bpf_func_proto *bpf_get_trace_printk_proto(void)
@@ -329,8 +329,8 @@ static const struct bpf_func_proto bpf_perf_event_output_proto = {
329329
.arg1_type = ARG_PTR_TO_CTX,
330330
.arg2_type = ARG_CONST_MAP_PTR,
331331
.arg3_type = ARG_ANYTHING,
332-
.arg4_type = ARG_PTR_TO_STACK,
333-
.arg5_type = ARG_CONST_STACK_SIZE,
332+
.arg4_type = ARG_PTR_TO_MEM,
333+
.arg5_type = ARG_CONST_SIZE,
334334
};
335335

336336
static DEFINE_PER_CPU(struct pt_regs, bpf_pt_regs);
@@ -492,8 +492,8 @@ static const struct bpf_func_proto bpf_perf_event_output_proto_tp = {
492492
.arg1_type = ARG_PTR_TO_CTX,
493493
.arg2_type = ARG_CONST_MAP_PTR,
494494
.arg3_type = ARG_ANYTHING,
495-
.arg4_type = ARG_PTR_TO_STACK,
496-
.arg5_type = ARG_CONST_STACK_SIZE,
495+
.arg4_type = ARG_PTR_TO_MEM,
496+
.arg5_type = ARG_CONST_SIZE,
497497
};
498498

499499
BPF_CALL_3(bpf_get_stackid_tp, void *, tp_buff, struct bpf_map *, map,

net/core/filter.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,8 +1416,8 @@ static const struct bpf_func_proto bpf_skb_store_bytes_proto = {
14161416
.ret_type = RET_INTEGER,
14171417
.arg1_type = ARG_PTR_TO_CTX,
14181418
.arg2_type = ARG_ANYTHING,
1419-
.arg3_type = ARG_PTR_TO_STACK,
1420-
.arg4_type = ARG_CONST_STACK_SIZE,
1419+
.arg3_type = ARG_PTR_TO_MEM,
1420+
.arg4_type = ARG_CONST_SIZE,
14211421
.arg5_type = ARG_ANYTHING,
14221422
};
14231423

@@ -1447,8 +1447,8 @@ static const struct bpf_func_proto bpf_skb_load_bytes_proto = {
14471447
.ret_type = RET_INTEGER,
14481448
.arg1_type = ARG_PTR_TO_CTX,
14491449
.arg2_type = ARG_ANYTHING,
1450-
.arg3_type = ARG_PTR_TO_RAW_STACK,
1451-
.arg4_type = ARG_CONST_STACK_SIZE,
1450+
.arg3_type = ARG_PTR_TO_UNINIT_MEM,
1451+
.arg4_type = ARG_CONST_SIZE,
14521452
};
14531453

14541454
BPF_CALL_2(bpf_skb_pull_data, struct sk_buff *, skb, u32, len)
@@ -1601,10 +1601,10 @@ static const struct bpf_func_proto bpf_csum_diff_proto = {
16011601
.gpl_only = false,
16021602
.pkt_access = true,
16031603
.ret_type = RET_INTEGER,
1604-
.arg1_type = ARG_PTR_TO_STACK,
1605-
.arg2_type = ARG_CONST_STACK_SIZE_OR_ZERO,
1606-
.arg3_type = ARG_PTR_TO_STACK,
1607-
.arg4_type = ARG_CONST_STACK_SIZE_OR_ZERO,
1604+
.arg1_type = ARG_PTR_TO_MEM,
1605+
.arg2_type = ARG_CONST_SIZE_OR_ZERO,
1606+
.arg3_type = ARG_PTR_TO_MEM,
1607+
.arg4_type = ARG_CONST_SIZE_OR_ZERO,
16081608
.arg5_type = ARG_ANYTHING,
16091609
};
16101610

@@ -2306,8 +2306,8 @@ static const struct bpf_func_proto bpf_skb_event_output_proto = {
23062306
.arg1_type = ARG_PTR_TO_CTX,
23072307
.arg2_type = ARG_CONST_MAP_PTR,
23082308
.arg3_type = ARG_ANYTHING,
2309-
.arg4_type = ARG_PTR_TO_STACK,
2310-
.arg5_type = ARG_CONST_STACK_SIZE,
2309+
.arg4_type = ARG_PTR_TO_MEM,
2310+
.arg5_type = ARG_CONST_SIZE,
23112311
};
23122312

23132313
static unsigned short bpf_tunnel_key_af(u64 flags)
@@ -2377,8 +2377,8 @@ static const struct bpf_func_proto bpf_skb_get_tunnel_key_proto = {
23772377
.gpl_only = false,
23782378
.ret_type = RET_INTEGER,
23792379
.arg1_type = ARG_PTR_TO_CTX,
2380-
.arg2_type = ARG_PTR_TO_RAW_STACK,
2381-
.arg3_type = ARG_CONST_STACK_SIZE,
2380+
.arg2_type = ARG_PTR_TO_UNINIT_MEM,
2381+
.arg3_type = ARG_CONST_SIZE,
23822382
.arg4_type = ARG_ANYTHING,
23832383
};
23842384

@@ -2412,8 +2412,8 @@ static const struct bpf_func_proto bpf_skb_get_tunnel_opt_proto = {
24122412
.gpl_only = false,
24132413
.ret_type = RET_INTEGER,
24142414
.arg1_type = ARG_PTR_TO_CTX,
2415-
.arg2_type = ARG_PTR_TO_RAW_STACK,
2416-
.arg3_type = ARG_CONST_STACK_SIZE,
2415+
.arg2_type = ARG_PTR_TO_UNINIT_MEM,
2416+
.arg3_type = ARG_CONST_SIZE,
24172417
};
24182418

24192419
static struct metadata_dst __percpu *md_dst;
@@ -2483,8 +2483,8 @@ static const struct bpf_func_proto bpf_skb_set_tunnel_key_proto = {
24832483
.gpl_only = false,
24842484
.ret_type = RET_INTEGER,
24852485
.arg1_type = ARG_PTR_TO_CTX,
2486-
.arg2_type = ARG_PTR_TO_STACK,
2487-
.arg3_type = ARG_CONST_STACK_SIZE,
2486+
.arg2_type = ARG_PTR_TO_MEM,
2487+
.arg3_type = ARG_CONST_SIZE,
24882488
.arg4_type = ARG_ANYTHING,
24892489
};
24902490

@@ -2509,8 +2509,8 @@ static const struct bpf_func_proto bpf_skb_set_tunnel_opt_proto = {
25092509
.gpl_only = false,
25102510
.ret_type = RET_INTEGER,
25112511
.arg1_type = ARG_PTR_TO_CTX,
2512-
.arg2_type = ARG_PTR_TO_STACK,
2513-
.arg3_type = ARG_CONST_STACK_SIZE,
2512+
.arg2_type = ARG_PTR_TO_MEM,
2513+
.arg3_type = ARG_CONST_SIZE,
25142514
};
25152515

25162516
static const struct bpf_func_proto *
@@ -2593,8 +2593,8 @@ static const struct bpf_func_proto bpf_xdp_event_output_proto = {
25932593
.arg1_type = ARG_PTR_TO_CTX,
25942594
.arg2_type = ARG_CONST_MAP_PTR,
25952595
.arg3_type = ARG_ANYTHING,
2596-
.arg4_type = ARG_PTR_TO_STACK,
2597-
.arg5_type = ARG_CONST_STACK_SIZE,
2596+
.arg4_type = ARG_PTR_TO_MEM,
2597+
.arg5_type = ARG_CONST_SIZE,
25982598
};
25992599

26002600
static const struct bpf_func_proto *

0 commit comments

Comments
 (0)