Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1073907lqo; Fri, 17 May 2024 09:50:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUIlY6DOJycZgX8Xk8JJOQfhp6sPC5KWT3cZYYWkCYWOR5GHxhnHM3VZ4lK46+M8Ywu111FbQl88JQQ1aKCs87hhUFJG5LbJZJI+oPTfA== X-Google-Smtp-Source: AGHT+IGv8mfbmcF5tEJ286LxX6WcteL8+X09cxJjliSX8wleQdu0BsKb2XIeVT4jNW/ba3oWjrYP X-Received: by 2002:a05:6e02:1aad:b0:36c:7eb2:50d5 with SMTP id e9e14a558f8ab-36cc149a3a6mr272781665ab.25.1715964651658; Fri, 17 May 2024 09:50:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715964651; cv=pass; d=google.com; s=arc-20160816; b=tWJL45XS9tTYNzAfSmUQD+OMqYITEsfv5wSQg8x6e4QlnoYNVEL/NuJ7UWwBGsd/ot EwzBv2cXNA++TOVkuibTk8mlU0WsLnfVpTr1P43Nl/PZdgG0jtRI20B/Ql1FfwClJQEB lllsNPYE7+Y71hD5cfuUbTq76HKnyTEz8yxeT7+nTRCbrS94IzorZyRyd2HLJxeEctMa bM0zByJN4rsFKpVqU/QyG1eRbhMSYKqoAb+w69CrIM8BrN8w4g1FIgcqFRLvDXL7BBDh 65zIPT8UzMKkCq8HB6SF7VTazOQxutcFrUSJ4g2ouAvihEVelSoBH3uNrJDRR97dib6S dAkg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=xvnTWD1cEKaVK4ivI+eYjMbuidicc56kl1oT1dQn6Kk=; fh=Pp1POxsxUPui3m0SETjijU5sVV/T/GhmG5tGLqEiZD0=; b=evlIFZcl4w2p02rALQXyTvDfv8wZ2eoF7lQMxeUIs57YTpovP1abAGeSRGiqbCeOEY XGdCtD2yV6pcC04FXaaiDc8OcFghExEJ0uJzcZyULZxXQgzjrxf3JPtwX4ymHBXAI4Gu 0IuWAzX5gs/74nNwtoDsWVsMglCof1Xjtd2aNYiu1IAHvyLBIrNI03fSKHZKIXWQX2ao K2woeZZUFqxsTautjA3eXeeB3zJMxxOIE8lfbmk+jhRG+eAkK1NLPs/AXFRLKMLQBqw7 E/XJzng5J4niD2xefwO8Q560ads2Ih38DM0wtiuOW28cdvi6NtSM+i1Deti8CIUrZNya /NUA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=uniroma2.it dmarc=pass fromdomain=uniroma2.it); spf=pass (google.com: domain of linux-kernel+bounces-182361-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182361-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=uniroma2.it Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-65c264d031csi2830874a12.0.2024.05.17.09.50.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 09:50:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182361-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=uniroma2.it dmarc=pass fromdomain=uniroma2.it); spf=pass (google.com: domain of linux-kernel+bounces-182361-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182361-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=uniroma2.it Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A5AAE285370 for ; Fri, 17 May 2024 16:50:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EF72C13D8A6; Fri, 17 May 2024 16:50:35 +0000 (UTC) Received: from smtp.uniroma2.it (smtp.uniroma2.it [160.80.6.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19AC438DD6; Fri, 17 May 2024 16:50:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=160.80.6.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715964635; cv=none; b=B5UGodzSNzuxC6LGgimx+eg3mNq1zQiok83GmBJp+zBzZdrRTPbkBmMnPlIYM0AsxrBhtCNfmEbmiYX/+GPTlkPcToHHXQv0xBAWoFIZOBTiRMNGyaDU02oIxDrR5J/+ne3cUEc64UhMg0tb3UdtVwhJceEaJ0s72fxiwc++1fY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715964635; c=relaxed/simple; bh=vMk0iJkt/6usvlUHcGZ0FKv+OTl9fcKjbBfN0zsDtHI=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=SwRyTrVCBnnhnuX5VL94DBIvdJ4jp79XiV8fOnmt4oXKhR3TWyQTnwurt7nWjlIfPr/9321gr7Mr4aHsq0vlPu+0JzoIaOCVT9+CR6M3HfZTL2q9yd7svM0EcFKe0zClhYWwndoQxvxDH30k1KhqrzpFRyuWcLvZGo04qhevUN4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniroma2.it; spf=pass smtp.mailfrom=uniroma2.it; arc=none smtp.client-ip=160.80.6.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniroma2.it Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=uniroma2.it Received: from localhost.localdomain ([160.80.103.126]) by smtp-2015.uniroma2.it (8.14.4/8.14.4/Debian-8) with ESMTP id 44HGkJN1020258 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Fri, 17 May 2024 18:46:20 +0200 From: Andrea Mayer To: "David S. Miller" , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Lebrun , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stefano Salsano , Paolo Lungaroni , Ahmed Abdelsalam , Andrea Mayer Subject: [net] ipv6: sr: fix missing sk_buff release in seg6_input_core Date: Fri, 17 May 2024 18:45:41 +0200 Message-Id: <20240517164541.17733-1-andrea.mayer@uniroma2.it> X-Mailer: git-send-email 2.20.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 X-Virus-Scanned: clamav-milter 0.100.0 at smtp-2015 X-Virus-Status: Clean The seg6_input() function is responsible for adding the SRH into a packet, delegating the operation to the seg6_input_core(). This function uses the skb_cow_head() to ensure that there is sufficient headroom in the sk_buff for accommodating the link-layer header. In the event that the skb_cow_header() function fails, the seg6_input_core() catches the error but it does not release the sk_buff, which will result in a memory leak. This issue was introduced in commit af3b5158b89d ("ipv6: sr: fix BUG due to headroom too small after SRH push") and persists even after commit 7a3f5b0de364 ("netfilter: add netfilter hooks to SRv6 data plane"), where the entire seg6_input() code was refactored to deal with netfilter hooks. The proposed patch addresses the identified memory leak by requiring the seg6_input_core() function to release the sk_buff in the event that skb_cow_head() fails. Fixes: af3b5158b89d ("ipv6: sr: fix BUG due to headroom too small after SRH push") Signed-off-by: Andrea Mayer --- net/ipv6/seg6_iptunnel.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/net/ipv6/seg6_iptunnel.c b/net/ipv6/seg6_iptunnel.c index 03b877ff4558..a75df2ec8db0 100644 --- a/net/ipv6/seg6_iptunnel.c +++ b/net/ipv6/seg6_iptunnel.c @@ -459,10 +459,8 @@ static int seg6_input_core(struct net *net, struct sock *sk, int err; err = seg6_do_srh(skb); - if (unlikely(err)) { - kfree_skb(skb); - return err; - } + if (unlikely(err)) + goto drop; slwt = seg6_lwt_lwtunnel(orig_dst->lwtstate); @@ -486,7 +484,7 @@ static int seg6_input_core(struct net *net, struct sock *sk, err = skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev)); if (unlikely(err)) - return err; + goto drop; if (static_branch_unlikely(&nf_hooks_lwtunnel_enabled)) return NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT, @@ -494,6 +492,9 @@ static int seg6_input_core(struct net *net, struct sock *sk, skb_dst(skb)->dev, seg6_input_finish); return seg6_input_finish(dev_net(skb->dev), NULL, skb); +drop: + kfree_skb(skb); + return err; } static int seg6_input_nf(struct sk_buff *skb) -- 2.20.1