Skip to content

Commit 9396c4e

Browse files
0x7f454c46Paolo Abeni
authored andcommitted
net/tcp: Don't store TCP-AO maclen on reqsk
This extra check doesn't work for a handshake when SYN segment has (current_key.maclen != rnext_key.maclen). It could be amended to preserve rnext_key.maclen instead of current_key.maclen, but that requires a lookup on listen socket. Originally, this extra maclen check was introduced just because it was cheap. Drop it and convert tcp_request_sock::maclen into boolean tcp_request_sock::used_tcp_ao. Fixes: 06b22ef ("net/tcp: Wire TCP-AO to request sockets") Signed-off-by: Dmitry Safonov <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 12083d7 commit 9396c4e

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed

include/linux/tcp.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ struct tcp_request_sock {
169169
#ifdef CONFIG_TCP_AO
170170
u8 ao_keyid;
171171
u8 ao_rcv_next;
172-
u8 maclen;
172+
bool used_tcp_ao;
173173
#endif
174174
};
175175

@@ -180,14 +180,10 @@ static inline struct tcp_request_sock *tcp_rsk(const struct request_sock *req)
180180

181181
static inline bool tcp_rsk_used_ao(const struct request_sock *req)
182182
{
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-
*/
187183
#ifndef CONFIG_TCP_AO
188184
return false;
189185
#else
190-
return tcp_rsk(req)->maclen != 0;
186+
return tcp_rsk(req)->used_tcp_ao;
191187
#endif
192188
}
193189

net/ipv4/tcp_ao.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ void tcp_ao_syncookie(struct sock *sk, const struct sk_buff *skb,
851851
const struct tcp_ao_hdr *aoh;
852852
struct tcp_ao_key *key;
853853

854-
treq->maclen = 0;
854+
treq->used_tcp_ao = false;
855855

856856
if (tcp_parse_auth_options(th, NULL, &aoh) || !aoh)
857857
return;
@@ -863,7 +863,7 @@ void tcp_ao_syncookie(struct sock *sk, const struct sk_buff *skb,
863863

864864
treq->ao_rcv_next = aoh->keyid;
865865
treq->ao_keyid = aoh->rnext_keyid;
866-
treq->maclen = tcp_ao_maclen(key);
866+
treq->used_tcp_ao = true;
867867
}
868868

869869
static enum skb_drop_reason

net/ipv4/tcp_input.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7182,11 +7182,12 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,
71827182
if (tcp_parse_auth_options(tcp_hdr(skb), NULL, &aoh))
71837183
goto drop_and_release; /* Invalid TCP options */
71847184
if (aoh) {
7185-
tcp_rsk(req)->maclen = aoh->length - sizeof(struct tcp_ao_hdr);
7185+
tcp_rsk(req)->used_tcp_ao = true;
71867186
tcp_rsk(req)->ao_rcv_next = aoh->keyid;
71877187
tcp_rsk(req)->ao_keyid = aoh->rnext_keyid;
7188+
71887189
} else {
7189-
tcp_rsk(req)->maclen = 0;
7190+
tcp_rsk(req)->used_tcp_ao = false;
71907191
}
71917192
#endif
71927193
tcp_rsk(req)->snt_isn = isn;

net/ipv4/tcp_output.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3720,7 +3720,6 @@ struct sk_buff *tcp_make_synack(const struct sock *sk, struct dst_entry *dst,
37203720
if (tcp_rsk_used_ao(req)) {
37213721
#ifdef CONFIG_TCP_AO
37223722
struct tcp_ao_key *ao_key = NULL;
3723-
u8 maclen = tcp_rsk(req)->maclen;
37243723
u8 keyid = tcp_rsk(req)->ao_keyid;
37253724

37263725
ao_key = tcp_sk(sk)->af_specific->ao_lookup(sk, req_to_sk(req),
@@ -3730,13 +3729,11 @@ struct sk_buff *tcp_make_synack(const struct sock *sk, struct dst_entry *dst,
37303729
* for another peer-matching key, but the peer has requested
37313730
* ao_keyid (RFC5925 RNextKeyID), so let's keep it simple here.
37323731
*/
3733-
if (unlikely(!ao_key || tcp_ao_maclen(ao_key) != maclen)) {
3734-
u8 key_maclen = ao_key ? tcp_ao_maclen(ao_key) : 0;
3735-
3732+
if (unlikely(!ao_key)) {
37363733
rcu_read_unlock();
37373734
kfree_skb(skb);
3738-
net_warn_ratelimited("TCP-AO: the keyid %u with maclen %u|%u from SYN packet is not present - not sending SYNACK\n",
3739-
keyid, maclen, key_maclen);
3735+
net_warn_ratelimited("TCP-AO: the keyid %u from SYN packet is not present - not sending SYNACK\n",
3736+
keyid);
37403737
return NULL;
37413738
}
37423739
key.ao_key = ao_key;

0 commit comments

Comments
 (0)