Commit 0ed5f79
Alexei Starovoitov
Merge branch 'bpf-allow-void-cast-using-bpf_rdonly_cast'
Eduard Zingerman says:
====================
bpf: allow void* cast using bpf_rdonly_cast()
Currently, pointers returned by `bpf_rdonly_cast()` have a type of
"pointer to btf id", and only casts to structure types are allowed.
Access to memory pointed to by these pointers is done through
`BPF_PROBE_{MEM,MEMSX}` instructions and does not produce errors on
invalid memory access.
This patch set extends `bpf_rdonly_cast()` to allow casts to an
equivalent of 'void *', effectively replacing
`bpf_probe_read_kernel()` calls in situations where access to
individual bytes or integers is necessary.
The mechanism was suggested and explored by Andrii Nakryiko in [1].
To help with detecting support for this feature, an
`enum bpf_features` is added with intended usage as follows:
if (bpf_core_enum_value_exists(enum bpf_features,
BPF_FEAT_RDONLY_CAST_TO_VOID))
...
[1] https://github.com/anakryiko/linux/tree/bpf-mem-cast
Changelog:
v2: https://lore.kernel.org/bpf/[email protected]/
v2 -> v3:
- dropped direct numbering for __MAX_BPF_FEAT.
v1: https://lore.kernel.org/bpf/[email protected]/
v1 -> v2:
- renamed BPF_FEAT_TOTAL to __MAX_BPF_FEAT and moved patch introducing
bpf_features enum to the start of the series (Alexei);
- dropped patch #3 allowing optout from CAP_SYS_ADMIN drop in
prog_tests/verifier.c, use a separate runner in prog_tests/*
instead.
====================
Acked-by: Andrii Nakryiko <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Alexei Starovoitov <[email protected]>File tree
3 files changed
+212
-12
lines changed- kernel/bpf
- tools/testing/selftests/bpf
- prog_tests
- progs
3 files changed
+212
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
47 | 52 | | |
48 | 53 | | |
49 | 54 | | |
| |||
7535 | 7540 | | |
7536 | 7541 | | |
7537 | 7542 | | |
| 7543 | + | |
7538 | 7544 | | |
7539 | 7545 | | |
7540 | 7546 | | |
| |||
7554 | 7560 | | |
7555 | 7561 | | |
7556 | 7562 | | |
7557 | | - | |
7558 | | - | |
| 7563 | + | |
| 7564 | + | |
| 7565 | + | |
| 7566 | + | |
| 7567 | + | |
| 7568 | + | |
| 7569 | + | |
7559 | 7570 | | |
7560 | 7571 | | |
7561 | 7572 | | |
| |||
13602 | 13613 | | |
13603 | 13614 | | |
13604 | 13615 | | |
13605 | | - | |
| 13616 | + | |
| 13617 | + | |
| 13618 | + | |
| 13619 | + | |
| 13620 | + | |
| 13621 | + | |
| 13622 | + | |
| 13623 | + | |
| 13624 | + | |
| 13625 | + | |
| 13626 | + | |
| 13627 | + | |
| 13628 | + | |
| 13629 | + | |
13606 | 13630 | | |
13607 | | - | |
| 13631 | + | |
13608 | 13632 | | |
13609 | 13633 | | |
13610 | | - | |
13611 | | - | |
13612 | | - | |
13613 | | - | |
13614 | | - | |
13615 | 13634 | | |
13616 | 13635 | | |
13617 | 13636 | | |
| |||
14410 | 14429 | | |
14411 | 14430 | | |
14412 | 14431 | | |
| 14432 | + | |
| 14433 | + | |
| 14434 | + | |
| 14435 | + | |
| 14436 | + | |
| 14437 | + | |
| 14438 | + | |
14413 | 14439 | | |
14414 | 14440 | | |
14415 | 14441 | | |
| |||
19618 | 19644 | | |
19619 | 19645 | | |
19620 | 19646 | | |
| 19647 | + | |
| 19648 | + | |
| 19649 | + | |
| 19650 | + | |
| 19651 | + | |
| 19652 | + | |
| 19653 | + | |
| 19654 | + | |
| 19655 | + | |
| 19656 | + | |
| 19657 | + | |
| 19658 | + | |
| 19659 | + | |
| 19660 | + | |
| 19661 | + | |
| 19662 | + | |
19621 | 19663 | | |
19622 | 19664 | | |
19623 | 19665 | | |
19624 | 19666 | | |
| 19667 | + | |
19625 | 19668 | | |
19626 | 19669 | | |
19627 | 19670 | | |
| |||
19638 | 19681 | | |
19639 | 19682 | | |
19640 | 19683 | | |
19641 | | - | |
19642 | | - | |
| 19684 | + | |
| 19685 | + | |
19643 | 19686 | | |
19644 | 19687 | | |
19645 | 19688 | | |
19646 | 19689 | | |
19647 | 19690 | | |
| 19691 | + | |
19648 | 19692 | | |
19649 | | - | |
| 19693 | + | |
| 19694 | + | |
| 19695 | + | |
| 19696 | + | |
| 19697 | + | |
| 19698 | + | |
| 19699 | + | |
| 19700 | + | |
| 19701 | + | |
19650 | 19702 | | |
19651 | 19703 | | |
19652 | 19704 | | |
| |||
21254 | 21306 | | |
21255 | 21307 | | |
21256 | 21308 | | |
| 21309 | + | |
21257 | 21310 | | |
21258 | 21311 | | |
21259 | 21312 | | |
| |||
24439 | 24492 | | |
24440 | 24493 | | |
24441 | 24494 | | |
| 24495 | + | |
| 24496 | + | |
24442 | 24497 | | |
24443 | 24498 | | |
24444 | 24499 | | |
| |||
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
Lines changed: 136 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
0 commit comments