From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 85CF1198E9C; Thu, 6 Jun 2024 14:18:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717683515; cv=none; b=lqI2XDbVk7bQsHWP9bc8G15K3j2mEU1aFUJaskeA8o9LInQggY8yFkHODDlJHa/0VlFuySpAJ5KpFqEg0rc0k96wrzeKjFQjuQABe3CmEgF9GFgImMriT3DSvlafoVTGEW35dUNIKcsmVD2/F5kT+gEkoplAFUwYlct5BpfrsUA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717683515; c=relaxed/simple; bh=Q/qc3JfqahrJy4pjgfAaWeXQojMauVVgUIcqjZ4ZQzw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DNjRerCVqCNIQauhNesh9CohxkV8qq5vsIQ7MeByCL+cfRgdcC5jhQ0F5wYz9UsRh117/kr6LbL0Gl8k5KmiUyoTEyW5d+pD1RmP/SBsu+V4eCUFGdYfiVizdYwY7bTtY8Xrid+eTNFntZoijoLPlEPPVcu/ZivrFg8dRYZ3rAg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=CnxpKqZ1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="CnxpKqZ1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A10CC32781; Thu, 6 Jun 2024 14:18:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1717683515; bh=Q/qc3JfqahrJy4pjgfAaWeXQojMauVVgUIcqjZ4ZQzw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CnxpKqZ17nE8HNC/cj8LydCCbc3elYGuLXmTzp/GiogcCOLLUf804/JnG9JCVjzwZ SuZNMIPbCPPq8s/MxKCYN/84bqGofbvQVEmLNQJQ8KBmlPVAy4GBpRCwtgLnzATuAz gOZBfCyiDBQt0o9XNyNKVqF7FCqKaCH7Hv2G6Un4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Andrea Mayer , Simon Horman , David Ahern , "David S. Miller" , Sasha Levin Subject: [PATCH 6.1 403/473] ipv6: sr: fix missing sk_buff release in seg6_input_core Date: Thu, 6 Jun 2024 16:05:32 +0200 Message-ID: <20240606131713.139691271@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240606131659.786180261@linuxfoundation.org> References: <20240606131659.786180261@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andrea Mayer [ Upstream commit 5447f9708d9e4c17a647b16a9cb29e9e02820bd9 ] 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 Reviewed-by: Simon Horman Reviewed-by: David Ahern Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- 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 34db881204d24..5924407b87b07 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); @@ -487,7 +485,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, @@ -495,6 +493,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.43.0