BPF List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: tavip@google.com
Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, willemb@google.com,
	horms@kernel.org, andrew+netdev@lunn.ch, ncardwell@google.com,
	kuniyu@google.com, dsahern@kernel.org, idosch@nvidia.com,
	john.fastabend@gmail.com, jakub@cloudflare.com,
	jiayuan.chen@linux.dev, sd@queasysnail.net, shuah@kernel.org,
	almasrymina@google.com, sdf@fomichev.me, kaiyuanz@google.com,
	ilias.apalodimas@linaro.org, hawk@kernel.org,
	mcroce@microsoft.com, herbert@gondor.apana.org.au,
	ecree.xilinx@gmail.com, bpf@vger.kernel.org,
	linux-kselftest@vger.kernel.org
Subject: Re: [PATCH net 06/10] tcp: reject unreadable skbs on TCP-MD5 and TCP-AO
Date: Fri, 04 Dec 2026 22:07:55 +0000	[thread overview]
Message-ID: <179642207543.3146.7112624887714955928@kernel.org> (raw)
In-Reply-To: <961d3d81ff49e8dd5829a298c8d3a1a11a1e9bfc.1796329894.git.tavip@google.com>

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/cover.1796329894.git.tavip%40google.com

  parent reply	other threads:[~2026-12-04 22:07 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 21:09 [PATCH net 00/10] net: fix unreadable net_iov skb handling across networking paths Octavian Purdila
2026-12-03 21:09 ` [PATCH net 01/10] net: gro: free skb on napi_frags_skb() header pull failure Octavian Purdila
2026-12-04 18:31   ` Mina Almasry
2026-12-03 21:09 ` [PATCH net 02/10] net: gro: reset unreadable and pp_recycle in napi_reuse_skb Octavian Purdila
2026-12-04 18:32   ` Mina Almasry
2026-12-04 21:07     ` Octavian Purdila
2026-12-04 21:09   ` sashiko-bot
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 03/10] inet: frag: reject fragments with mixed readability in reassembly Octavian Purdila
2026-12-04 18:38   ` Mina Almasry
2026-12-04 21:09     ` Octavian Purdila
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 04/10] net: skbuff, skmsg, strparser: reject unreadable frags Octavian Purdila
2026-12-04 18:58   ` Mina Almasry
2026-12-04 21:25     ` Octavian Purdila
2026-12-04 21:09   ` sashiko-bot
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 05/10] tls: reject unreadable skbs in tls_strp Octavian Purdila
2026-12-04 18:44   ` Mina Almasry
2026-12-04 22:24     ` Octavian Purdila
2026-12-04 21:09   ` sashiko-bot
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 06/10] tcp: reject unreadable skbs on TCP-MD5 and TCP-AO Octavian Purdila
2026-12-04 18:46   ` Mina Almasry
2026-12-04 22:26     ` Octavian Purdila
2026-12-04 21:09   ` sashiko-bot
2026-12-04 22:07   ` netdev-bot+sashiko [this message]
2026-12-03 21:09 ` [PATCH net 07/10] net: kunit: test unreadable net_iov napi_gro_frags Octavian Purdila
2026-12-04 18:47   ` Mina Almasry
2026-12-04 21:09   ` sashiko-bot
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 08/10] net: kunit: test unreadable net_iov defrag and skb helpers Octavian Purdila
2026-12-04 21:09   ` sashiko-bot
2026-12-04 22:07   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 09/10] selftests: drv-net: devmem: test unreadable kTLS RX Octavian Purdila
2026-12-04 18:48   ` Mina Almasry
2026-12-04 22:28     ` Octavian Purdila
2026-12-04 21:09   ` sashiko-bot
2026-12-04 22:08   ` netdev-bot+sashiko
2026-12-03 21:09 ` [PATCH net 10/10] selftests: drv-net: devmem: test unreadable skbs on TCP-MD5 and TCP-AO Octavian Purdila
2026-12-04 21:09   ` sashiko-bot
2026-12-04 22:08   ` netdev-bot+sashiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179642207543.3146.7112624887714955928@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=almasrymina@google.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=bpf@vger.kernel.org \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=ecree.xilinx@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=hawk@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jakub@cloudflare.com \
    --cc=jiayuan.chen@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=kaiyuanz@google.com \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mcroce@microsoft.com \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sd@queasysnail.net \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=tavip@google.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox