]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
5.18-stable patches
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 23 Jun 2022 16:14:31 +0000 (18:14 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 23 Jun 2022 16:14:31 +0000 (18:14 +0200)
added patches:
bpf-fix-calling-global-functions-from-bpf_prog_type_ext-programs.patch
dt-bindings-nvmem-sfp-add-clock-properties.patch
selftests-bpf-add-selftest-for-calling-global-functions-from-freplace.patch

queue-5.18/bpf-fix-calling-global-functions-from-bpf_prog_type_ext-programs.patch [new file with mode: 0644]
queue-5.18/dt-bindings-nvmem-sfp-add-clock-properties.patch [new file with mode: 0644]
queue-5.18/selftests-bpf-add-selftest-for-calling-global-functions-from-freplace.patch [new file with mode: 0644]
queue-5.18/series

diff --git a/queue-5.18/bpf-fix-calling-global-functions-from-bpf_prog_type_ext-programs.patch b/queue-5.18/bpf-fix-calling-global-functions-from-bpf_prog_type_ext-programs.patch
new file mode 100644 (file)
index 0000000..44a2f0e
--- /dev/null
@@ -0,0 +1,65 @@
+From f858c2b2ca04fc7ead291821a793638ae120c11d Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= <toke@redhat.com>
+Date: Mon, 6 Jun 2022 09:52:51 +0200
+Subject: bpf: Fix calling global functions from BPF_PROG_TYPE_EXT programs
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+From: Toke Høiland-Jørgensen <toke@redhat.com>
+
+commit f858c2b2ca04fc7ead291821a793638ae120c11d upstream.
+
+The verifier allows programs to call global functions as long as their
+argument types match, using BTF to check the function arguments. One of the
+allowed argument types to such global functions is PTR_TO_CTX; however the
+check for this fails on BPF_PROG_TYPE_EXT functions because the verifier
+uses the wrong type to fetch the vmlinux BTF ID for the program context
+type. This failure is seen when an XDP program is loaded using
+libxdp (which loads it as BPF_PROG_TYPE_EXT and attaches it to a global XDP
+type program).
+
+Fix the issue by passing in the target program type instead of the
+BPF_PROG_TYPE_EXT type to bpf_prog_get_ctx() when checking function
+argument compatibility.
+
+The first Fixes tag refers to the latest commit that touched the code in
+question, while the second one points to the code that first introduced
+the global function call verification.
+
+v2:
+- Use resolve_prog_type()
+
+Fixes: 3363bd0cfbb8 ("bpf: Extend kfunc with PTR_TO_CTX, PTR_TO_MEM argument support")
+Fixes: 51c39bb1d5d1 ("bpf: Introduce function-by-function verification")
+Reported-by: Simon Sundberg <simon.sundberg@kau.se>
+Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
+Link: https://lore.kernel.org/r/20220606075253.28422-1-toke@redhat.com
+Signed-off-by: Alexei Starovoitov <ast@kernel.org>
+[ backport: resolve conflict due to kptr series missing ]
+Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ kernel/bpf/btf.c |    4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+--- a/kernel/bpf/btf.c
++++ b/kernel/bpf/btf.c
+@@ -5769,6 +5769,7 @@ static int btf_check_func_arg_match(stru
+                                   struct bpf_reg_state *regs,
+                                   bool ptr_to_mem_ok)
+ {
++      enum bpf_prog_type prog_type = resolve_prog_type(env->prog);
+       struct bpf_verifier_log *log = &env->log;
+       u32 i, nargs, ref_id, ref_obj_id = 0;
+       bool is_kfunc = btf_is_kernel(btf);
+@@ -5834,8 +5835,7 @@ static int btf_check_func_arg_match(stru
+               if (ret < 0)
+                       return ret;
+-              if (btf_get_prog_ctx_type(log, btf, t,
+-                                        env->prog->type, i)) {
++              if (btf_get_prog_ctx_type(log, btf, t, prog_type, i)) {
+                       /* If function expects ctx type in BTF check that caller
+                        * is passing PTR_TO_CTX.
+                        */
diff --git a/queue-5.18/dt-bindings-nvmem-sfp-add-clock-properties.patch b/queue-5.18/dt-bindings-nvmem-sfp-add-clock-properties.patch
new file mode 100644 (file)
index 0000000..2ad5e16
--- /dev/null
@@ -0,0 +1,59 @@
+From 8cb0cd68bef75af5ac8ef93f3314d4f8dc8767a3 Mon Sep 17 00:00:00 2001
+From: Sean Anderson <sean.anderson@seco.com>
+Date: Fri, 29 Apr 2022 17:26:57 +0100
+Subject: dt-bindings: nvmem: sfp: Add clock properties
+
+From: Sean Anderson <sean.anderson@seco.com>
+
+commit 8cb0cd68bef75af5ac8ef93f3314d4f8dc8767a3 upstream.
+
+To program fuses, it is necessary to set the fuse programming time. This
+is determined based on the value of the platform clock. Add a clock
+property.
+
+Because this property is necessary for programming, it is made
+mandatory. Since these bindings have not yet been present in a stable
+release (though they are on track for 5.18), it is not an ABI break to
+change them in this manner.
+
+Signed-off-by: Sean Anderson <sean.anderson@seco.com>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20220429162701.2222-13-srinivas.kandagatla@linaro.org
+Cc: Michael Walle <michael@walle.cc>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ Documentation/devicetree/bindings/nvmem/fsl,layerscape-sfp.yaml |   14 ++++++++++
+ 1 file changed, 14 insertions(+)
+
+--- a/Documentation/devicetree/bindings/nvmem/fsl,layerscape-sfp.yaml
++++ b/Documentation/devicetree/bindings/nvmem/fsl,layerscape-sfp.yaml
+@@ -24,15 +24,29 @@ properties:
+   reg:
+     maxItems: 1
++  clocks:
++    maxItems: 1
++    description:
++      The SFP clock. Typically, this is the platform clock divided by 4.
++
++  clock-names:
++    const: sfp
++
+ required:
+   - compatible
+   - reg
++  - clock-names
++  - clocks
+ unevaluatedProperties: false
+ examples:
+   - |
++    #include <dt-bindings/clock/fsl,qoriq-clockgen.h>
+     efuse@1e80000 {
+         compatible = "fsl,ls1028a-sfp";
+         reg = <0x1e80000 0x8000>;
++        clocks = <&clockgen QORIQ_CLK_PLATFORM_PLL
++                            QORIQ_CLK_PLL_DIV(4)>;
++        clock-names = "sfp";
+     };
diff --git a/queue-5.18/selftests-bpf-add-selftest-for-calling-global-functions-from-freplace.patch b/queue-5.18/selftests-bpf-add-selftest-for-calling-global-functions-from-freplace.patch
new file mode 100644 (file)
index 0000000..c1bb6fb
--- /dev/null
@@ -0,0 +1,81 @@
+From 2cf7b7ffdae519b284f1406012b52e2282fa36bf Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= <toke@redhat.com>
+Date: Mon, 6 Jun 2022 09:52:52 +0200
+Subject: selftests/bpf: Add selftest for calling global functions from freplace
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+From: Toke Høiland-Jørgensen <toke@redhat.com>
+
+commit 2cf7b7ffdae519b284f1406012b52e2282fa36bf upstream.
+
+Add a selftest that calls a global function with a context object parameter
+from an freplace function to check that the program context type is
+correctly converted to the freplace target when fetching the context type
+from the kernel BTF.
+
+v2:
+- Trim includes
+- Get rid of global function
+- Use __noinline
+
+Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
+Link: https://lore.kernel.org/r/20220606075253.28422-2-toke@redhat.com
+Signed-off-by: Alexei Starovoitov <ast@kernel.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c   |   14 +++++++++++
+ tools/testing/selftests/bpf/progs/freplace_global_func.c |   18 +++++++++++++++
+ 2 files changed, 32 insertions(+)
+ create mode 100644 tools/testing/selftests/bpf/progs/freplace_global_func.c
+
+--- a/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
++++ b/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
+@@ -395,6 +395,18 @@ static void test_func_map_prog_compatibi
+                                    "./test_attach_probe.o");
+ }
++static void test_func_replace_global_func(void)
++{
++      const char *prog_name[] = {
++              "freplace/test_pkt_access",
++      };
++
++      test_fexit_bpf2bpf_common("./freplace_global_func.o",
++                                "./test_pkt_access.o",
++                                ARRAY_SIZE(prog_name),
++                                prog_name, false, NULL);
++}
++
+ /* NOTE: affect other tests, must run in serial mode */
+ void serial_test_fexit_bpf2bpf(void)
+ {
+@@ -416,4 +428,6 @@ void serial_test_fexit_bpf2bpf(void)
+               test_func_replace_multi();
+       if (test__start_subtest("fmod_ret_freplace"))
+               test_fmod_ret_freplace();
++      if (test__start_subtest("func_replace_global_func"))
++              test_func_replace_global_func();
+ }
+--- /dev/null
++++ b/tools/testing/selftests/bpf/progs/freplace_global_func.c
+@@ -0,0 +1,18 @@
++// SPDX-License-Identifier: GPL-2.0
++#include <linux/bpf.h>
++#include <bpf/bpf_helpers.h>
++
++__noinline
++int test_ctx_global_func(struct __sk_buff *skb)
++{
++      volatile int retval = 1;
++      return retval;
++}
++
++SEC("freplace/test_pkt_access")
++int new_test_pkt_access(struct __sk_buff *skb)
++{
++      return test_ctx_global_func(skb);
++}
++
++char _license[] SEC("license") = "GPL";
index 157d89d4ef4c0b62509fcbda35d3a572a9ee1103..da6a1a9ed11b3d2a8a9852f0f7cf751cb9c28475 100644 (file)
@@ -6,3 +6,6 @@ net-wwan-iosm-remove-pointless-null-check.patch
 x86-boot-wrap-literal-addresses-in-absolute_pointer.patch
 fsnotify-introduce-mark-type-iterator.patch
 fsnotify-consistent-behavior-for-parent-not-watching-children.patch
+bpf-fix-calling-global-functions-from-bpf_prog_type_ext-programs.patch
+selftests-bpf-add-selftest-for-calling-global-functions-from-freplace.patch
+dt-bindings-nvmem-sfp-add-clock-properties.patch