Skip to content

Commit eff8313

Browse files
committed
Merge branch 'tcp-ao'
Dmitry Safonov says: ==================== net/tcp: Add TCP-AO support This is version 16 of TCP-AO support. It addresses the build warning in the middle of patch set, reported by kernel test robot. There's one Sparse warning introduced by tcp_sigpool_start(): __cond_acquires() seems to currently being broken. I've described the reasoning for it on v9 cover letter. Also, checkpatch.pl warnings were addressed, but yet I've left the ones that are more personal preferences (i.e. 80 columns limit). Please, ping me if you have a strong feeling about one of them. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents cc54d2e + 7fe0e38 commit eff8313

File tree

24 files changed

+5175
-436
lines changed

24 files changed

+5175
-436
lines changed

Documentation/networking/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ Contents:
106106
sysfs-tagging
107107
tc-actions-env-rules
108108
tc-queue-filters
109+
tcp_ao
109110
tcp-thin
110111
team
111112
timestamping

Documentation/networking/tcp_ao.rst

Lines changed: 444 additions & 0 deletions
Large diffs are not rendered by default.

include/linux/sockptr.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,29 @@ static inline int copy_from_sockptr(void *dst, sockptr_t src, size_t size)
5555
return copy_from_sockptr_offset(dst, src, 0, size);
5656
}
5757

