From nobody Fri Jun 12 15:49:08 2026 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 213143D8108 for ; Thu, 14 May 2026 08:11:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778746307; cv=none; b=ewKPR10wq2wRwCacw2DUcmuP01c+CzCxJJ7Z5z23rxaafN5fi81bjwiECqEZEg8W0tgaX1Zy0IYt5/jpjK3I/tsdQow6etERVJY+d+zNAqYVPonPUz0Mos0yuaL0L7rMQSvblJ+UP+IgRgNG17YQ+EQ/n+69AMxfLJN/b8c9Puo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778746307; c=relaxed/simple; bh=kkPDxk7OQpWCY/y7s9Mr8zrhCCBIgHaHwNxYTwv1mXw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Fc+uArOcZDXxBUqDhuZkaIAGNP9mm1v/vhO0luE0W2GbECfbPiBRU+/aFWBVPt7ClCqJ9BjxmkwdSjkgxNtF1wePWkbasaTJNZMXyWz+hlN4Imngij4b3y3YdsHpEc2NH/V3aNPYff+JnF8JS5+gt48ehLfqT9Qbs9HJLc6ETUA= 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=PHauOMU+; arc=none smtp.client-ip=209.85.128.48 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="PHauOMU+" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-48909558b3aso74621735e9.0 for ; Thu, 14 May 2026 01:11:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778746304; x=1779351104; 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=FI+vW5VUqDX/h/2J5DFaTVeCzdVFXEjt4d+lYVo7VXU=; b=PHauOMU+Wx9DmMX/nkPi2Tt/ccsmQgPVIQaESeztbhyE97mCIa1OdzwNaPOn9VbHES BcoeRxZMTfXB5sexZV3cT4Hel3z5np30qflVocnKPE5Mvn6y1CaQr+rjN+vuQWmhDREE YL7BLDQ3zkPbNVlpOj1ZL8rTqhRRVl2Exe+gBYBIgwpJcj5cwa3VLWk30N8d6CEzjAzh MlGhmCI29n+ZTU7RvqIpMXQWhkvwu/4C212HEBaLgbzGGPAYyHUUZS5uvMmRxsoHYLL5 Ce3Kfre4Ruuq+fbFFE6Z7O/MYC8WpcZVNr71l+X2MXHOU3AhJ//BLS5Dsjy+rS5MiPhA oMfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778746304; x=1779351104; 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=FI+vW5VUqDX/h/2J5DFaTVeCzdVFXEjt4d+lYVo7VXU=; b=HGK8ezSeagESXQoAcZGrFQqADGbDlz++0DjJe/gwjOX8nxhRxZijoGzQXGaATFfY+Q FbusRhFPwR45UFYgCR+ZIjag6jPLvQmWiWHBpF1VTqZ7PpoZVq5SaSd3VpSLrb1OEDc7 9KJYwowB5SmIAbGd9bcGYGz2FiZp3B4D4eznW2oFXDponQOVPXeccczQpf2qpbo4/aOA RrlAtRO2O38L9Ji1IOKny/7p3E0wv6UJBohc6olclCW6N30VxnyCv6NLkwlcOclrQLjW Cbr/KJ50PwkbHVaoz1uyD3dt/d/BotzrbWTtTr33zfuQCHRp+5evem6f/WJTGq0Gg8bL Znaw== X-Forwarded-Encrypted: i=1; AFNElJ9DLEh+Rqh4g27p7cJi5UjLoQE5uzjJXHuNcndrT/a23nvYuW0jE05goAZzd/41o+zExii3anZx+9K0eSU=@vger.kernel.org X-Gm-Message-State: AOJu0Yx3xS2cQ0aX4X4EuR2p83urGZ8TRu1GrkJuiMl3JTUOCJ0eym4x KkWOlXIMr4wTvo5G15woWVLcQcXtEm/dEuhiuGtxSGKuwrtMpqy4pHty X-Gm-Gg: Acq92OGla3pa2FJNMz5FOZoFQ/jDLSYxbos3wK1KtIbuJpd1ge59qLaX63+A9W8+4yT pORCpqHj7riAg+2z1p10/JP6uZOpZvWnLq9ryWnkC2RTe5xF534qB0PGCn14ClKyB3JSlYUXnIo uh6uEE8zlYh9ZDAWULPY9KLxiAWGV7pgSq9eYNVa8S6oear1KUhalne5TKOCWSfO5SzjC3Piyl5 z3JOtOVpY6zIFX0FYuZHr82GzC9VL6HFoFF1ce+VyTum48ggk6MHmrryahYlkxwCeQI7dq9hwrg FVJ7opz6ZieEjDKfDQqa+DLi20dakiacU98RTtMxTha3JwFE8P/4qTRTVy3PiiDrh8G8HZFSatR 4iFnnc351ThkIm7WvoEJ+kb3NOVO4d+xubytO5DHdG6J2iXBMVAjEkY2PAdP9P2Lu9CKN0v2muO 3KI4eT2PBGgI8beeDfJR7QZny832mW5lv/MUenWYh1c3cxnO7wgjUlFVyV9KqDKl1tepOLCfo0N pNwjRU= X-Received: by 2002:a05:600c:5246:b0:485:4388:3492 with SMTP id 5b1f17b1804b1-48fce9cf9a5mr99561185e9.11.1778746304359; Thu, 14 May 2026 01:11:44 -0700 (PDT) Received: from localhost.localdomain ([2a01:827:3b28:500:4954:471e:9dc7:7f18]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48fdb278ad3sm43069565e9.8.2026.05.14.01.11.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2026 01:11:43 -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 10:11:23 +0200 Message-ID: <20260514081123.1626-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: quoted-printable Content-Type: text/plain; charset="utf-8" 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. 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_bu= ff *skb, struct esp_info * err =3D 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; + } } =20 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_b= uff *skb, struct esp_info err =3D 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; + } } =20 if ((x->props.flags & XFRM_STATE_ESN)) --=20 2.41.0.windows.3