Skip to content

Commit 4c8530d

Browse files
0x7f454c46kuba-moo
authored andcommitted
net/tcp: Only produce AO/MD5 logs if there are any keys
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> Reviewed-by: Eric Dumazet <edumazet@google.com> Fixes: 2717b5a ("net/tcp: Add tcp_hash_fail() ratelimited logs") Link: https://lore.kernel.org/r/20240104-tcp_hash_fail-logs-v1-1-ff3e1f6f9e72@arista.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 2e957f9 commit 4c8530d

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

include/net/tcp.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,8 +1788,6 @@ struct tcp_md5sig_key *tcp_v4_md5_lookup(const struct sock *sk,
17881788
const struct sock *addr_sk);
17891789

17901790
#ifdef CONFIG_TCP_MD5SIG
1791-
#include <linux/jump_label.h>
1792-
extern struct static_key_false_deferred tcp_md5_needed;
17931791
struct tcp_md5sig_key *__tcp_md5_do_lookup(const struct sock *sk, int l3index,
17941792
const union tcp_md5_addr *addr,
17951793
int family, bool any_l3index);

include/net/tcp_ao.h

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,35 @@ struct tcp_ao_info {
127127
struct rcu_head rcu;
128128
};
129129

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+
146+
static inline bool tcp_hash_should_produce_warnings(void)
147+
{
148+
return static_branch_tcp_md5() || static_branch_tcp_ao();
149+
}
150+
130151
#define tcp_hash_fail(msg, family, skb, fmt, ...) \
131152
do { \
132153
const struct tcphdr *th = tcp_hdr(skb); \
133154
char hdr_flags[6]; \
134155
char *f = hdr_flags; \
135156
\
157+
if (!tcp_hash_should_produce_warnings()) \
158+
break; \
136159
if (th->fin) \
137160
*f++ = 'F'; \
138161
if (th->syn) \
@@ -159,9 +182,6 @@ do { \
159182

160183
#ifdef CONFIG_TCP_AO
161184
/* TCP-AO structures and functions */
162-
#include <linux/jump_label.h>
163-
extern struct static_key_false_deferred tcp_ao_needed;
164-
165185
struct tcp4_ao_context {
166186
__be32 saddr;
167187
__be32 daddr;

0 commit comments

Comments
 (0)