|
| 1 | +bpf: Refuse unused attributes in bpf_prog_{attach,detach} |
| 2 | + |
| 3 | +jira LE-1907 |
| 4 | +Rebuild_History Non-Buildable kernel-5.14.0-427.18.1.el9_4 |
| 5 | +commit-author Lorenz Bauer <lmb@isovalent.com> |
| 6 | +commit ba62d61128bda71fd02622f320ac59d861fc4baa |
| 7 | +Empty-Commit: Cherry-Pick Conflicts during history rebuild. |
| 8 | +Will be included in final tarball splat. Ref for failed cherry-pick at: |
| 9 | +ciq/ciq_backports/kernel-5.14.0-427.18.1.el9_4/ba62d611.failed |
| 10 | + |
| 11 | +The recently added tcx attachment extended the BPF UAPI for attaching and |
| 12 | +detaching by a couple of fields. Those fields are currently only supported |
| 13 | +for tcx, other types like cgroups and flow dissector silently ignore the |
| 14 | +new fields except for the new flags. |
| 15 | + |
| 16 | +This is problematic once we extend bpf_mprog to older attachment types, since |
| 17 | +it's hard to figure out whether the syscall really was successful if the |
| 18 | +kernel silently ignores non-zero values. |
| 19 | + |
| 20 | +Explicitly reject non-zero fields relevant to bpf_mprog for attachment types |
| 21 | +which don't use the latter yet. |
| 22 | + |
| 23 | +Fixes: e420bed02507 ("bpf: Add fd-based tcx multi-prog infra with link support") |
| 24 | + Signed-off-by: Lorenz Bauer <lmb@isovalent.com> |
| 25 | +Co-developed-by: Daniel Borkmann <daniel@iogearbox.net> |
| 26 | + Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> |
| 27 | +Link: https://lore.kernel.org/r/20231006220655.1653-3-daniel@iogearbox.net |
| 28 | + Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org> |
| 29 | +(cherry picked from commit ba62d61128bda71fd02622f320ac59d861fc4baa) |
| 30 | + Signed-off-by: Jonathan Maple <jmaple@ciq.com> |
| 31 | + |
| 32 | +# Conflicts: |
| 33 | +# kernel/bpf/syscall.c |
| 34 | +diff --cc kernel/bpf/syscall.c |
| 35 | +index 62481af02f05,d77b2f8b9364..000000000000 |
| 36 | +--- a/kernel/bpf/syscall.c |
| 37 | ++++ b/kernel/bpf/syscall.c |
| 38 | +@@@ -3811,6 -3804,16 +3811,19 @@@ static int bpf_prog_attach(const union |
| 39 | + ptype = attach_type_to_prog_type(attr->attach_type); |
| 40 | + if (ptype == BPF_PROG_TYPE_UNSPEC) |
| 41 | + return -EINVAL; |
| 42 | +++<<<<<<< HEAD |
| 43 | +++======= |
| 44 | ++ if (bpf_mprog_supported(ptype)) { |
| 45 | ++ if (attr->attach_flags & ~BPF_F_ATTACH_MASK_MPROG) |
| 46 | ++ return -EINVAL; |
| 47 | ++ } else { |
| 48 | ++ if (attr->attach_flags & ~BPF_F_ATTACH_MASK_BASE) |
| 49 | ++ return -EINVAL; |
| 50 | ++ if (attr->relative_fd || |
| 51 | ++ attr->expected_revision) |
| 52 | ++ return -EINVAL; |
| 53 | ++ } |
| 54 | +++>>>>>>> ba62d61128bd (bpf: Refuse unused attributes in bpf_prog_{attach,detach}) |
| 55 | + |
| 56 | + prog = bpf_prog_get_type(attr->attach_bpf_fd, ptype); |
| 57 | + if (IS_ERR(prog)) |
| 58 | +@@@ -3865,6 -3873,21 +3878,24 @@@ static int bpf_prog_detach(const union |
| 59 | + return -EINVAL; |
| 60 | + |
| 61 | + ptype = attach_type_to_prog_type(attr->attach_type); |
| 62 | +++<<<<<<< HEAD |
| 63 | +++======= |
| 64 | ++ if (bpf_mprog_supported(ptype)) { |
| 65 | ++ if (ptype == BPF_PROG_TYPE_UNSPEC) |
| 66 | ++ return -EINVAL; |
| 67 | ++ if (attr->attach_flags & ~BPF_F_ATTACH_MASK_MPROG) |
| 68 | ++ return -EINVAL; |
| 69 | ++ if (attr->attach_bpf_fd) { |
| 70 | ++ prog = bpf_prog_get_type(attr->attach_bpf_fd, ptype); |
| 71 | ++ if (IS_ERR(prog)) |
| 72 | ++ return PTR_ERR(prog); |
| 73 | ++ } |
| 74 | ++ } else if (attr->attach_flags || |
| 75 | ++ attr->relative_fd || |
| 76 | ++ attr->expected_revision) { |
| 77 | ++ return -EINVAL; |
| 78 | ++ } |
| 79 | +++>>>>>>> ba62d61128bd (bpf: Refuse unused attributes in bpf_prog_{attach,detach}) |
| 80 | + |
| 81 | + switch (ptype) { |
| 82 | + case BPF_PROG_TYPE_SK_MSG: |
| 83 | +* Unmerged path kernel/bpf/syscall.c |
0 commit comments