๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #20654

Re: [PATCH net v2] tls: fix send() returning success after the TCP send failed

#20654
From: netdev-bot+sashiko
Date: Mon, 23 Nov 2026 02:13
124 lines
12515 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 ยท High: 1 ยท Medium: 0 ยท Low: 0

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).

- [High] With async encryption, send() still returns success when the TCP
  send fails during that same call.

--

tls: fix send() returning success after the TCP send failed

The patch adds an abort_err field to struct tls_sw_context_tx. It is set
when tls_tx_records() aborts the connection after a failed TCP send. The
field is checked in tls_tx_records(), tls_push_record() and the
tls_sw_sendmsg_locked() loop, and bpf_exec_tx_verdict() uses it to tell
that the record was not sent and to take it out of copied.

> diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
> index 226e0f176fdc8..795cbfe5fb2a1 100644
> --- a/net/tls/tls_sw.c
> +++ b/net/tls/tls_sw.c

[ ... ]

> @@ -708,13 +717,15 @@ static int tls_push_record(struct sock *sk, int flags,
>  static int bpf_exec_tx_verdict(struct sk_msg *msg, struct sock *sk,
>  			       u8 record_type, ssize_t *copied, int flags)
>  {
> +	struct tls_sw_context_tx *ctx = tls_sw_ctx_tx(tls_get_ctx(sk));
>  	int err;
>
>  	err = tls_push_record(sk, flags, record_type);
> -	if (err && err != -EINPROGRESS && sk->sk_err == EBADMSG) {
> +	if (err && err != -EINPROGRESS &&
> +	    (ctx->abort_err || sk->sk_err == EBADMSG)) {
>  		*copied -= sk_msg_free(sk, msg);
>  		tls_free_open_rec(sk);
> -		err = -sk->sk_err;
> +		err = ctx->abort_err ?: -EBADMSG;
>  	}
>  	return err;
>  }

[Severity: High]
When encryption completes asynchronously, can send() still return success
after the TCP send fails in that same call?

With an async AEAD, or on the MAY_BACKLOG -EBUSY path that ends up as
-EINPROGRESS, tls_push_record() returns before it reaches
tls_tx_records():

    rc = tls_do_encryption(sk, tls_ctx, ctx, req, ...);
    if (rc < 0) {
        if (rc != -EINPROGRESS)
            tls_err_abort(sk, -EBADMSG);
        ctx->async_capable = 1;
        return rc;
    }

That makes err == -EINPROGRESS here, so the new branch is skipped and
nothing is subtracted from *copied.

The record then goes to TCP later in the same sendmsg() call, from the
send_end block of tls_sw_sendmsg_locked():

    /* Transmit if any encryptions have completed */
    if (test_and_clear_bit(BIT_TX_SCHEDULED, &ctx->tx_bitmask)) {
        cancel_delayed_work(&ctx->tx_work.work);
        tls_tx_records(sk, msg->msg_flags);
    }

end:
    ret = sk_stream_error(sk, msg->msg_flags, ret);
    return copied > 0 ? copied : ret;

Say tcp_sendmsg_locked() fails there with -EPIPE after shutdown(SHUT_WR)
or a reset. tls_tx_records() sets ctx->abort_err, but its return value
is dropped. ret is still 0 and copied is positive, so the caller is told
that the record was sent.

The two in-loop "Transmit if any encryptions have completed" blocks, on
the zerocopy and copy paths, follow the same pattern. The next iteration
hits the new abort_err check and jumps to send_end, but copied still
counts the failed records.

Take the reproducer from the commit message on a system where gcm(aes)
completes asynchronously. The first send has async_capable == 0 and
eor == true, so it takes the zerocopy path. Then:

tls_sw_sendmsg_locked()
  bpf_exec_tx_verdict() returns -EINPROGRESS, num_async++
  send_end: tls_encrypt_async_wait() returns 0
  tls_tx_records()
    tls_push_sg()
      tcp_sendmsg_locked() returns -EPIPE
  return copied

So it looks like send() would still print 5. Later sends do now fail with
EPIPE because of the new check at the top of the loop.

tx_work_handler() also ignores the result of tls_tx_records(). There,
though, the send that queued the record has usually returned already.

The commit message says "Do not count the record as sent" and "The send()
above then fails with EPIPE". Should the tls_tx_records() error from the
send_end and in-loop transmits be propagated, or ctx->abort_err be checked
after them, so that the failed records are not counted in copied?

This first-send behaviour on the async path also existed before
b341ca51d267. Since this patch targets this class of bug, would it make
sense to cover the async path too?

[ ... ]

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119141106.840038-1-hengyul%40cs.unc.edu
Technical Details
Message-ID: <179540001873.3135.1838308128939252702@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368957-linux-kernel-netdev=dewy.ru
References: <20261119141106.840038-1-hengyul@cs.unc.edu>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368957-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2] tls: fix send() returning success after the TCP
 send failed
Date: Mon, 23 Nov 2026 02:13:38 +0000
Organization: Usenet Network
Message-ID: <179540001873.3135.1838308128939252702@kernel.org>
References: <20261119141106.840038-1-hengyul@cs.unc.edu>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3769824"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:WfauUNRIGV3NxAvRdCC6fOGQDLY= sha256:Ij/EAcq+ZU5sQ44a+YPEKHaWFwJcGCXT1/UKjVXynT0=
	sha1:idijW1cXFaTstEpQEomkBztypeE= sha256:xNC/kmddZTEN/C20tWV3DmAfimlj8+xUBmj0eDQoelc=
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 B2EFA125D8A; Mon, 23 Nov 2026 05:13:57 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, 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 9EO2dGDZ3BNN;
	Mon, 23 Nov 2026 05:13:53 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-368957-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 13006125D83; Mon, 23 Nov 2026 05:13:45 +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 ADE002C4C8; Mon, 23 Nov 2026 02:13:42 +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=1795400021;
	b=prPswuz0CNBjIiW65U7IM4i0sCuCNJKr/JvE2h27UgGTpvCVVeIlJloVcjf2MGGlu0Ao
	 E0+pMwU7R5MMOrc3/6x30yO49jzJYhB2WQNLQYa7CZLJsZtlNGUhfkqjzYtAtBQnhsJoT
	 oqJxJOL48q85WTlV+nAaCmcARuk4OSjuz4t/UJUyDKoBhYVZJcgIZya1ZQin1fgAsFf/0
	 1tjIqJL7I/KNeDpMAmeIjHC/O5at0BphOBctss9lmZ9jcrjm9hYyyDDaBMHt5gyYcEB5I
	 PE56/YPkBoDgGL6ffMvfPLUwwwx4Hso+u1uMw8btnPU6XgI4VRYaKxUoKhmyNcIWEpQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795400021;
	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=w0qcFHuhOxRFhzy+XALtHsGtZc6YwmNn3t9p0bTe8Ek=;
	b=ZNeROL8nUzeYlh+mol1XVQp2kZ3AQWZL002QCLeTNwh6M4WIMbz41T5E+i+hHVEEE+pV
	 Dknat7hW5Z3rO9IYTqa5Ad+MKWJmjQIpVwmqHxN5AS6AlSeMAWsxfQ8rVgS/VpP+7shIe
	 B0eB8jVit6RVu+MZLywydQnZ1dXxa9ehLlJuRXi51VDOZDjJt3ObDaWH3aJO9rzGI/lHx
	 LYsCSkbcFDXU1oxMq5MxjBtI0vsR3RecW8JYnhOCrCeWnLojV8tbb0cqs5iLVFK+gYAFd
	 ptMcMfpdlq1Qit3++IEGrB2qSAgNb6wzqaMlV9VukA4OujIuOGnnZgaIbmCXD4e/UaA==
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=cRPPexqY;
	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 C39BA606A68C;
	Mon, 23 Nov 2026 02:13:41 +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=cRPPexqY
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=1795400021;
	b=KQmmSbU4V7/++l9KIUR+qPY1CLHl3bq5k6a3dV+BXZvx9d4vhTyGsAad+CKHOCHFZ9xX
	 kpTgU2Cq0KrcNkxjzvd1wIGAVarx2ptsEkkPyP3kNrwi9ac523EAuLqSUR1DUc0lKnNny
	 1RcOX4S3Fs1a5pGlImmIl94H9BXiFx4kIgOR80WYdrkwsNecZyWr258PEEtxqQiOnVbYp
	 DjsU+El5hOpRiERFw9yyvsz0lxoVyRFKVCba+L2qhOF3OWyuPVXxb0EMOfhrUNSFEIT2L
	 4lwNw+hu5N3wZlWpNoj4g8o/PnCFZ3M6GiRDU2iZ5DyulOTm/rdBwExSlkkaTwr1SOw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795400021;
	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=w0qcFHuhOxRFhzy+XALtHsGtZc6YwmNn3t9p0bTe8Ek=;
	b=KxihsPMJU1PrqviMQS6w6tfHSoMw2lqvm5fIFqz15ydluDgXdhR2fft0KYussOt3n0OR
	 k25KoBzr7U2YtsMYihG7+E1H5S3TQxlxqarK2IoVCdJjd/fmsMl1nOW+3SBQ4Yh3x1fD3
	 WMDshIrF6CvG2FAIxl/Z6e5pP5tgvtZId865aIXO56wvyRG2eZ6lyJfZ+bhC5COQJuNSi
	 oZpe60AEVGzFRNWjP9oriXfEILIfa5nEt8dp5y7ICZLl1VSThf9ziFhRzPlfElJZ41xFZ
	 RegmK3aU3sNvsD+A/3aMBOt1jFgBOCFJ5kQfGl9bwhMcBrGrZkjGNMEtT/CXKehzzMQ==
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=cRPPexqY;
	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) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id E30EC606A33C;
	Mon, 23 Nov 2026 02:13:40 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F8481F000C6;
	Mon, 23 Nov 2026 02:13:39 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795400019;
	bh=w0qcFHuhOxRFhzy+XALtHsGtZc6YwmNn3t9p0bTe8Ek=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=cRPPexqYtX4gt98SVt8GN3oQ0ogmZgyPAGRoQo3ek9jc/awTUFDn2vFTuhR10E8sN
	 h9iS/vYQKqZ6sdWCbaI6Ex7NQKmvjT3n6S1V4hLqQwxTnOPU6pEGKb5E7P77byfb7H
	 3KNPtRgBO1MAdtWsqJfsUHe6dlAEmCZNDSdc8AZl7Eo8xsMhVYlIjYijZEDt9LFLOo
	 pWMDMbzFGkxv2ppepByqp9p03A5RBN9NZGOkklK4pxSCCfOBKJji/+md9n037KG0zt
	 Ty+7jPmIEvPdKiXRDJ5CKziZtsnwMMEAMorMghAlV7egPP6yZXmLBnYu7fOe9d9qoi
	 tovYqz40/H8xQ==
X-Cc: john.fastabend@gmail.com, kuba@kernel.org, sd@queasysnail.net,
 davem@davemloft.net, edumazet@kernel.org, pabeni@redhat.com, horms@kernel.org,
 bcodding@redhat.com, ben.coddington@hammerspace.com,
 rjethwani@purestorage.com, netdev@vger.kernel.org, bpf@vger.kernel.org,
 linux-kernel@vger.kernel.org
X-In-Reply-To: <20261119141106.840038-1-hengyul@cs.unc.edu>
X-sashiko-severity: High
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