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 3BB5C25F783; Tue, 11 Mar 2025 15:33:39 +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=1741707219; cv=none; b=rr3993ynPNp8PykMBKLWerc5RH49dz0QhkWdcm+pfgkzv3NWqXk3Y2mSArCjtwjAM0pJPNr2pOcXB3e8v+x/IfajsClYaUb8xIjf5L/fmzJFlAPTKwfHZGfTdsPAxLFCloj4Mo1OMRYtdDcZi8sXgmJjTG7Vy1gCsRrTVtM2wPY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741707219; c=relaxed/simple; bh=o0CFUJTMSprhiUdm1hcR8XiLrd5UVSeav+Yp9HPt6x4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E19cLYOjct894S5am+sDlWYKDIfxcXL2WFua8zpQrEo97AHk+5DF0hJRcgG6wlZFG4ddc0NZKgRR7WRZJNSF2bofD5R7T+NvSYrjNMV9dDCLh6XWOOHP7/A+wUI+T/4dZx0S/nyuuqG4eDdsCHW5KjZ9bc9fp2b3ix14KdYdEBU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=C9eqtBRd; 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="C9eqtBRd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BAC27C4CEE9; Tue, 11 Mar 2025 15:33:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1741707219; bh=o0CFUJTMSprhiUdm1hcR8XiLrd5UVSeav+Yp9HPt6x4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C9eqtBRdOZbmel7QWu71/4Ur80+3y/fm5EZX9+kjQA6yhjMapsLKhj2EgBuIuH1ue 76i6Z1JrAoYneIuSBXdGPyJROhT6hkAU2w7apKZeHQUPLgBQwv2zK4BNnJyTPlb3hh IqTbcb2pOyKd1Zf7TNJxaZAAlX/gfqJKmunktzco= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Eric Dumazet , David Ahern , Kuniyuki Iwashima , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.10 284/462] ndisc: use RCU protection in ndisc_alloc_skb() Date: Tue, 11 Mar 2025 15:59:10 +0100 Message-ID: <20250311145809.592441600@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250311145758.343076290@linuxfoundation.org> References: <20250311145758.343076290@linuxfoundation.org> User-Agent: quilt/0.68 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 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet [ Upstream commit 628e6d18930bbd21f2d4562228afe27694f66da9 ] ndisc_alloc_skb() can be called without RTNL or RCU being held. Add RCU protection to avoid possible UAF. Fixes: de09334b9326 ("ndisc: Introduce ndisc_alloc_skb() helper.") Signed-off-by: Eric Dumazet Reviewed-by: David Ahern Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20250207135841.1948589-3-edumazet@google.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/ipv6/ndisc.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index c0a5552733177..2361f4af49e8f 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -417,15 +417,11 @@ static struct sk_buff *ndisc_alloc_skb(struct net_device *dev, { int hlen = LL_RESERVED_SPACE(dev); int tlen = dev->needed_tailroom; - struct sock *sk = dev_net(dev)->ipv6.ndisc_sk; struct sk_buff *skb; skb = alloc_skb(hlen + sizeof(struct ipv6hdr) + len + tlen, GFP_ATOMIC); - if (!skb) { - ND_PRINTK(0, err, "ndisc: %s failed to allocate an skb\n", - __func__); + if (!skb) return NULL; - } skb->protocol = htons(ETH_P_IPV6); skb->dev = dev; @@ -436,7 +432,9 @@ static struct sk_buff *ndisc_alloc_skb(struct net_device *dev, /* Manually assign socket ownership as we avoid calling * sock_alloc_send_pskb() to bypass wmem buffer limits */ - skb_set_owner_w(skb, sk); + rcu_read_lock(); + skb_set_owner_w(skb, dev_net_rcu(dev)->ipv6.ndisc_sk); + rcu_read_unlock(); return skb; } -- 2.39.5