Skip to contentSkip to conversation

net/ipv6: Revert remove expired routes with a separated list of routes

PATCH Superseded David Ahern 3 participants 6 messages Dec 17, 2023 – Dec 19, 2023

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

David Ahern

author maintainer
#0 lore raw

PATCH 1/1 net/ipv6: Revert remove expired routes with a separated list of routes

Revert the remainder of 5a08d0065a915 which added a warn on if a fib entry is still on the gc_link list, and then revert all of the commit in the Fixes tag. The commit has some race conditions given how expires is managed on a fib6_info in relation to timer start, adding the entry to the gc list and setting the timer value leading to UAF. Revert the commit and try again in a later release.

Fixes 3dec89b14d37 ("net/ipv6: Remove expired routes with a separated list of routes")
Cc Kui-Feng Lee <[email protected]>
---
 include/net/ip6_fib.h | 68 +++++++++----------------------------------
 net/ipv6/ip6_fib.c    | 55 ++++------------------------------
 net/ipv6/route.c      |  6 ++--
 3 files changed, 23 insertions(+), 106 deletions(-)
include/net/ip6_fib.h +14 -54
index 95ed495c3a40..9ba6413fd2e3 100644
@@ -179,9 +179,6 @@ struct fib6_info {
 
 	refcount_t			fib6_ref;
 	unsigned long			expires;
-
-	struct hlist_node		gc_link;
-
 	struct dst_metrics		*fib6_metrics;
 #define fib6_pmtu		fib6_metrics->metrics[RTAX_MTU-1]
 
@@ -250,6 +247,19 @@ static inline bool fib6_requires_src(const struct fib6_info *rt)
 	return rt->fib6_src.plen > 0;
 }
 
+static inline void fib6_clean_expires(struct fib6_info *f6i)
+{
+	f6i->fib6_flags &= ~RTF_EXPIRES;
+	f6i->expires = 0;
+}
+
+static inline void fib6_set_expires(struct fib6_info *f6i,
+				    unsigned long expires)
+{
+	f6i->expires = expires;
+	f6i->fib6_flags |= RTF_EXPIRES;
+}
+
 static inline bool fib6_check_expired(const struct fib6_info *f6i)
 {
 	if (f6i->fib6_flags & RTF_EXPIRES)
@@ -257,11 +267,6 @@ static inline bool fib6_check_expired(const struct fib6_info *f6i)
 	return false;
 }
 
-static inline bool fib6_has_expires(const struct fib6_info *f6i)
-{
-	return f6i->fib6_flags & RTF_EXPIRES;
-}
-
 /* Function to safely get fn->fn_sernum for passed in rt
  * and store result in passed in cookie.
  * Return true if we can get cookie safely
@@ -328,10 +333,8 @@ static inline bool fib6_info_hold_safe(struct fib6_info *f6i)
 
 static inline void fib6_info_release(struct fib6_info *f6i)
 {
-	if (f6i && refcount_dec_and_test(&f6i->fib6_ref)) {
-		DEBUG_NET_WARN_ON_ONCE(!hlist_unhashed(&f6i->gc_link));
+	if (f6i && refcount_dec_and_test(&f6i->fib6_ref))
 		call_rcu(&f6i->rcu, fib6_info_destroy_rcu);
-	}
 }
 
 enum fib6_walk_state {
@@ -385,7 +388,6 @@ struct fib6_table {
 	struct inet_peer_base	tb6_peers;
 	unsigned int		flags;
 	unsigned int		fib_seq;
-	struct hlist_head       tb6_gc_hlist;	/* GC candidates */
 #define RT6_TABLE_HAS_DFLT_ROUTER	BIT(0)
 };
 
@@ -502,48 +504,6 @@ void fib6_gc_cleanup(void);
 
 int fib6_init(void);
 
