File tree Expand file tree Collapse file tree 5 files changed +27
-15
lines changed Expand file tree Collapse file tree 5 files changed +27
-15
lines changed Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ struct bpf_map {
56
56
struct work_struct work ;
57
57
atomic_t usercnt ;
58
58
struct bpf_map * inner_map_meta ;
59
- u8 name [BPF_OBJ_NAME_LEN ];
59
+ char name [BPF_OBJ_NAME_LEN ];
60
60
};
61
61
62
62
/* function argument constraints */
@@ -189,7 +189,7 @@ struct bpf_prog_aux {
189
189
struct bpf_prog * prog ;
190
190
struct user_struct * user ;
191
191
u64 load_time ; /* ns since boottime */
192
- u8 name [BPF_OBJ_NAME_LEN ];
192
+ char name [BPF_OBJ_NAME_LEN ];
193
193
union {
194
194
struct work_struct work ;
195
195
struct rcu_head rcu ;
Original file line number Diff line number Diff line change @@ -230,7 +230,7 @@ union bpf_attr {
230
230
__u32 numa_node ; /* numa node (effective only if
231
231
* BPF_F_NUMA_NODE is set).
232
232
*/
233
- __u8 map_name [BPF_OBJ_NAME_LEN ];
233
+ char map_name [BPF_OBJ_NAME_LEN ];
234
234
};
235
235
236
236
struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
@@ -253,7 +253,7 @@ union bpf_attr {
253
253
__aligned_u64 log_buf ; /* user supplied buffer */
254
254
__u32 kern_version ; /* checked when prog_type=kprobe */
255
255
__u32 prog_flags ;
256
- __u8 prog_name [BPF_OBJ_NAME_LEN ];
256
+ char prog_name [BPF_OBJ_NAME_LEN ];
257
257
};
258
258
259
259
struct { /* anonymous struct used by BPF_OBJ_* commands */
@@ -888,7 +888,7 @@ struct bpf_prog_info {
888
888
__u32 created_by_uid ;
889
889
__u32 nr_map_ids ;
890
890
__aligned_u64 map_ids ;
891
- __u8 name [BPF_OBJ_NAME_LEN ];
891
+ char name [BPF_OBJ_NAME_LEN ];
892
892
} __attribute__((aligned (8 )));
893
893
894
894
struct bpf_map_info {
@@ -898,7 +898,7 @@ struct bpf_map_info {
898
898
__u32 value_size ;
899
899
__u32 max_entries ;
900
900
__u32 map_flags ;
901
- __u8 name [BPF_OBJ_NAME_LEN ];
901
+ char name [BPF_OBJ_NAME_LEN ];
902
902
} __attribute__((aligned (8 )));
903
903
904
904
/* User bpf_sock_ops struct to access socket values and specify request ops
Original file line number Diff line number Diff line change @@ -309,12 +309,25 @@ bpf_get_prog_addr_region(const struct bpf_prog *prog,
309
309
310
310
static void bpf_get_prog_name (const struct bpf_prog * prog , char * sym )
311
311
{
312
+ const char * end = sym + KSYM_NAME_LEN ;
313
+
312
314
BUILD_BUG_ON (sizeof ("bpf_prog_" ) +
313
- sizeof (prog -> tag ) * 2 + 1 > KSYM_NAME_LEN );
315
+ sizeof (prog -> tag ) * 2 +
316
+ /* name has been null terminated.
317
+ * We should need +1 for the '_' preceding
318
+ * the name. However, the null character
319
+ * is double counted between the name and the
320
+ * sizeof("bpf_prog_") above, so we omit
321
+ * the +1 here.
322
+ */
323
+ sizeof (prog -> aux -> name ) > KSYM_NAME_LEN );
314
324
315
325
sym += snprintf (sym , KSYM_NAME_LEN , "bpf_prog_" );
316
326
sym = bin2hex (sym , prog -> tag , sizeof (prog -> tag ));
317
- * sym = 0 ;
327
+ if (prog -> aux -> name [0 ])
328
+ snprintf (sym , (size_t )(end - sym ), "_%s" , prog -> aux -> name );
329
+ else
330
+ * sym = 0 ;
318
331
}
319
332
320
333
static __always_inline unsigned long
Original file line number Diff line number Diff line change @@ -322,6 +322,8 @@ static int bpf_obj_name_cpy(char *dst, const char *src)
322
322
{
323
323
const char * end = src + BPF_OBJ_NAME_LEN ;
324
324
325
+ memset (dst , 0 , BPF_OBJ_NAME_LEN );
326
+
325
327
/* Copy all isalnum() and '_' char */
326
328
while (src < end && * src ) {
327
329
if (!isalnum (* src ) && * src != '_' )
@@ -333,9 +335,6 @@ static int bpf_obj_name_cpy(char *dst, const char *src)
333
335
if (src == end )
334
336
return - EINVAL ;
335
337
336
- /* '\0' terminates dst */
337
- * dst = 0 ;
338
-
339
338
return 0 ;
340
339
}
341
340
Original file line number Diff line number Diff line change @@ -230,7 +230,7 @@ union bpf_attr {
230
230
__u32 numa_node ; /* numa node (effective only if
231
231
* BPF_F_NUMA_NODE is set).
232
232
*/
233
- __u8 map_name [BPF_OBJ_NAME_LEN ];
233
+ char map_name [BPF_OBJ_NAME_LEN ];
234
234
};
235
235
236
236
struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
@@ -253,7 +253,7 @@ union bpf_attr {
253
253
__aligned_u64 log_buf ; /* user supplied buffer */
254
254
__u32 kern_version ; /* checked when prog_type=kprobe */
255
255
__u32 prog_flags ;
256
- __u8 prog_name [BPF_OBJ_NAME_LEN ];
256
+ char prog_name [BPF_OBJ_NAME_LEN ];
257
257
};
258
258
259
259
struct { /* anonymous struct used by BPF_OBJ_* commands */
@@ -871,7 +871,7 @@ struct bpf_prog_info {
871
871
__u32 created_by_uid ;
872
872
__u32 nr_map_ids ;
873
873
__aligned_u64 map_ids ;
874
- __u8 name [BPF_OBJ_NAME_LEN ];
874
+ char name [BPF_OBJ_NAME_LEN ];
875
875
} __attribute__((aligned (8 )));
876
876
877
877
struct bpf_map_info {
@@ -881,7 +881,7 @@ struct bpf_map_info {
881
881
__u32 value_size ;
882
882
__u32 max_entries ;
883
883
__u32 map_flags ;
884
- __u8 name [BPF_OBJ_NAME_LEN ];
884
+ char name [BPF_OBJ_NAME_LEN ];
885
885
} __attribute__((aligned (8 )));
886
886
887
887
/* User bpf_sock_ops struct to access socket values and specify request ops
You can’t perform that action at this time.
0 commit comments