Patch "bpf: Add dummy type reference to nf_conn___init to fix type deduplication" has been added to the 6.1-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    bpf: Add dummy type reference to nf_conn___init to fix type deduplication

to the 6.1-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     bpf-add-dummy-type-reference-to-nf_conn___init-to-fi.patch
and it can be found in the queue-6.1 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 230b09b33a059fcf568483346d66f2f7812fe81e
Author: Toke Høiland-Jørgensen <toke@xxxxxxxxxx>
Date:   Thu Dec 1 13:39:39 2022 +0100

    bpf: Add dummy type reference to nf_conn___init to fix type deduplication
    
    [ Upstream commit 578ce69ffda49d6c1a252490553290d1f27199f0 ]
    
    The bpf_ct_set_nat_info() kfunc is defined in the nf_nat.ko module, and
    takes as a parameter the nf_conn___init struct, which is allocated through
    the bpf_xdp_ct_alloc() helper defined in the nf_conntrack.ko module.
    However, because kernel modules can't deduplicate BTF types between each
    other, and the nf_conn___init struct is not referenced anywhere in vmlinux
    BTF, this leads to two distinct BTF IDs for the same type (one in each
    module). This confuses the verifier, as described here:
    
    https://lore.kernel.org/all/87leoh372s.fsf@xxxxxxx/
    
    As a workaround, add an explicit BTF_TYPE_EMIT for the type in
    net/filter.c, so the type definition gets included in vmlinux BTF. This
    way, both modules can refer to the same type ID (as they both build on top
    of vmlinux BTF), and the verifier is no longer confused.
    
    v2:
    
    - Use BTF_TYPE_EMIT (which is a statement so it has to be inside a function
      definition; use xdp_func_proto() for this, since this is mostly
      xdp-related).
    
    Fixes: 820dc0523e05 ("net: netfilter: move bpf_ct_set_nat_info kfunc in nf_nat_bpf.c")
    Signed-off-by: Toke Høiland-Jørgensen <toke@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20221201123939.696558-1-toke@xxxxxxxxxx
    Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/net/core/filter.c b/net/core/filter.c
index b35f642d117f..9b2e18c0d299 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -80,6 +80,7 @@
 #include <net/tls.h>
 #include <net/xdp.h>
 #include <net/mptcp.h>
+#include <net/netfilter/nf_conntrack_bpf.h>
 
 static const struct bpf_func_proto *
 bpf_sk_base_func_proto(enum bpf_func_id func_id);
@@ -7988,6 +7989,19 @@ xdp_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
 	default:
 		return bpf_sk_base_func_proto(func_id);
 	}
+
+#if IS_MODULE(CONFIG_NF_CONNTRACK) && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES)
+	/* The nf_conn___init type is used in the NF_CONNTRACK kfuncs. The
+	 * kfuncs are defined in two different modules, and we want to be able
+	 * to use them interchangably with the same BTF type ID. Because modules
+	 * can't de-duplicate BTF IDs between each other, we need the type to be
+	 * referenced in the vmlinux BTF or the verifier will get confused about
+	 * the different types. So we add this dummy type reference which will
+	 * be included in vmlinux BTF, allowing both modules to refer to the
+	 * same type ID.
+	 */
+	BTF_TYPE_EMIT(struct nf_conn___init);
+#endif
 }
 
 const struct bpf_func_proto bpf_sock_map_update_proto __weak;



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux