 tls: fix handling of zero-length records on the rx_list · gregkh/linux@3439c15 · 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 3439c15 Browse files Browse files kuba-moo authored and gregkh committed tls: fix handling of zero-length records on the rx_list commit 62708b9 upstream. Each recvmsg() call must process either - only contiguous DATA records (any number of them) - one non-DATA record If the next record has different type than what has already been processed we break out of the main processing loop. If the record has already been decrypted (which may be the case for TLS 1.3 where we don't know type until decryption) we queue the pending record to the rx_list. Next recvmsg() will pick it up from there. Queuing the skb to rx_list after zero-copy decrypt is not possible, since in that case we decrypted directly to the user space buffer, and we don't have an skb to queue (darg.skb points to the ciphertext skb for access to metadata like length). Only data records are allowed zero-copy, and we break the processing loop after each non-data record. So we should never zero-copy and then find out that the record type has changed. The corner case we missed is when the initial record comes from rx_list, and it's zero length. Reported-by: Muhammad Alifa Ramdhan &lt;ramdhan@starlabs.sg&gt; Reported-by: Billy Jheng Bing-Jhong &lt;billy@starlabs.sg&gt; Fixes: 84c61fe ("tls: rx: do not use the standard strparser") Reviewed-by: Sabrina Dubroca &lt;sd@queasysnail.net&gt; Link: https://patch.msgid.link/20250820021952.143068-1-kuba@kernel.org Signed-off-by: Jakub Kicinski &lt;kuba@kernel.org&gt; Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt; 1 parent e42ac65 commit 3439c15 Copy full SHA for 3439c15 1 file changed + 6 - 1 Lines changed: 6 additions &amp; 1 deletion File tree Expand file tree Collapse file tree Open diff view settings Filter options net/tls tls_sw.c Expand file tree Collapse file tree Open diff view settings Collapse file ‎ net/tls/tls_sw.c ‎ Copy file name to clipboard Expand all lines: net/tls/tls_sw.c + 6 - 1 Lines changed: 6 additions &amp; 1 deletion Original file line number Diff line number Diff line change @@ -1774,6 +1774,9 @@ int decrypt_skb(struct sock *sk, struct scatterlist *sgout) 1774 1774 return tls_decrypt_sg ( sk , NULL , sgout , &amp; darg ); 1775 1775 } 1776 1776 1777 + /* All records returned from a recvmsg() call must have the same type. 1778 + * 0 is not a valid content type. Use it as &quot;no type reported, yet&quot;. 1779 + */ 1777 1780 static int tls_record_content_type ( struct msghdr * msg , struct tls_msg * tlm , 1778 1781 u8 * control ) 1779 1782 { @@ -2017,8 +2020,10 @@ int tls_sw_recvmsg(struct sock *sk, 2017 2020 if ( err &lt; 0 ) 2018 2021 goto end ; 2019 2022 2023 + /* process_rx_list() will set @control if it processed any records */ 2020 2024 copied = err ; 2021 - if ( len &lt;= copied || ( copied &amp;&amp; control != TLS_RECORD_TYPE_DATA ) || rx_more ) 2025 + if ( len &lt;= copied || rx_more || 2026 + ( control &amp;&amp; control != TLS_RECORD_TYPE_DATA )) 2022 2027 goto end ; 2023 2028 2024 2029 target = sock_rcvlowat ( sk , flags &amp; MSG_WAITALL , len ); 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. 