Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The patch tries to stop unreadable (devmem) skbs on the TX
queues from coexisting with an active TCP-MD5 key.
- [Low] The patch adds a new early exit in tcp_ao_hash_skb()
(net/ipv4/tcp_ao.c): `if (tcp_ao_hash_skb_data(&mac_ctx, skb, th->doff…
- [Low] Documentation/networking/devmem.rst, 'Implementation & Caveats'
-> 'Unreadable skbs', lists what breaks with devmem payloads:…
--
tcp: reject unreadable skbs on TCP-MD5 and TCP-AO
This patch makes the TCP-MD5 and TCP-AO payload hashing helpers fail
with -EFAULT on unreadable (devmem) skbs, and checks those errors on
the receive and reset paths. On transmit, it rejects devmem sends when
an MD5 or AO key is active and rejects adding keys while unreadable
skbs are queued. It also adds a guard in __tcp_transmit_skb().
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index 80de376a9d2ef..f0ab18b589872 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -1226,6 +1226,16 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
> /* 'common' sending to sendq */
> }
>
> + if (unlikely(binding)) {
> + struct tcp_key key;
> +
> + tcp_get_current_key(sk, &key);
> + if (tcp_key_is_md5(&key) || tcp_key_is_ao(&key)) {
> + err = -EOPNOTSUPP;
> + goto out_err;
> + }
> + }
> +
[Severity: Medium]
This check runs only once, before the restart: label. Can a TCP-MD5 key
become current after it has passed?
Inside the copy loop, new_segment can jump to wait_for_space. That
happens, for example, when readable skbs from earlier sends fill
sk_sndbuf:
wait_for_space:
sk_set_nospace(sk);
...
err = sk_stream_wait_memory(sk, &timeo);
sk_stream_wait_memory() drops the socket lock in sk_wait_event(). While
the lock is dropped, a concurrent setsockopt(TCP_MD5SIG) can run:
do_tcp_setsockopt()
tcp_v4_parse_md5_keys()
tcp_md5_do_add()
tcp_tx_has_unreadable_skb() <- only readable skbs queued so far
tcp_md5_do_add() has no socket state restriction, so the key gets
installed. When the sender gets the lock back, it keeps queueing devmem
skbs without checking the key again. The
skb_frags_readable(skb) != !binding test forces new segments.
The TCP-AO version of this doesn't seem possible, because the first
TCP_AO_ADD_KEY requires LISTEN or CLOSE state.
There also seems to be a way to get here with no key add at all.
tcp_v4_md5_lookup() and tcp_v6_md5_lookup() take l3index from
addr_sk->sk_bound_dev_if:
l3index = l3mdev_master_ifindex_by_index(sock_net(sk),
addr_sk->sk_bound_dev_if);
Suppose a VRF-scoped (TCP_MD5SIG_FLAG_IFINDEX) key does not match the
unbound socket. Devmem sends are then allowed and devmem skbs get
queued.
A later first SO_BINDTODEVICE, or enslaving the device to the VRF, can
make md5_lookup() return that key. tcp_md5_do_add() is never called in
this case.
In both cases the guard added to __tcp_transmit_skb() fires on every
transmit, retransmit and window probe. tcp_write_xmit() then leaves the
skb at the head of the write queue:
if (unlikely(tcp_transmit_skb(sk, skb, 1, gfp)))
break;
sendmsg() has already reported this data as sent. Does the connection
then stall until the probe or RTO limits abort it?
The guard does prevent the bad page mapping. However, the commit
message calls it only "a defensive guard in __tcp_transmit_skb()",
while this path is reachable and ends in a stall.
[ ... ]
> diff --git a/net/ipv4/tcp_ao.c b/net/ipv4/tcp_ao.c
> index 857b8684e01d9..34c69dfcedd04 100644
> --- a/net/ipv4/tcp_ao.c
> +++ b/net/ipv4/tcp_ao.c
[ ... ]
> @@ -726,7 +733,8 @@ int tcp_ao_hash_skb(unsigned short int family,
> tcp_ao_hash_header(&mac_ctx, th,
> !!(key->keyflags & TCP_AO_KEYF_EXCLUDE_OPT),
> ao_hash, hash_offset, tcp_ao_maclen(key));
> - tcp_ao_hash_skb_data(&mac_ctx, skb, th->doff << 2);
> + if (tcp_ao_hash_skb_data(&mac_ctx, skb, th->doff << 2))
> + goto clear_hash;
> tcp_ao_mac_final(&mac_ctx, hash_buf);
>
> memcpy(ao_hash, hash_buf, tcp_ao_maclen(key));
[Severity: Low]
This new exit is taken after tcp_ao_mac_init() has expanded the traffic
key into the on-stack mac_ctx, and it skips tcp_ao_mac_final().
For HMAC-SHA1 and HMAC-SHA256, isn't the final step the only place the
keyed context gets wiped? The library final routines end with
memzero_explicit(ctx, sizeof(*ctx)). The clear_hash label only clears
the output buffer:
clear_hash:
memset(ao_hash, 0, tcp_ao_maclen(key));
return 1;
On this path, the HMAC inner and outer state derived from the traffic
key stays in the dead stack frame of tcp_ao_hash_skb(). A remote peer
can reach this through tcp_ao_verify_hash()->tcp_ao_hash_skb() when
AO-signed segments land on a devmem RX queue.
Could skb_frags_readable() be checked before tcp_ao_mac_init()?
Alternatively, mac_ctx could be wiped with memzero_explicit() on the
error path.
For AES-128-CMAC, aes_cmac_final() does not wipe mac_ctx->aes_cmac.key.
The expanded AES key is therefore already left on the stack on the
existing success path. Only the HMAC case is new here.
[ ... ]
> @@ -1665,6 +1673,9 @@ static int tcp_ao_add_cmd(struct sock *sk, unsigned short int family,
> if (IS_ERR(ao_info))
> return PTR_ERR(ao_info);
>
> + if (tcp_tx_has_unreadable_skb(sk))
> + return -EOPNOTSUPP;
> +
[Severity: Low]
This isn't a bug, but Documentation/networking/devmem.rst has an
"Unreadable skbs" caveat list. It covers loopback, software checksum,
and tcpdump/bpf, but not the restrictions this patch adds:
- tcp_sendmsg_locked() returns -EOPNOTSUPP for devmem TX when TCP-MD5
or TCP-AO is active.
- setsockopt(TCP_MD5SIG/TCP_MD5SIG_EXT) via tcp_md5_do_add(), and
setsockopt(TCP_AO_ADD_KEY) via tcp_ao_add_cmd(), return -EOPNOTSUPP
while unreadable skbs are queued.
- Devmem RX segments on an MD5 or AO connection are dropped as
authentication failures.
Could the caveat list be updated to say that devmem and TCP-MD5/TCP-AO
cannot be combined?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cove…%40google.com