58+
static inline int copy_struct_from_sockptr(void *dst, size_t ksize,
59+
sockptr_t src, size_t usize)
60+
{
61+
size_t size = min(ksize, usize);
62+
size_t rest = max(ksize, usize) - size;
63+
64+
if (!sockptr_is_kernel(src))
65+
return copy_struct_from_user(dst, ksize, src.user, size);
66+
67+
if (usize < ksize) {
68+
memset(dst + size, 0, rest);
69+
} else if (usize > ksize) {
70+
char *p = src.kernel;
71+
72+
while (rest--) {
73+
if (*p++)
74+
return -E2BIG;
75+
}
76+
}
77+
memcpy(dst, src.kernel, size);
78+
return 0;
79+
}
80+
5881
static inline int copy_to_sockptr_offset(sockptr_t dst, size_t offset,
5982
const void *src, size_t size)
6083
{

include/linux/tcp.h

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,31 @@ struct tcp_request_sock {
166166
* after data-in-SYN.
167167
*/
168168
u8 syn_tos;
169+
#ifdef CONFIG_TCP_AO
170+
u8 ao_keyid;
171+
u8 ao_rcv_next;
172+
u8 maclen;
173+
#endif
169174
};
170175

171176
static inline struct tcp_request_sock *tcp_rsk(const struct request_sock *req)
172177
{
173178
return (struct tcp_request_sock *)req;
174179
}
175180

181+
static inline bool tcp_rsk_used_ao(const struct request_sock *req)
182+
{
183+
/* The real length of MAC is saved in the request socket,
184+
* signing anything with zero-length makes no sense, so here is
185+
* a little hack..
186+
*/
187+
#ifndef CONFIG_TCP_AO
188+
return false;
189+
#else
190+
return tcp_rsk(req)->maclen != 0;
191+
#endif
192+
}
193+
176194
#define TCP_RMEM_TO_WIN_SCALE 8
177195

178196
struct tcp_sock {
@@ -447,13 +465,18 @@ struct tcp_sock {
447465
bool syn_smc; /* SYN includes SMC */
448466
#endif
449467

450-
#ifdef CONFIG_TCP_MD5SIG
451-
/* TCP AF-Specific parts; only used by MD5 Signature support so far */
468+
#if defined(CONFIG_TCP_MD5SIG) || defined(CONFIG_TCP_AO)
469+
/* TCP AF-Specific parts; only used by TCP-AO/MD5 Signature support so far */
452470
const struct tcp_sock_af_ops *af_specific;
453471

472+
#ifdef CONFIG_TCP_MD5SIG
454473
/* TCP MD5 Signature Option information */
455474
struct tcp_md5sig_info __rcu *md5sig_info;
456475
#endif
476+
#ifdef CONFIG_TCP_AO
477+
struct tcp_ao_info __rcu *ao_info;
478+
#endif
479+
#endif
457480

458481
/* TCP fastopen related information */
459482
struct tcp_fastopen_request *fastopen_req;
@@ -509,6 +532,9 @@ struct tcp_timewait_sock {
509532
#ifdef CONFIG_TCP_MD5SIG
510533
struct tcp_md5sig_key *tw_md5_key;
511534
#endif
535+
#ifdef CONFIG_TCP_AO
536+
struct tcp_ao_info __rcu *ao_info;
537+
#endif
512538
};
513539

514540
static inline struct tcp_timewait_sock *tcp_twsk(const struct sock *sk)

include/net/dropreason-core.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@
2020
FN(IP_NOPROTO) \
2121
FN(SOCKET_RCVBUFF) \
2222
FN(PROTO_MEM) \
23+
FN(TCP_AUTH_HDR) \
2324
FN(TCP_MD5NOTFOUND) \
2425
FN(TCP_MD5UNEXPECTED) \
2526
FN(TCP_MD5FAILURE) \
27+
FN(TCP_AONOTFOUND) \
28+
FN(TCP_AOUNEXPECTED) \
29+
FN(TCP_AOKEYNOTFOUND) \
30+
FN(TCP_AOFAILURE) \
2631
FN(SOCKET_BACKLOG) \
2732
FN(TCP_FLAGS) \
2833
FN(TCP_ZEROWINDOW) \
@@ -142,6 +147,11 @@ enum skb_drop_reason {
142147
* drop out of udp_memory_allocated.
143148
*/
144149
SKB_DROP_REASON_PROTO_MEM,
150+
/**
151+
* @SKB_DROP_REASON_TCP_AUTH_HDR: TCP-MD5 or TCP-AO hashes are met
152+
* twice or set incorrectly.
153+
*/
154+
SKB_DROP_REASON_TCP_AUTH_HDR,
145155
/**
146156
* @SKB_DROP_REASON_TCP_MD5NOTFOUND: no MD5 hash and one expected,
147157
* corresponding to LINUX_MIB_TCPMD5NOTFOUND
@@ -157,6 +167,26 @@ enum skb_drop_reason {
157167
* to LINUX_MIB_TCPMD5FAILURE
158168
*/
159169
SKB_DROP_REASON_TCP_MD5FAILURE,
170+
/**
171+
* @SKB_DROP_REASON_TCP_AONOTFOUND: no TCP-AO hash and one was expected,
172+
* corresponding to LINUX_MIB_TCPAOREQUIRED
173+
*/
174+
SKB_DROP_REASON_TCP_AONOTFOUND,
175+
/**
176+
* @SKB_DROP_REASON_TCP_AOUNEXPECTED: TCP-AO hash is present and it
177+
* was not expected, corresponding to LINUX_MIB_TCPAOKEYNOTFOUND
178+
*/
179+
SKB_DROP_REASON_TCP_AOUNEXPECTED,
180+
/**
181+
* @SKB_DROP_REASON_TCP_AOKEYNOTFOUND: TCP-AO key is unknown,
182+
* corresponding to LINUX_MIB_TCPAOKEYNOTFOUND
183+
*/
184+
SKB_DROP_REASON_TCP_AOKEYNOTFOUND,
185+
/**
186+
* @SKB_DROP_REASON_TCP_AOFAILURE: TCP-AO hash is wrong,
187+
* corresponding to LINUX_MIB_TCPAOBAD
188+
*/
189+
SKB_DROP_REASON_TCP_AOFAILURE,
160190
/**
161191
* @SKB_DROP_REASON_SOCKET_BACKLOG: failed to add skb to socket backlog (
162192
* see LINUX_MIB_TCPBACKLOGDROP)

0 commit comments

Comments
 (0)