From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1BD41F00A1B; Fri, 4 Dec 2026 22:07:55 +0000 (UTC) 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== Subject: Re: [PATCH net 06/10] tcp: reject unreadable skbs on TCP-MD5 and TCP-AO 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 Date: Fri, 04 Dec 2026 22:07:55 +0000 Message-ID: <179642207543.3146.7112624887714955928@kernel.org> In-Reply-To: <961d3d81ff49e8dd5829a298c8d3a1a11a1e9bfc.1796329894.git.tavip@google.com> References: <961d3d81ff49e8dd5829a298c8d3a1a11a1e9bfc.1796329894.git.tavip@google.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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