 nvme-tcp: fix NULL pointer dereferences in nvmet_tcp_build_pdu_iovec · gregkh/linux@7d75570 · 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 7d75570 Browse files Browse files shivam-2315 authored and gregkh committed nvme-tcp: fix NULL pointer dereferences in nvmet_tcp_build_pdu_iovec [ Upstream commit 32b63ac ] Commit efa5630 ("nvmet-tcp: Fix a kernel panic when host sends an invalid H2C PDU length") added ttag bounds checking and data_offset validation in nvmet_tcp_handle_h2c_data_pdu(), but it did not validate whether the command's data structures (cmd-&gt;req.sg and cmd-&gt;iov) have been properly initialized before processing H2C_DATA PDUs. The nvmet_tcp_build_pdu_iovec() function dereferences these pointers without NULL checks. This can be triggered by sending H2C_DATA PDU immediately after the ICREQ/ICRESP handshake, before sending a CONNECT command or NVMe write command. Attack vectors that trigger NULL pointer dereferences: 1. H2C_DATA PDU sent before CONNECT → both pointers NULL 2. H2C_DATA PDU for READ command → cmd-&gt;req.sg allocated, cmd-&gt;iov NULL 3. H2C_DATA PDU for uninitialized command slot → both pointers NULL The fix validates both cmd-&gt;req.sg and cmd-&gt;iov before calling nvmet_tcp_build_pdu_iovec(). Both checks are required because: - Uninitialized commands: both NULL - READ commands: cmd-&gt;req.sg allocated, cmd-&gt;iov NULL - WRITE commands: both allocated Fixes: efa5630 ("nvmet-tcp: Fix a kernel panic when host sends an invalid H2C PDU length") Reviewed-by: Sagi Grimberg &lt;sagi@grimberg.me&gt; Signed-off-by: Shivam Kumar &lt;kumar.shivam43666@gmail.com&gt; Signed-off-by: Keith Busch &lt;kbusch@kernel.org&gt; Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt; 1 parent 95f81cd commit 7d75570 Copy full SHA for 7d75570 1 file changed + 12 Lines changed: 12 additions &amp; 0 deletions File tree Expand file tree Collapse file tree Open diff view settings Filter options drivers/nvme/target tcp.c Expand file tree Collapse file tree Open diff view settings Collapse file ‎ drivers/nvme/target/tcp.c ‎ Copy file name to clipboard Expand all lines: drivers/nvme/target/tcp.c + 12 Lines changed: 12 additions &amp; 0 deletions Original file line number Diff line number Diff line change @@ -956,6 +956,18 @@ static int nvmet_tcp_handle_h2c_data_pdu(struct nvmet_tcp_queue *queue) 956 956 pr_err ( &quot;H2CData PDU len %u is invalid\n&quot; , cmd -&gt; pdu_len ); 957 957 goto err_proto ; 958 958 } 959 + /* 960 + * Ensure command data structures are initialized. We must check both 961 + * cmd-&gt;req.sg and cmd-&gt;iov because they can have different NULL states: 962 + * - Uninitialized commands: both NULL 963 + * - READ commands: cmd-&gt;req.sg allocated, cmd-&gt;iov NULL 964 + * - WRITE commands: both allocated 965 + */ 966 + if ( unlikely (! cmd -&gt; req . sg || ! cmd -&gt; iov )) { 967 + pr_err ( &quot;queue %d: H2CData PDU received for invalid command state (ttag %u)\n&quot; , 968 + queue -&gt; idx , data -&gt; ttag ); 969 + goto err_proto ; 970 + } 959 971 cmd -&gt; pdu_recv = 0 ; 960 972 nvmet_tcp_build_pdu_iovec ( cmd ); 961 973 queue -&gt; cmd = cmd ; 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. 