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 1A13D22576A; Mon, 10 Mar 2025 18:13:49 +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=1741630430; cv=none; b=Jlr2M5zj/9qt2KXG9AI4Zu4c62PgP9og482CgASPr+WGYLZqNOx6RIkUYNIXwI4zld3Q4QOhUf0xaHraESPt+kSGOhhSi7hM9neH56mxmiSjPLSPQ8pEXTedj5xcgY77eICFv5uIF4qP3ywL5KbQBoP9lUpNAA0PQdFXaTvIcMo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741630430; c=relaxed/simple; bh=f4bcPVqlQBKz4t+nHpapg4tPpqFDAAaL5VBaXEJYEIQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=heNOnx9QPgPhbIxlupQm/JPdv4B37nNfk66XcB5MDKY7OwD2WZ1dekbuA2rtB/113m4rgtWaCGuG3X3e36tBqn/0V2bsxLlKMzVsvRSh8E2+apVzV41gNuhz0bohY8+EuelM5j85cKgoh2+Mcc5w89W64fFg+WlHGXzBhOkADW0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=jUrfMSjL; 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="jUrfMSjL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42024C4CEE5; Mon, 10 Mar 2025 18:13:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1741630429; bh=f4bcPVqlQBKz4t+nHpapg4tPpqFDAAaL5VBaXEJYEIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jUrfMSjLUgvVJ/fxEYMfPQFufoKugveQor2RK9NddRZiQhra3Ouvg8zD+3ubGhvHJ i3fBLzdL7H6/8FOKJtZkgzKUboVpHqPII4ngLAB2VjiCYjkdPgAJKBOqtnUUMlc1kW qJ+ZKwygu+vN49XYiFqcYLku3ditv7+KpKFC3Oy4= 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.15 403/620] ndisc: use RCU protection in ndisc_alloc_skb() Date: Mon, 10 Mar 2025 18:04:09 +0100 Message-ID: <20250310170601.499605257@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250310170545.553361750@linuxfoundation.org> References: <20250310170545.553361750@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.15-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 63c1420c58249..3972189c09b14 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