-/* fib6_info must be locked by the caller, and fib6_info->fib6_table can be
- * NULL.
- */
-static inline void fib6_set_expires_locked(struct fib6_info *f6i,
-					   unsigned long expires)
-{
-	struct fib6_table *tb6;
-
-	tb6 = f6i->fib6_table;
-	f6i->expires = expires;
-	if (tb6 && !fib6_has_expires(f6i))
-		hlist_add_head(&f6i->gc_link, &tb6->tb6_gc_hlist);
-	f6i->fib6_flags |= RTF_EXPIRES;
-}
-
-/* fib6_info must be locked by the caller, and fib6_info->fib6_table can be
- * NULL.  If fib6_table is NULL, the fib6_info will no be inserted into the
- * list of GC candidates until it is inserted into a table.
- */
-static inline void fib6_set_expires(struct fib6_info *f6i,
-				    unsigned long expires)
-{
-	spin_lock_bh(&f6i->fib6_table->tb6_lock);
-	fib6_set_expires_locked(f6i, expires);
-	spin_unlock_bh(&f6i->fib6_table->tb6_lock);
-}
-
-static inline void fib6_clean_expires_locked(struct fib6_info *f6i)
-{
-	if (fib6_has_expires(f6i))
-		hlist_del_init(&f6i->gc_link);
-	f6i->fib6_flags &= ~RTF_EXPIRES;
-	f6i->expires = 0;
-}
-
-static inline void fib6_clean_expires(struct fib6_info *f6i)
-{
-	spin_lock_bh(&f6i->fib6_table->tb6_lock);
-	fib6_clean_expires_locked(f6i);
-	spin_unlock_bh(&f6i->fib6_table->tb6_lock);
-}
-
 struct ipv6_route_iter {
 	struct seq_net_private p;
 	struct fib6_walker w;
net/ipv6/ip6_fib.c +6 -49

111 lines not on this page · raw message

net/ipv6/route.c +3 -3
index b132feae3393..ea1dec8448fc 100644
@@ -3763,10 +3763,10 @@ static struct fib6_info *ip6_route_info_create(struct fib6_config *cfg,
 		rt->dst_nocount = true;
 
 	if (cfg->fc_flags & RTF_EXPIRES)
-		fib6_set_expires_locked(rt, jiffies +
-					clock_t_to_jiffies(cfg->fc_expires));
+		fib6_set_expires(rt, jiffies +
+				clock_t_to_jiffies(cfg->fc_expires));
 	else
-		fib6_clean_expires_locked(rt);
+		fib6_clean_expires(rt);
 
 	if (cfg->fc_protocol == RTPROT_UNSPEC)
 		cfg->fc_protocol = RTPROT_BOOT;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 11 lines · David Ahern

Revert the remainder of 5a08d0065a915 which added a warn on if a fib entry is still on the gc_link list, and then revert all of the commit in the Fixes tag. The commit has some race conditions given how expires is managed on a fib6_info in relation to timer start, adding the entry to the gc list and setting the timer value leading to UAF. Revert the commit and try again in a later release.

Fixes 3dec89b14d37 ("net/ipv6: Remove expired routes with a separated list of routes")
Cc Kui-Feng Lee <[email protected]>

I guess we need two patches, one in net-next, one in net ?

If this patch targets net tree, it probably should be a plain revert (no need to mention 5a08d0065a915)

#2 lore raw
In reply to David Ahern
Quoted 6 lines · David Ahern

Revert the remainder of 5a08d0065a915 which added a warn on if a fib entry is still on the gc_link list, and then revert all of the commit in the Fixes tag. The commit has some race conditions given how expires is managed on a fib6_info in relation to timer start, adding the entry to the gc list and setting the timer value leading to UAF. Revert the commit and try again in a later release.

May I know what your concerns are about the patch I provided? Even I try it again later, I still need to know what I miss and should address.

author maintainer
#3 lore raw
Quoted 10 lines · Kui-Feng Lee
Quoted 6 lines · David Ahern

Revert the remainder of 5a08d0065a915 which added a warn on if a fib entry is still on the gc_link list, and then revert  all of the commit in the Fixes tag. The commit has some race conditions given how expires is managed on a fib6_info in relation to timer start, adding the entry to the gc list and setting the timer value leading to UAF. Revert the commit and try again in a later release.

Quoted 3 lines

May I know what your concerns are about the patch I provided? Even I try it again later, I still need to know what I miss and should address.

This is a judgement call based on 6.7-rc number and upcoming holidays with people offline. A bug fix is needed for a performance optimization; the smart response here is to revert the patch and try again after the holidays.

#4 lore raw
Quoted 11 lines · David Ahern
Quoted 10 lines · Kui-Feng Lee
Quoted 6 lines · David Ahern

Revert the remainder of 5a08d0065a915 which added a warn on if a fib entry is still on the gc_link list, and then revert  all of the commit in the Fixes tag. The commit has some race conditions given how expires is managed on a fib6_info in relation to timer start, adding the entry to the gc list and setting the timer value leading to UAF. Revert the commit and try again in a later release.

Quoted 8 lines
Quoted 3 lines

May I know what your concerns are about the patch I provided? Even I try it again later, I still need to know what I miss and should address.

This is a judgement call based on 6.7-rc number and upcoming holidays with people offline. A bug fix is needed for a performance optimization; the smart response here is to revert the patch and try again after the holidays.

Got it! Thanks!

author maintainer
#5 lore raw
Quoted 18 lines · Kui-Feng Lee
Quoted 15 lines · David Ahern
Quoted 13 lines · Kui-Feng Lee
Quoted 6 lines · David Ahern

Revert the remainder of 5a08d0065a915 which added a warn on if a fib entry is still on the gc_link list, and then revert  all of the commit in the Fixes tag. The commit has some race conditions given how expires is managed on a fib6_info in relation to timer start, adding the entry to the gc list and setting the timer value leading to UAF. Revert the commit and try again in a later release.

May I know what your concerns are about the patch I provided? Even I try it again later, I still need to know what I miss and should address.

Quoted 5 lines
Quoted 4 lines

This is a judgement call based on 6.7-rc number and upcoming holidays with people offline. A bug fix is needed for a performance optimization; the smart response here is to revert the patch and try again after the holidays.

Got it! Thanks!

In January, send a new set (RFC if it is still the merge window) with the following:

1. audit all of the uses of RTF_EXPIRES. Some of the places need to be cleaned up first. For example, rt6_add_dflt_router sets RTF_EXPIRES flag but does not set fc_expires. I believe that function can be updated to take the expires value and removes the need to set it later in ndisc_router_discovery. See if the management of expires value can be consolidated under the table lock.

2. Use gc_list instead of gc_link to be consistent with other gc lists (and the fact that it is a list)

3. Add selftests using veth and namespaces to test RAs. It can depend on and check for the existence of the ra or radvd command; the key is to attempt a stress test on the router discovery path. Similarly for addrconf.

That is in addition to your new selftests in the last set you sent.