 tcp: fix a signed-integer-overflow bug in tcp_add_backlog() · gregkh/linux@9d04b4d · GitHub Skip to content Navigation Menu Toggle navigation Sign in Appearance settings Platform AI CODE CREATION GitHub Copilot Write better code with AI GitHub Spark Build and deploy intelligent apps GitHub Models Manage and compare prompts MCP Registry New Integrate external tools DEVELOPER WORKFLOWS Actions Automate any workflow Codespaces Instant dev environments Issues Plan and track work Code Review Manage code changes APPLICATION SECURITY GitHub Advanced Security Find and fix vulnerabilities Code security Secure your code as you build Secret protection  EXPLORE Why GitHub Documentation Blog Changelog Marketplace View all features Solutions BY COMPANY SIZE Enterprises Small and medium teams Startups Nonprofits BY USE CASE App Modernization DevSecOps DevOps CI/CD View all use cases BY INDUSTRY Healthcare Financial services Manufacturing Government View all industries View all solutions Resources EXPLORE BY TOPIC AI Software Development DevOps Security View all topics EXPLORE BY TYPE Customer stories Events &amp; webinars Ebooks &amp; reports Business insights GitHub Skills SUPPORT &amp; SERVICES Documentation Customer support Community forum Trust center Partners View all resources Open Source COMMUNITY GitHub Sponsors Fund open source developers PROGRAMS Security Lab Maintainer Community Accelerator GitHub Stars Archive Program REPOSITORIES Topics Trending Collections Enterprise ENTERPRISE SOLUTIONS Enterprise platform AI-powered developer platform AVAILABLE ADD-ONS GitHub Advanced Security Enterprise-grade security features Copilot for Business Enterprise-grade AI features Premium Support Enterprise-grade 24/7 support Pricing Search or jump to... Search code, repositories, users, issues, pull requests... --> Search Clear Search syntax tips Provide feedback --> We read every piece of feedback, and take your input very seriously.  Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly --> Name Query To see all available qualifiers, see our documentation . Cancel Create saved search Sign in Sign up Appearance settings Resetting focus You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} gregkh / linux Public Notifications You must be signed in to change notification settings Fork 676 Star 636 Code Actions Security and quality 0 Insights Additional navigation options Code Actions Security and quality Insights Commit 9d04b4d Browse files Browse files Lu Wei authored and gregkh committed tcp: fix a signed-integer-overflow bug in tcp_add_backlog() [ Upstream commit ec791d8 ] The type of sk_rcvbuf and sk_sndbuf in struct sock is int, and in tcp_add_backlog(), the variable limit is caculated by adding sk_rcvbuf, sk_sndbuf and 64 * 1024, it may exceed the max value of int and overflow. This patch reduces the limit budget by halving the sndbuf to solve this issue since ACK packets are much smaller than the payload. Fixes: c9c3321 ("tcp: add tcp_add_backlog()") Signed-off-by: Lu Wei &lt;luwei32@huawei.com&gt; Reviewed-by: Eric Dumazet &lt;edumazet@google.com&gt; Acked-by: Kuniyuki Iwashima &lt;kuniyu@amazon.com&gt; Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt; Stable-dep-of: ec00ed4 ("tcp: avoid premature drops in tcp_add_backlog()") Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt; 1 parent 527eaa5 commit 9d04b4d Copy full SHA for 9d04b4d 1 file changed + 3 - 1 Lines changed: 3 additions &amp; 1 deletion File tree Expand file tree Collapse file tree Open diff view settings Filter options net/ipv4 tcp_ipv4.c Expand file tree Collapse file tree Open diff view settings Collapse file ‎ net/ipv4/tcp_ipv4.c ‎ Copy file name to clipboard Expand all lines: net/ipv4/tcp_ipv4.c + 3 - 1 Lines changed: 3 additions &amp; 1 deletion Original file line number Diff line number Diff line change @@ -1781,11 +1781,13 @@ bool tcp_add_backlog(struct sock *sk, struct sk_buff *skb) 1781 1781 __skb_push ( skb , hdrlen ); 1782 1782 1783 1783 no_coalesce : 1784 + limit = ( u32 ) READ_ONCE ( sk -&gt; sk_rcvbuf ) + ( u32 )( READ_ONCE ( sk -&gt; sk_sndbuf ) &gt;&gt; 1 ); 1785 + 1784 1786 /* Only socket owner can try to collapse/prune rx queues 1785 1787 * to reduce memory overhead, so add a little headroom here. 1786 1788 * Few sockets backlog are possibly concurrently non empty. 1787 1789 */ 1788 - limit = READ_ONCE ( sk -&gt; sk_rcvbuf ) + READ_ONCE ( sk -&gt; sk_sndbuf ) + 64 * 1024 ; 1790 + limit += 64 * 1024 ; 1789 1791 1790 1792 if ( unlikely ( sk_add_backlog ( sk , skb , limit ))) { 1791 1793 bh_unlock_sock ( sk ); 0 commit comments Comments 0 ( 0 ) Footer &copy; 2026 GitHub,&nbsp;Inc. Footer navigation Terms Privacy Security Status Community Docs Contact Manage cookies Do not share my personal information You can’t perform that action at this time. 