From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: netdev@vger.kernel.org
Cc: mrpre@163.com, Jiayuan Chen <jiayuan.chen@linux.dev>,
Eric Dumazet <edumazet@google.com>,
Neal Cardwell <ncardwell@google.com>,
Kuniyuki Iwashima <kuniyu@google.com>,
"David S. Miller" <davem@davemloft.net>,
David Ahern <dsahern@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
David Howells <dhowells@redhat.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH net-next v1] tcp: Correct signedness in skb remaining space calculation
Date: Wed, 2 Jul 2025 19:00:38 +0800 [thread overview]
Message-ID: <20250702110039.15038-1-jiayuan.chen@linux.dev> (raw)
The calculation for the remaining space, 'copy = size_goal - skb->len',
was prone to an integer promotion bug that prevented copy from ever being
negative.
The variable types involved are:
copy: ssize_t (long)
size_goal: int
skb->len: unsigned int
Due to C's type promotion rules, the signed size_goal is converted to an
unsigned int to match skb->len before the subtraction. The result is an
unsigned int.
When this unsigned int result is then assigned to the s64 copy variable,
it is zero-extended, preserving its non-negative value. Consequently,
copy is always >= 0.
The intended logic is that a negative copy value indicates that the tail
skb lacks sufficient space for appending new data, which should trigger
the allocation of a new skb. Because of this bug, the condition copy <= 0
was never met, causing the code to always append to the tail skb.
Fixes: 270a1c3de47e ("tcp: Support MSG_SPLICE_PAGES")
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
---
net/ipv4/tcp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 8a3c99246d2e..ed942cd17351 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1180,7 +1180,7 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
skb = tcp_write_queue_tail(sk);
if (skb)
- copy = size_goal - skb->len;
+ copy = size_goal - (ssize_t)skb->len;
trace_tcp_sendmsg_locked(sk, msg, skb, size_goal);
--
2.47.1
next reply other threads:[~2025-07-02 11:01 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-02 11:00 Jiayuan Chen [this message]
2025-07-02 13:41 ` [PATCH net-next v1] tcp: Correct signedness in skb remaining space calculation Jiayuan Chen
2025-07-02 13:59 ` Eric Dumazet
2025-07-02 14:02 ` Eric Dumazet
2025-07-02 15:27 ` Jiayuan Chen
2025-07-02 15:34 ` Eric Dumazet
2025-07-03 12:03 ` Jiayuan Chen
2025-07-03 12:06 ` Jiayuan Chen
2025-07-03 12:33 ` Eric Dumazet
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=20250702110039.15038-1-jiayuan.chen@linux.dev \
--to=jiayuan.chen@linux.dev \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mrpre@163.com \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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;
as well as URLs for NNTP newsgroup(s).