Article View: linux.kernel.netdev
Article #27168Re: [PATCH net 06/10] tcp: reject unreadable skbs on TCP-MD5 and TCP-AO
From: netdev-bot+sashiko
Date: Fri, 04 Dec 2026 22:07
Date: Fri, 04 Dec 2026 22:07
182 lines
14847 bytes
14847 bytes
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
Technical Details
Message-ID:
<179642207543.3146.7112624887714955928@kernel.org>Path:
mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mi.newsdeef.eu!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377690-linux-kernel-netdev=dewy.ruReferences:
<961d3d81ff49e8dd5829a298c8d3a1a11a1e9bfc.1796329894.git.tavip@google.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mi.newsdeef.eu!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377690-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev 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 Organization: Usenet Network Message-ID: <179642207543.3146.7112624887714955928@kernel.org> References: <961d3d81ff49e8dd5829a298c8d3a1a11a1e9bfc.1796329894.git.tavip@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2884566"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:JHSYJmvIj0ziC8WQsUs2aLLiqzw= sha256:Pk2PcEyAzxUCNnGKV/LTmW1bULu/wjCHbZo9sqTMzvQ= sha1:C3gdotUCd0CYZkHI4Oct1WxjBmA= sha256:5GXkdcbvtY1/FBnP4bOTKdxDDdMHxmLHs8UjzPbzrgE= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 3209F117D12; Sat, 5 Dec 2026 01:09:08 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.541 X-Spam-Status: No, score=-3.541 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lWQElDQd-Hou; Sat, 5 Dec 2026 01:09:04 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-377690-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 4FC6E117D0B; Sat, 5 Dec 2026 01:08:56 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id AFF993FE46; Fri, 4 Dec 2026 22:08:08 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796422088; b=lcIoC2vOH8Ia78p8cZPAk+u9T7Oly4mctJPdoR0nXFOpBDDcGOXVq3al12Zrw/Zcbg9b /7gtKept4vhRwctXxF8+zMwxaiDmm0A73ShxjGX8dMRgin7jkzhjmEMo+PD0adaQbK+qh ZMgdMyB/sSr5uXet2oZFtswBvkybMkkFwoztlSNEc06H/QAwNGgBAqfMibdDDQvs1Vr2z I6ifQCxOQjFXzZ6Xj/JasJlFoY4iSI4IAghRspa/A7vNgnQHxliXymYRR54DwKD6t54DY bfCFGKO+GJUw/XlN1XY0uoCddMdeZTPY5QMgTUU4R5gf66qCnizLCPGGTQ5oyxT5tOA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796422088; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=ooC3X5RfdOz0AsiBAKw0xbdYqfyi2uPt/htLBCnT9WQ=; b=O1xfwuKeY5J5kfJI3Dhb7wJFpzKkgbsvO8LWlnpU1IxOsYRnCMR/uNoTrMkV1ThW8hRp hZgiCrIW8jhPLX9tSP+imGXazwhO2Ppr4HSz7CplCx+KppQ0UEZ5DjVZ3whmkDpEWcH1N /lG7HvuQFOyrHp2YMQA7p7/fof91rDy19Jk/9GUonZfOhY1/jl54P+CAIcPJu6t9BNq01 DdU55NqnrCxfFhMTDdsCHH1eDdG6XzApP4G6wxcT4Bh8lmocvLyt5e57OTyU02hcvRVSZ x14f+MFxoB6gqweXLnDmccGe/KxIjsFdxW6SVNrs0fhveRVyrjO1Z7Xa6jtqg2xsoRA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cj5vyZNz; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 85ABD606A336; Fri, 4 Dec 2026 22:08:08 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cj5vyZNz X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796422077; b=EIHR11aHCDk/uS/h0c+8IJmNEhXzz4QdJESML811SpZhr418hIQPSEsu+UvgADFTYUDd OslIlUSbPvJU56AXEI1+VWn4x8goK7i6NPuzmUtok/53le+E3V2X1CxC6RovNAp+kjg64 rFhtuQITGWaqeCEnrCcDHcdGXE/uXWt9zwvQ0qJ0tPQSjgNUTCgVIFAValWsNW9uTCP7+ 3cRxBtzaH5Y4bF5e21P44wRl6rg5jYAePKQfsWoE2v6ZqtyrY1WN/h8z+kpWEop9lg6rI PT9nOwiYXaGGqw7clWjYpWNPbm9z2XS6wngeT9YnRaQnPDYeXKJ1FClpmQiH5cEijwQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796422077; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=ooC3X5RfdOz0AsiBAKw0xbdYqfyi2uPt/htLBCnT9WQ=; b=Ccv9ZIXOFRSPeZRIxRD/C/6EPkFs/LiGkJLji0fPDzThKLfWC0lc7rBOBBHFh+Xp2Qr8 S+lHLlk4ttvkfiklIuO+r8HmVdGY9zc62bBaIrzRT5eS4mumNL7FD7owHMDlSS2KAFuDY NkNcOgug4/JgtlygY1BM8Jo6smIsqk4PRQJvC0a11TOGrxCQgKk799HFHBha5RsL9hqAJ GOah3bu2daBk/A6VDI5gX3icvL4oRl5Mq6oRkN1gclXzAJd7UfhhJnhyq0lYzqFdScNF8 gIDxK3cw5J2GJALEddZPWguBvgJUjzlJrlmAlNUj1UWd47ndTT1Ryk21eSra0T+KpwA== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cj5vyZNz; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A2439606A33B; Fri, 4 Dec 2026 22:07:57 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1BD41F00A1B; Fri, 4 Dec 2026 22:07:55 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796422077; bh=ooC3X5RfdOz0AsiBAKw0xbdYqfyi2uPt/htLBCnT9WQ=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=cj5vyZNzkaFJipGRuPg/RwmNENI3AFXwzwvrKwKLnigOWJeZ7LsbuPUoSIbZIpfN8 b9drFcASkvnw3jIzID36uWYeQg04I1BKReUy7hsXaRq6BO2etD/0mLyK1B0yosCkui /CauE5uQwUyOYPexOVooS3lTfxM4eI+QhYWc34yRh68XqeTcCTHptD23FXnGlZEZHa BjAaMhad3S6UyQ9ZQ3NBvC9G70S5b/uBLA/oiF45ppqux7Ifyk2aKWfUi/FMjz+P2h BJ1idHr+ldOP+Dhw5sqBlHCC0jH6Fh9OAyvQnykus3V8eXqXShMqVLHRPZq7rlsz8r xMhOdUHNVPnHg== X-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 X-In-Reply-To: <961d3d81ff49e8dd5829a298c8d3a1a11a1e9bfc.1796329894.git.tavip@google.com> X-sashiko-severity: Medium X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list