 tls: fix handling of zero-length records on the rx_list · gregkh/linux@2902c3e · 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 2902c3e 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 3bcb702 commit 2902c3e Copy full SHA for 2902c3e 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 @@ -1864,6 +1864,9 @@ int decrypt_skb(struct sock *sk, struct scatterlist *sgout) 1864 1864 return tls_decrypt_sg ( sk , NULL , sgout , &amp; darg ); 1865 1865 } 1866 1866 1867 + /* All records returned from a recvmsg() call must have the same type. 1868 + * 0 is not a valid content type. Use it as &quot;no type reported, yet&quot;. 1869 + */ 1867 1870 static int tls_record_content_type ( struct msghdr * msg , struct tls_msg * tlm , 1868 1871 u8 * control ) 1869 1872 { @@ -2107,8 +2110,10 @@ int tls_sw_recvmsg(struct sock *sk, 2107 2110 if ( err &lt; 0 ) 2108 2111 goto end ; 2109 2112 2113 + /* process_rx_list() will set @control if it processed any records */ 2110 2114 copied = err ; 2111 - if ( len &lt;= copied || ( copied &amp;&amp; control != TLS_RECORD_TYPE_DATA ) || rx_more ) 2115 + if ( len &lt;= copied || rx_more || 2116 + ( control &amp;&amp; control != TLS_RECORD_TYPE_DATA )) 2112 2117 goto end ; 2113 2118 2114 2119 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. 