From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33BBE3DBD7C for ; Mon, 4 May 2026 15:27:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777908453; cv=none; b=XHklRjyI3x1E7IxeFztoXp3Gc+wUydLYvd6yjKD4lQ648bgxzL1rCoVaWmJvPFtR4bI0zn/07TTh0HJLldP6kEQh0XIQqpk0wHMtIhNVl8DCEw7l66P79Ej6E41rwRCOxB0hK+I2BuFBVAZm+fP0bgi0C0qRKZzqDugD/5RYXO4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777908453; c=relaxed/simple; bh=hO+zym3mTv4R/jUftjLR4dlYFUKwiMbLkRn34MxFFe4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=RMKbrLsqIaO/GQs1PfcDnz7R0UP3yt99zWmiX5kaHu1YVsoBSAb5JBIsiqVrgRwMFbmXhcil3uLlrKFIExqPNwv1OEOkOyz4SceezefLtXkrASTNEHnzV6+wBFtseMOUvpWZPtZaYAC8SUJ5ty6EB14hKiHDefSyRqenY9H/cmA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WC1pNmR9; arc=none smtp.client-ip=209.85.215.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WC1pNmR9" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-c80170db7d6so585397a12.0 for ; Mon, 04 May 2026 08:27:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777908450; x=1778513250; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=PZjvTocBotG8D32T0Fa7dku0HsteTt04rb/ig51a7Kg=; b=WC1pNmR9RX5SB5Z3qgYn452e62E+X9OcyDvBz9IWVAGK5znktMG5PUVVOs2Sx4GPjS qDdrudwDdUTu4sck6bRobYEwXp1gehgnajwnY5x6F72Vm6rfhqWpq+xG7HWw4Bgjs1XE Nh9k8AbvfgUeacEx+VcYPk7eq3jli+lZPvj0iUUFESVe5QAyStk47ku7pgvjTNDjVGi1 kVvvVJeiL3OM9bEj0E8X+UKrRVfXkSGkXFM65sxGyAOYM1c5CLBqcbn8YiFR6ivO8XQi XW9O4nvU312o7Dh5djOWluPDyU515L7S04fIDdOKlNO++t6SeLSFD/cyCXzCgxyZVWrs Vi8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777908450; x=1778513250; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=PZjvTocBotG8D32T0Fa7dku0HsteTt04rb/ig51a7Kg=; b=cmj6dcgmna/vjPZ2zs54kOMeT+PYAfEDi25NBQrIDGEVTXtVHpdUjjr8lntEcJ6A/k 3G5Wf5eaW8Cm5dxIPbm3oNI/3pXbF4ixp5SnHcppr/WmFvl/ur3UCVYnV8zAfbyQzDbz jtaFfOMUallFoqAgq65kVGv79mAwaW9ccjbS1ffPEz9U2PCe5T/kkzjkaTDhnQnO8Fp8 B8ZUUAOXC+GpYphF0JsV+8XsXcL7sv+CvB/poZFFmOzv/UyBsxMP7dyKiZtBKHGhslAU cGY+3uHd9KPtQRCzPa1GxA0b3qL1qfBuJZYVY/kgIgFYLFG6pQE764eLy7swmERiRgrg nijA== X-Forwarded-Encrypted: i=1; AFNElJ/q3kvpiCpdBUsWFEmakqSGL0O2JxBBpOfvb1ML/4gjPEqnUOP5YCpSZ6zVyFV9gVhu2gbAwDHN3CcmjV8=@vger.kernel.org X-Gm-Message-State: AOJu0YyL0JxoBLK+7/fpBlWXw0K6H9XEKngJ4ta46286qmLlIj+BHEFW CdwrSqil+D+HbYz55mrDOswtXktbJsOPe6ARWgsz66bHubiyfWfDpVrN X-Gm-Gg: AeBDievs3IqVb7ICrLxfwpPH/tyriAFEuUeUDZUXLrlSumn0PGxuGWFoSkl664yu3U3 zYI33br1YEgh3+FLwDYCXEgbHELgCFYLyjXQhyhfZASd+5DsudctKmZXpWcsh0b0PhVC52hXwrR 61SOPLtlVxhwq986HbB125CzZkeqtYA4wFmZe5FpV0soMSZBV8hJ8NahlA2SoKMhIkyzeW+0P4T dtBT/cq8HhJaNI80JlXVfewEXJpDQfUPYBnNL1dQkh7zUmhlV8kkjXtLeMb4/7S5j+uu7ywLoR5 /V6cJjWAE94JP14DagmgusQRlwxeXLNXQ//8vTFZUO/H9mTdUGOkYyKsUAiX34RjBWdpuSA1Lzc wkRZJqWziwLcoUpT3GvwsBomNKLhlZrTQ/I2e32JIjjTDMryUhzZGM3KBdnr73Zq/UK+7KbJLEn qadP3KcSpOcE+eVo6zmNafmXmEZ3dG/jK0988j3aLrZMjMnE8h8wCH/oz+EWq3HJLJN4SYZu958 IXarblc/2iF/lo8WeYpiBooM+YG X-Received: by 2002:a05:6300:48:b0:3a3:c6df:7239 with SMTP id adf61e73a8af0-3a7f1ad0724mr10192618637.10.1777908450288; Mon, 04 May 2026 08:27:30 -0700 (PDT) Received: from localhost.localdomain (114-45-143-162.dynamic-ip.hinet.net. [114.45.143.162]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c7ffbbbd313sm9924766a12.12.2026.05.04.08.27.26 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 04 May 2026 08:27:29 -0700 (PDT) From: HexRabbit To: netdev@vger.kernel.org Cc: Steffen Klassert , Greg Kroah-Hartman , Herbert Xu , Simon Horman , "David S . Miller" , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Ido Schimmel , Hyunwoo Kim , linux-kernel@vger.kernel.org, Kuan-Ting Chen , stable@vger.kernel.org Subject: [PATCH net v2] xfrm: esp: avoid in-place decrypt on shared skb frags Date: Mon, 4 May 2026 23:27:12 +0800 Message-ID: <20260504152712.76305-1-h3xrabbit@gmail.com> X-Mailer: git-send-email 2.50.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Kuan-Ting Chen MSG_SPLICE_PAGES can attach pages from a pipe directly to an skb. TCP marks such skbs with SKBFL_SHARED_FRAG after skb_splice_from_iter(), so later paths that may modify packet data can first make a private copy. The IPv4/IPv6 datagram append paths did not set this flag when splicing pages into UDP skbs. That leaves an ESP-in-UDP packet made from shared pipe pages looking like an ordinary uncloned nonlinear skb. ESP input then takes the no-COW fast path for uncloned skbs without a frag_list and decrypts in place over data that is not owned privately by the skb. Mark IPv4/IPv6 datagram splice frags with SKBFL_SHARED_FRAG, matching TCP. Also make ESP input fall back to skb_cow_data() when the flag is present, so ESP does not decrypt externally backed frags in place. Private nonlinear skb frags still use the existing fast path. This intentionally does not change ESP output. In esp_output_head(), the path that appends the ESP trailer to existing skb tailroom without calling skb_cow_data() is not reachable for nonlinear skbs: skb_tailroom() returns zero when skb->data_len is nonzero, while ESP tailen is positive. Thus ESP output will either use the separate destination-frag path or fall back to skb_cow_data(). Fixes: cac2661c53f3 ("esp4: Avoid skb_cow_data whenever possible") Fixes: 03e2a30f6a27 ("esp6: Avoid skb_cow_data whenever possible") Fixes: 7da0dde68486 ("ip, udp: Support MSG_SPLICE_PAGES") Fixes: 6d8192bd69bb ("ip6, udp6: Support MSG_SPLICE_PAGES") Reported-by: Hyunwoo Kim Reported-by: Kuan-Ting Chen Cc: stable@vger.kernel.org Signed-off-by: Kuan-Ting Chen --- v2: - Add Fixes tags - Add stable Cc and Reported-by trailers. net/ipv4/esp4.c | 3 ++- net/ipv4/ip_output.c | 2 ++ net/ipv6/esp6.c | 3 ++- net/ipv6/ip6_output.c | 2 ++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c index 6dfc0bcde..6a5febbdb 100644 --- a/net/ipv4/esp4.c +++ b/net/ipv4/esp4.c @@ -873,7 +873,8 @@ static int esp_input(struct xfrm_state *x, struct sk_buff *skb) nfrags = 1; goto skip_cow; - } else if (!skb_has_frag_list(skb)) { + } else if (!skb_has_frag_list(skb) && + !skb_has_shared_frag(skb)) { nfrags = skb_shinfo(skb)->nr_frags; nfrags++; diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index e4790cc7b..5bcd73cbd 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -1233,6 +1233,8 @@ static int __ip_append_data(struct sock *sk, if (err < 0) goto error; copy = err; + if (!(flags & MSG_NO_SHARED_FRAGS)) + skb_shinfo(skb)->flags |= SKBFL_SHARED_FRAG; wmem_alloc_delta += copy; } else if (!zc) { int i = skb_shinfo(skb)->nr_frags; diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c index 9f7531373..9c06c5a14 100644 --- a/net/ipv6/esp6.c +++ b/net/ipv6/esp6.c @@ -915,7 +915,8 @@ static int esp6_input(struct xfrm_state *x, struct sk_buff *skb) nfrags = 1; goto skip_cow; - } else if (!skb_has_frag_list(skb)) { + } else if (!skb_has_frag_list(skb) && + !skb_has_shared_frag(skb)) { nfrags = skb_shinfo(skb)->nr_frags; nfrags++; diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 7e92909ab..1f2a33fbe 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -1794,6 +1794,8 @@ static int __ip6_append_data(struct sock *sk, if (err < 0) goto error; copy = err; + if (!(flags & MSG_NO_SHARED_FRAGS)) + skb_shinfo(skb)->flags |= SKBFL_SHARED_FRAG; wmem_alloc_delta += copy; } else if (!zc) { int i = skb_shinfo(skb)->nr_frags; -- 2.43.0