All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net/tcp: Only produce AO/MD5 logs if there are any keys
@ 2024-01-04 13:42 Dmitry Safonov
  2024-01-04 13:57 ` Dmitry Safonov
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Dmitry Safonov @ 2024-01-04 13:42 UTC (permalink / raw)
  To: Eric Dumazet, David S. Miller, Jakub Kicinski, Paolo Abeni
  Cc: Dmitry Safonov, Christian Kujau, Salam Noureddine, Dmitry Safonov,
	netdev, linux-kernel

User won't care about inproper hash options in the TCP header if they
don't use neither TCP-AO nor TCP-MD5. Yet, those logs can add up in
syslog, while not being a real concern to the host admin:
> kernel: TCP: TCP segment has incorrect auth options set for XX.20.239.12.54681->XX.XX.90.103.80 [S]

Keep silent and avoid logging when there aren't any keys in the system.

Side-note: I also defined static_branch_tcp_*() helpers to avoid more
ifdeffery, going to remove more ifdeffery further with their help.

Reported-by: Christian Kujau <lists@nerdbynature.de>
Closes: https://lore.kernel.org/all/f6b59324-1417-566f-a976-ff2402718a8d@nerdbynature.de/
Signed-off-by: Dmitry Safonov <dima@arista.com>
---
 include/net/tcp.h    |  2 --
 include/net/tcp_ao.h | 26 +++++++++++++++++++++++---
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/include/net/tcp.h b/include/net/tcp.h
index 144ba48bb07b..87f0e6c2e1f2 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -1788,8 +1788,6 @@ struct tcp_md5sig_key *tcp_v4_md5_lookup(const struct sock *sk,
 					 const struct sock *addr_sk);
 
 #ifdef CONFIG_TCP_MD5SIG
-#include <linux/jump_label.h>
-extern struct static_key_false_deferred tcp_md5_needed;
 struct tcp_md5sig_key *__tcp_md5_do_lookup(const struct sock *sk, int l3index,
 					   const union tcp_md5_addr *addr,
 					   int family, bool any_l3index);
diff --git a/include/net/tcp_ao.h b/include/net/tcp_ao.h
index 647781080613..b04afced4cc9 100644
--- a/include/net/tcp_ao.h
+++ b/include/net/tcp_ao.h
@@ -127,12 +127,35 @@ struct tcp_ao_info {
 	struct rcu_head		rcu;
 };
 
+#ifdef CONFIG_TCP_MD5SIG
+#include <linux/jump_label.h>
+extern struct static_key_false_deferred tcp_md5_needed;
+#define static_branch_tcp_md5()	static_branch_unlikely(&tcp_md5_needed.key)
+#else
+#define static_branch_tcp_md5()	false
+#endif
+#ifdef CONFIG_TCP_AO
+/* TCP-AO structures and functions */
+#include <linux/jump_label.h>
+extern struct static_key_false_deferred tcp_ao_needed;
+#define static_branch_tcp_ao()	static_branch_unlikely(&tcp_ao_needed.key)
+#else
+#define static_branch_tcp_ao()	false
+#endif
+
+static inline bool tcp_hash_should_produce_warnings(void)
+{
+	return static_branch_tcp_md5() || static_branch_tcp_ao();
+}
+
 #define tcp_hash_fail(msg, family, skb, fmt, ...)			\
 do {									\
 	const struct tcphdr *th = tcp_hdr(skb);				\
 	char hdr_flags[6];						\
 	char *f = hdr_flags;						\
 									\
+	if (!tcp_hash_should_produce_warnings())			\
+		break;							\
 	if (th->fin)							\
 		*f++ = 'F';						\
 	if (th->syn)							\
@@ -159,9 +182,6 @@ do {									\
 
 #ifdef CONFIG_TCP_AO
 /* TCP-AO structures and functions */
-#include <linux/jump_label.h>
-extern struct static_key_false_deferred tcp_ao_needed;
-
 struct tcp4_ao_context {
 	__be32		saddr;
 	__be32		daddr;

---
base-commit: ac865f00af293d081356bec56eea90815094a60e
change-id: 20240104-tcp_hash_fail-logs-daa1a4dde694

Best regards,
-- 
Dmitry Safonov <dima@arista.com>


^ permalink raw reply related	[flat|nested] 10+ messages in thread
* Re: [PATCH] net/tcp: Only produce AO/MD5 logs if there are any keys
@ 2024-01-06 12:11 kernel test robot
  2024-01-07 11:52 ` Liu, Yujie
  0 siblings, 1 reply; 10+ messages in thread
From: kernel test robot @ 2024-01-06 12:11 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp

:::::: 
:::::: Manual check reason: "low confidence bisect report"
:::::: 

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20240104-tcp_hash_fail-logs-v1-1-ff3e1f6f9e72@arista.com>
References: <20240104-tcp_hash_fail-logs-v1-1-ff3e1f6f9e72@arista.com>
TO: Dmitry Safonov <dima@arista.com>

Hi Dmitry,

kernel test robot noticed the following build warnings:

[auto build test WARNING on ac865f00af293d081356bec56eea90815094a60e]

url:    https://github.com/intel-lab-lkp/linux/commits/Dmitry-Safonov/net-tcp-Only-produce-AO-MD5-logs-if-there-are-any-keys/20240104-214510
base:   ac865f00af293d081356bec56eea90815094a60e
patch link:    https://lore.kernel.org/r/20240104-tcp_hash_fail-logs-v1-1-ff3e1f6f9e72%40arista.com
patch subject: [PATCH] net/tcp: Only produce AO/MD5 logs if there are any keys
:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/r/202401061952.k6UqFm0j-lkp@intel.com/

includecheck warnings: (new ones prefixed by >>)
>> include/net/tcp_ao.h: linux/jump_label.h is included more than once.

vim +131 include/net/tcp_ao.h

   129	
   130	#ifdef CONFIG_TCP_MD5SIG
 > 131	#include <linux/jump_label.h>
   132	extern struct static_key_false_deferred tcp_md5_needed;
   133	#define static_branch_tcp_md5()	static_branch_unlikely(&tcp_md5_needed.key)
   134	#else
   135	#define static_branch_tcp_md5()	false
   136	#endif
   137	#ifdef CONFIG_TCP_AO
   138	/* TCP-AO structures and functions */
 > 139	#include <linux/jump_label.h>
   140	extern struct static_key_false_deferred tcp_ao_needed;
   141	#define static_branch_tcp_ao()	static_branch_unlikely(&tcp_ao_needed.key)
   142	#else
   143	#define static_branch_tcp_ao()	false
   144	#endif
   145	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-01-07 11:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-04 13:42 [PATCH] net/tcp: Only produce AO/MD5 logs if there are any keys Dmitry Safonov
2024-01-04 13:57 ` Dmitry Safonov
2024-01-04 15:57 ` Jakub Kicinski
2024-01-04 16:42   ` Dmitry Safonov
2024-01-04 16:58     ` Jakub Kicinski
2024-01-04 16:59       ` Eric Dumazet
2024-01-04 17:30         ` Dmitry Safonov
2024-01-04 17:20 ` patchwork-bot+netdevbpf
  -- strict thread matches above, loose matches on Subject: below --
2024-01-06 12:11 kernel test robot
2024-01-07 11:52 ` Liu, Yujie

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.