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 DEBBA17592; Tue, 30 Apr 2024 11:23:19 +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=1714476200; cv=none; b=GR5bQAQeIodL0Xq1ubik1SgeGRjpF2gjZodEOvDmV3czfH68wHISV30bDxrj3AOBurpEp3/kArur0vpLDYXPum2MT/qUfq095Im89CGZxsnNnKjahhvWcU9mm+yjByje+WOhvcTmN9+4yn9qZjYtwoYsUF8/9VxX7XurSm8q5GE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714476200; c=relaxed/simple; bh=TYePNH1LP027FHcNmpkEob3HnpyGgnA21/XKqGu8kRw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jw2+inTEmsq4JxGTin5eKfFOjnOYO6IWlWPQ8bGgQ/mlWIA3Kcq+6N3LqULXVeJiGd17LVc7O7mK6VXd24wxE4GqBH4t78KqvdZe627+L12aownejrmuMGdLe2DQKExY3WTk9KFNuVRadH6TTar9iTzkgP4Nn4nMbTxoKLr39FE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=wqT7YCol; 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="wqT7YCol" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63F5AC2BBFC; Tue, 30 Apr 2024 11:23:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1714476199; bh=TYePNH1LP027FHcNmpkEob3HnpyGgnA21/XKqGu8kRw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wqT7YColMzfhQjIczcrUh6vUssWH9+PUU0PrGoozeIyWEfS3/26Oly0dJhyQm6tmC C6MklUBxM/2iKc82KOS2bjL+zSHa0pnDuWHltYCC55tWKTYSFnLn/J6RzQb6LUTddu W41pnjkdRv5T2KcHGFQ36+UXJrsnE+XS0J3weBbQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Hyunwoo Kim , Eric Dumazet , "David S. Miller" , Sasha Levin Subject: [PATCH 5.4 065/107] net: gtp: Fix Use-After-Free in gtp_dellink Date: Tue, 30 Apr 2024 12:40:25 +0200 Message-ID: <20240430103046.574716495@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430103044.655968143@linuxfoundation.org> References: <20240430103044.655968143@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 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Hyunwoo Kim [ Upstream commit f2a904107ee2b647bb7794a1a82b67740d7c8a64 ] Since call_rcu, which is called in the hlist_for_each_entry_rcu traversal of gtp_dellink, is not part of the RCU read critical section, it is possible that the RCU grace period will pass during the traversal and the key will be free. To prevent this, it should be changed to hlist_for_each_entry_safe. Fixes: 94dc550a5062 ("gtp: fix an use-after-free in ipv4_pdp_find()") Signed-off-by: Hyunwoo Kim Reviewed-by: Eric Dumazet Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/gtp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index e5961082a4afd..0d6d2fe9eabdb 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -706,11 +706,12 @@ static int gtp_newlink(struct net *src_net, struct net_device *dev, static void gtp_dellink(struct net_device *dev, struct list_head *head) { struct gtp_dev *gtp = netdev_priv(dev); + struct hlist_node *next; struct pdp_ctx *pctx; int i; for (i = 0; i < gtp->hash_size; i++) - hlist_for_each_entry_rcu(pctx, >p->tid_hash[i], hlist_tid) + hlist_for_each_entry_safe(pctx, next, >p->tid_hash[i], hlist_tid) pdp_context_delete(pctx); list_del_rcu(>p->list); -- 2.43.0