lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:   Wed, 30 Sep 2020 18:02:24 -0700
From:   Yonghong Song <yhs@...com>
To:     <bpf@...r.kernel.org>, <netdev@...r.kernel.org>
CC:     Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>, <kernel-team@...com>,
        Michal Kubecek <mkubecek@...e.cz>
Subject: [PATCH bpf v2] bpf: fix "unresolved symbol" build error with resolve_btfids

Michal reported a build failure likes below:
   BTFIDS  vmlinux
   FAILED unresolved symbol tcp_timewait_sock
   make[1]: *** [/.../linux-5.9-rc7/Makefile:1176: vmlinux] Error 255

This error can be triggered when config has CONFIG_NET enabled
but CONFIG_INET disabled. In this case, there is no user of
structs inet_timewait_sock and tcp_timewait_sock and hence vmlinux BTF
types are not generated for these two structures.

To fix the problem, for two timewait structures, if CONFIG_INET=n,
use BTF_ID_UNUSED instead of BTF_ID to skip btf id generation
in resolve_btfids.

Fixes: fce557bcef11 ("bpf: Make btf_sock_ids global")
Reported-by: Michal Kubecek <mkubecek@...e.cz>
Signed-off-by: Yonghong Song <yhs@...com>
---
 include/linux/btf_ids.h | 20 +++++++++++++++++---
 net/core/filter.c       |  1 +
 2 files changed, 18 insertions(+), 3 deletions(-)

Changelog:
  v1 -> v2:
    . For unsupported socket times, using BTF_ID_UNUSED to
      keep the id as 0. (Martin)

diff --git a/include/linux/btf_ids.h b/include/linux/btf_ids.h
index 4867d549e3c1..9c49bf89a9a7 100644
--- a/include/linux/btf_ids.h
+++ b/include/linux/btf_ids.h
@@ -102,23 +102,37 @@ asm(							\
  * skc_to_*_sock() helpers. All these sockets should have
  * sock_common as the first argument in its memory layout.
  */
-#define BTF_SOCK_TYPE_xxx \
+
+#define __BTF_SOCK_TYPE_xxx \
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock)			\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock)	\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock)	\
-	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock)	\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock)			\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock)				\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common)		\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock)			\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock)		\
-	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock)		\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock)			\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock)			\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock)
 
+#ifdef CONFIG_INET
+#define __BTF_SOCK_TW_TYPE_xxx						\
+	BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock)	\
+	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock)
+#else
+#define __BTF_SOCK_TW_TYPE_xxx						\
+	BTF_SOCK_TYPE_UNUSED(BTF_SOCK_TYPE_INET_TW)			\
+	BTF_SOCK_TYPE_UNUSED(BTF_SOCK_TYPE_TCP_TW)
+#endif
+
+#define BTF_SOCK_TYPE_xxx						\
+	__BTF_SOCK_TYPE_xxx						\
+	__BTF_SOCK_TW_TYPE_xxx
+
 enum {
 #define BTF_SOCK_TYPE(name, str) name,
+#define BTF_SOCK_TYPE_UNUSED(name) name,
 BTF_SOCK_TYPE_xxx
 #undef BTF_SOCK_TYPE
 MAX_BTF_SOCK_TYPE,
diff --git a/net/core/filter.c b/net/core/filter.c
index 21eaf3b182f2..396fe928e202 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -9500,6 +9500,7 @@ void bpf_prog_change_xdp(struct bpf_prog *prev_prog, struct bpf_prog *prog)
 #ifdef CONFIG_DEBUG_INFO_BTF
 BTF_ID_LIST_GLOBAL(btf_sock_ids)
 #define BTF_SOCK_TYPE(name, type) BTF_ID(struct, type)
+#define BTF_SOCK_TYPE_UNUSED(name) BTF_ID_UNUSED
 BTF_SOCK_TYPE_xxx
 #undef BTF_SOCK_TYPE
 #else
-- 
2.24.1

Powered by blists - more mailing lists