From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 12F623815FE for ; Thu, 14 May 2026 09:42:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778751754; cv=none; b=SUbt1ThXuasreO2Ku4hMmvGUL+23eac98H4N8KFEgLyDp/qp3U8ksi0F89al3oPb2HPQMoJqx1yqVAcZERh9bCKA1rQUJrwyzAX9Q6ImIoPavQpq+QRKI/IWnOLnCYbXVzYZi7aMpos3Hy3Zj1xeD+REhGBYuvDPDPQD8GkuWQ0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778751754; c=relaxed/simple; bh=rQs/D4qYJck2kIgPhiZZ3Fg/5QkATjQrK5UVoTLqQHQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=J/3AKPiaGMfbbAuJ+FCCd/7YTWMOz1YzBkUHUd/Mjr2Cac6YiqRz3rwSjDtfNlh+9/5uOyfiGli3SvN/gKOHJJu/YYkvcthTQVEcVObKrgaiVmM42FbeRubEeTbhoCGfKpxubmKsj63Q+KKmUIyYXxK+5ABj+vbUenirDjY8YS0= 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=rMWt8wDo; arc=none smtp.client-ip=209.85.128.49 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="rMWt8wDo" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-488af96f6b2so91801645e9.0 for ; Thu, 14 May 2026 02:42:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778751751; x=1779356551; 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=RU5N7TG/2oOJFFJ1rhjydLyb1X8rOImh10nKex9OxhY=; b=rMWt8wDoEr/QWctj/Krh95UsJ5Q4Y6MMKQ88WpaS/TSNpsMJbbAamYfHYDPOLXekVG lahDH0ZZGlXECbgNizASF5dGaHXeiG9Yva+msOgv6wUFipIUfulI1ZW6fclw0UadVlpR ayVe7ndKBt9X4FzSpCHbVSDfmcWhgJtd+RGI6Y3+SddHijMoecLs39zDIR+PCeXRdQzY HIDfr7me5Y0SCzcLrrIh/KtjffGgl4u/QCECCwtTdhomWBqpHUNbRzfD/XEdk+T4e1n5 Ecpw3RQMT3dl6Dy13SVOahoPZ4by9AOQAhW27QvkAdvTip0UVUX+AF9qNn8yrw8HorIz GuXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778751751; x=1779356551; 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=RU5N7TG/2oOJFFJ1rhjydLyb1X8rOImh10nKex9OxhY=; b=dpjH5hg+v5fc3nCiHhxZPjIKFbal2jlIaNkLB1UHkUVfsj7sBVg9MrehY54uOVv0Lh RG6FPY26IIYhnDQSz2ff0wtwX2o0kZavOEaO+jv7MQ9mO/+uXxhc4zA6z2b1Cwq7vI6Q +B94ezoa+JPkz5FcOqySG7hZ2agNWmovLxpDvvNgiowNWJZF2TNbFdX19JUHrWiyuqtv RmwnxHeDTnrj/+3OcBiHcHNFV/vROeJIUDIA88R/js2QPiy6nWm5TZonasTlINVNFIkI QLupW69N6aYOdcLm7sIwtQat/mOFMtT8fTaug+f51wpfUzfyrLJcRLk4ByG2tg9HBNWj CVWQ== X-Forwarded-Encrypted: i=1; AFNElJ94ENDycLiSd401jl9/REumSk5O/ARmvmWWbJ20aDythDe/su2mv+q7n2zYp3lAOaE3jG+0+g3wlu1Hh/s=@vger.kernel.org X-Gm-Message-State: AOJu0YxeJF/jj+PLtSpqcRT/+8JG+5k+FTnWkZkxabaryCuQAbMutVJ/ EyarGPvJaP9VH4IoDtUhLivNtlyRYq4p14SyLi4IDv2p2eBk5JQQmsh7 X-Gm-Gg: Acq92OGyCIle2ECiL1CPfkpVguI4uN0ePwS9nNHcvr+rI+Hyl4vREzqU+Zsc0ln8aKk Kinrkge6KeSK+WXP660GjR1i009+LaiyBsmLRd0ByjRYXEpgbSW26EuGG9S+8J+lUGXB0JxG6mO P5ipxtUKXFELLpnAjyjVjkhKXfUUG0DfXA7cEY+hjKaFO1j3Cia/VX5YV5KBAkU4vQQaOSbqSeG KPy4NtfM81r9b+XA31jSIUTorNkkPRzWT0PkiP657/0bssuQ8JJQZ7Y18KZy+ruCdD0hVtq3tx+ UMOmOHnBNf5uqYb9WixXN0wpDUZx2CZen/2FDc0gB1nC3wRN3lfE0edMvfdg772YPfVwuwo8Hk6 WejGJE+0u/LseLwza71cO8OVc8QVVuJlvFEQJCp+LhpXIDyBbQj8A1dBH8c3LxjPW6tqCDiw9TO 8yzy3si/1FQuHp85YFlaJLA+lCqWl4tKsjerbSekm4i6p4niMqkt6FAojhjl9J7sWa50EOZLtZf xmsRUc= X-Received: by 2002:a05:600c:698d:b0:48a:7676:30bc with SMTP id 5b1f17b1804b1-48fc9a31279mr112949385e9.14.1778751751255; Thu, 14 May 2026 02:42:31 -0700 (PDT) Received: from localhost.localdomain ([2a01:827:3b28:500:b184:4b99:e746:532b]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48fd648d3a5sm51654735e9.2.2026.05.14.02.42.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2026 02:42:30 -0700 (PDT) From: Alessandro Schino <7991aleschino@gmail.com> To: netdev@vger.kernel.org Cc: steffen.klassert@secunet.com, herbert@gondor.apana.org.au, davem@davemloft.net, linux-kernel@vger.kernel.org, e521588 , Alessandro Schino <7991aleschino@gmail.com> Subject: [PATCH] esp: fix page frag reference leak on skb_to_sgvec failure Date: Thu, 14 May 2026 11:42:11 +0200 Message-ID: <20260514094212.32-1-7991aleschino@gmail.com> X-Mailer: git-send-email 2.41.0.windows.3 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: e521588 In esp_output_tail(), when esp->inplace is false, the old skb page frags are replaced with a new page from the xfrm page_frag cache. The source scatterlist (sg) is built from the old frags before the replacement, and esp_ssg_unref() is responsible for releasing the old page references after the crypto operation completes. However, if the second skb_to_sgvec() call (which builds the destination scatterlist from the new page) fails, the code jumps to error_free which only calls kfree(tmp). The old page frag references captured in the source scatterlist are never released: 1. sg[] is built from old frags via skb_to_sgvec() (no extra get_page) 2. nr_frags is set to 1 and frag[0] is replaced with the new page 3. Second skb_to_sgvec() fails -> goto error_free 4. kfree(tmp) frees the sg[] memory but old frags are not unref'd 5. kfree_skb() only releases frag[0] (the new page), not the old ones Fix this by calling esp_ssg_unref() before the goto error_free when the second skb_to_sgvec() fails. At this point, the source scatterlist in tmp is fully populated, so esp_ssg_unref() can properly release all old page frag references. The same issue exists in both esp4 and esp6 as the code is identical. Fixes: cac2661c53f3 ("esp4: Avoid skb_cow_data whenever possible") Fixes: 03e2a30f6a27 ("esp6: Avoid skb_cow_data whenever possible") Signed-off-by: Alessandro Schino <7991aleschino@gmail.com> --- net/ipv4/esp4.c | 4 +++- net/ipv6/esp6.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c index 6a5febbdbee4..5c4b162c1bb5 100644 --- a/net/ipv4/esp4.c +++ b/net/ipv4/esp4.c @@ -569,8 +569,10 @@ int esp_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info * err = skb_to_sgvec(skb, dsg, (unsigned char *)esph - skb->data, assoclen + ivlen + esp->clen + alen); - if (unlikely(err < 0)) + if (unlikely(err < 0)) { + esp_ssg_unref(x, tmp, skb); goto error_free; + } } if ((x->props.flags & XFRM_STATE_ESN)) diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c index 9c06c5a1419d..9166e1da3615 100644 --- a/net/ipv6/esp6.c +++ b/net/ipv6/esp6.c @@ -600,8 +600,10 @@ int esp6_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info err = skb_to_sgvec(skb, dsg, (unsigned char *)esph - skb->data, assoclen + ivlen + esp->clen + alen); - if (unlikely(err < 0)) + if (unlikely(err < 0)) { + esp_ssg_unref(x, tmp, skb); goto error_free; + } } if ((x->props.flags & XFRM_STATE_ESN)) -- 2.41.0.windows.3