Skip to contentSkip to conversation

Fix dangling pointer at f6i->gc_link.

PATCH Superseded [email protected] 5 participants 13 messages Dec 8, 2023 – Dec 13, 2023

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Fix dangling pointer at f6i->gc_link.

From: Kui-Feng Lee <[email protected]>

According to a report [1], f6i->gc_link may point to a free block causing use-after-free. According the stacktraces in the report, it is very likely that a f6i was added to the GC list after being removed from the tree of a fib6_table. The reason this can happen is the current implementation determines if a f6i is on a tree in a wrong way. It believes a f6i is on a tree if f6i->fib6_table is not NULL. However, f6i->fib6_table is not reset when f6i is removed from a tree.

The new solution is to check if f6i->fib6_node is not NULL as well. f6i->fib6_node is set/or reset when the f6i is added/or removed from from a tree. It can be used to determines if a f6i is on a tree reliably.

The other change is to determine if a f6i is on a GC list. The current implementation relies on RTF_EXPIRES on fib6_flags. It needs to consider if a f6i is on a tree as well. The new solution is checking hlist_unhashed() on f6i->gc_link, a clear evidence, instead.

[1] https://lore.kernel.org/all/[email protected]/

---
Major changes from v1:

- Split fib6_set_expires_locked() and fib6_clean_expires_locked()

- Use hlist_unhashed() on gc_link instead of checking RTF_EXPIRES to determine if a f6i is on a GC list.

- Add tests on toggling routes between permanent and temporary.

v1: https://lore.kernel.org/all/[email protected]/

Kui-Feng Lee (2):
net/ipv6: insert a f6i to a GC list only if the f6i is in a fib6_table
tree.
selftests: fib_tests: Add tests for toggling between w/ and w/o
expires.

 include/net/ip6_fib.h                    | 46 ++++++++++++----
 net/ipv6/route.c                         |  6 +--
 tools/testing/selftests/net/fib_tests.sh | 69 +++++++++++++++++++++++-
 3 files changed, 105 insertions(+), 16 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/2 net/ipv6: insert a f6i to a GC list only if the f6i is in a fib6_table tree.

From: Kui-Feng Lee <[email protected]>

Check f6i->fib6_node and hlist_unhashed(&f6i->gc_link) before inserting a f6i (fib6_info) to tb6_gc_hlist.

The current implementation checks if f6i->fib6_table is not NULL to determines if a f6i is on a tree, however it is not enough. When a f6i is removed from a fib6_table, f6i->fib6_table is not reset. However, fib6_node is always reset when a f6i is removed from a fib6_table and is set when a f6i is added to a fib6_table. So, f6i->fib6_node is a reliable way to determine if a f6i is on a tree.

The current implementation checks RTF_EXPIRES on f6i->fib6_flags to determine if a f6i is on a GC list. It also consider if the f6i is on a tree before making a conclusion. This is indirect and complicated. The new solution is checking hlist_unhashed(&f6i->gc_link), a clear evidence.

Putting them together, these changes provide more reliable signals to determines if a f6i should be added/or removed to a GC list.

Fixes 3dec89b14d37 ("net/ipv6: Remove expired routes with a separated list of routes.")
Reported-by [email protected]
Cc Eric Dumazet <[email protected]>
---
 include/net/ip6_fib.h | 46 ++++++++++++++++++++++++++++++++-----------
 net/ipv6/route.c      |  6 +++---
 2 files changed, 38 insertions(+), 14 deletions(-)
include/net/ip6_fib.h +35 -11
index 1ba9f4ddf2f6..1213722c394f 100644
@@ -500,21 +500,47 @@ 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)
+static inline void fib6_add_gc_list(struct fib6_info *f6i)
 {
 	struct fib6_table *tb6;
 
 	tb6 = f6i->fib6_table;
-	f6i->expires = expires;
-	if (tb6 && !fib6_has_expires(f6i))
+	if (tb6 &&
+	    rcu_dereference_protected(f6i->fib6_node,
+				      lockdep_is_held(&tb6->tb6_lock)) &&
+	    hlist_unhashed(&f6i->gc_link))
 		hlist_add_head(&f6i->gc_link, &tb6->tb6_gc_hlist);
+}
+
+static inline void fib6_del_gc_list(struct fib6_info *f6i)
+{
+	if (!hlist_unhashed(&f6i->gc_link))
+		hlist_del_init(&f6i->gc_link);
+}
+
+static inline void __fib6_set_expires(struct fib6_info *f6i,
+				      unsigned long expires)
+{
+	f6i->expires = expires;
 	f6i->fib6_flags |= RTF_EXPIRES;
 }
 
+static inline void __fib6_clean_expires(struct fib6_info *f6i)
+{
+	f6i->fib6_flags &= ~RTF_EXPIRES;
+	f6i->expires = 0;
+}
+
+/* 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)
+{
+	__fib6_set_expires(f6i, expires);
+	fib6_add_gc_list(f6i);
+}
+
 /* 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.
@@ -529,10 +555,8 @@ static inline void fib6_set_expires(struct fib6_info *f6i,
 
 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;
+	fib6_del_gc_list(f6i);
+	__fib6_clean_expires(f6i);
 }
 
 static inline void fib6_clean_expires(struct fib6_info *f6i)
net/ipv6/route.c +3 -3
index b132feae3393..dcaeb88d73aa 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
#5 lore raw

PATCH v2 2/2 selftests: fib_tests: Add tests for toggling between w/ and w/o expires.

In reply to [email protected]

From: Kui-Feng Lee <[email protected]>

Make sure that toggling routes between w/ expires and w/o expires works properly with GC list.

When a route with expires is replaced by a permanent route, the entry should be removed from the gc list. When a permanent routes is replaced by a temporary route, the new entry should be added to the gc list. The new tests check if these basic operators work properly.

---
 tools/testing/selftests/net/fib_tests.sh | 69 +++++++++++++++++++++++-
 1 file changed, 67 insertions(+), 2 deletions(-)
tools/testing/selftests/net/fib_tests.sh +67 -2
index 66d0db7a2614..a8b4628fd7d2 100755
@@ -806,10 +806,75 @@ fib6_gc_test()
 	    ret=0
 	fi
 
-	set +e
-
 	log_test $ret 0 "ipv6 route garbage collection"
 
+	# Delete permanent routes
+	for i in $(seq 1 5000); do
+	    $IP -6 route del 2001:30::$i \
+		via 2001:10::2 dev dummy_10
+	done
+
+	# Permanent routes
+	for i in $(seq 1 100); do
+	    # Expire route after $EXPIRE seconds
+	    $IP -6 route add 2001:20::$i \
+		via 2001:10::2 dev dummy_10
+	done
+	# Replace with temporary routes
+	for i in $(seq 1 100); do
+	    # Expire route after $EXPIRE seconds
+	    $IP -6 route replace 2001:20::$i \
+		via 2001:10::2 dev dummy_10 expires $EXPIRE
+	done
+	N_EXP_SLEEP=$($IP -6 route list |grep expires|wc -l)
+	if [ $N_EXP_SLEEP -ne 100 ]; then
+	    echo "FAIL: expected 100 routes with expires, got $N_EXP_SLEEP"
+	fi
+	sleep $(($EXPIRE * 2 + 1))
+	N_EXP_SLEEP=$($IP -6 route list |grep expires|wc -l)
+	if [ $N_EXP_SLEEP -ne 0 ]; then
+	    echo "FAIL: expected 0 routes with expires," \
+		 "got $N_EXP_SLEEP"
+	    ret=1
+	else
+	    ret=0
+	fi
+
+	log_test $ret 0 "ipv6 route garbage collection (replace with expires)"
+
+	PERM_BASE=$($IP -6 route list |grep -v expires|wc -l)
+	# Temporary routes
+	for i in $(seq 1 100); do
+	    # Expire route after $EXPIRE seconds
+	    $IP -6 route add 2001:20::$i \
+		via 2001:10::2 dev dummy_10 expires $EXPIRE
+	done
+	# Replace with permanent routes
+	for i in $(seq 1 100); do
+	    # Expire route after $EXPIRE seconds
+	    $IP -6 route replace 2001:20::$i \
+		via 2001:10::2 dev dummy_10
+	done
+	N_EXP_SLEEP=$($IP -6 route list |grep expires|wc -l)
+	if [ $N_EXP_SLEEP -ne 0 ]; then
+	    echo "FAIL: expected 0 routes with expires," \
+		 "got $N_EXP_SLEEP"
+	fi
+	sleep $(($EXPIRE * 2 + 1))
+	N_EXP_PERM=$($IP -6 route list |grep -v expires|wc -l)
+	N_EXP_PERM=$(($N_EXP_PERM - $PERM_BASE))
+	if [ $N_EXP_PERM -ne 100 ]; then
+	    echo "FAIL: expected 100 permanent routes," \
+		 "got $N_EXP_PERM"
+	    ret=1
+	else
+	    ret=0
+	fi
+
+	log_test $ret 0 "ipv6 route garbage collection (replace with permanent)"
+
+	set +e
+
 	cleanup &> /dev/null
 }
 
Signature · 1 line
2.34.1
maintainer
#2 lore raw

Re: [PATCH net-next v2 1/2] net/ipv6: insert a f6i to a GC list only if the f6i is in a fib6_table tree.

In reply to [email protected]
Quoted 11 lines · On 12/8/23 12:45 PM, [email protected] wrote:

From: Kui-Feng Lee <[email protected]>

Check f6i->fib6_node and hlist_unhashed(&f6i->gc_link) before inserting a f6i (fib6_info) to tb6_gc_hlist.

The current implementation checks if f6i->fib6_table is not NULL to determines if a f6i is on a tree, however it is not enough. When a f6i is removed from a fib6_table, f6i->fib6_table is not reset. However, fib6_node is always reset when a f6i is removed from a fib6_table and is set when a f6i is added to a fib6_table. So, f6i->fib6_node is a reliable way to determine if a f6i is on a tree.

Which is an indication that the table is not the right check but neither is the fib6_node. If expires is set on a route entry, add it to the gc_list; if expires is reset on a route entry, remove it from the gc_list. If the value of expires is changed while on the gc_list list, just update the expires value.

#3 lore raw

Re: [PATCH net-next v2 1/2] net/ipv6: insert a f6i to a GC list only if the f6i is in a fib6_table tree.

Quoted 13 lines · David Ahern
Quoted 11 lines · On 12/8/23 12:45 PM, [email protected] wrote:

From: Kui-Feng Lee <[email protected]>

Check f6i->fib6_node and hlist_unhashed(&f6i->gc_link) before inserting a f6i (fib6_info) to tb6_gc_hlist.

The current implementation checks if f6i->fib6_table is not NULL to determines if a f6i is on a tree, however it is not enough. When a f6i is removed from a fib6_table, f6i->fib6_table is not reset. However, fib6_node is always reset when a f6i is removed from a fib6_table and is set when a f6i is added to a fib6_table. So, f6i->fib6_node is a reliable way to determine if a f6i is on a tree.

Quoted 6 lines

Which is an indication that the table is not the right check but neither is the fib6_node. If expires is set on a route entry, add it to the gc_list; if expires is reset on a route entry, remove it from the gc_list. If the value of expires is changed while on the gc_list list, just update the expires value.

I don't quite follow you.
If an entry is not on a tree, why do we still add the entry to the gc list? (This is the reason to check f6i->fib6_node.)

The changes in this patch rely on two indications, 1. if a f6i is on a tree, 2. if a f6i is on a gc list (described in the 3rd paragraph of the comment log.)
An entry is added to a gc list only if it has expires and is not on the list yet. An entry is removed from a gc list only if it is on a gc list. And, just like what you said earlier, it just updates the expires value
while an entry is already on a gc list.

#4 lore raw

Re: [PATCH net-next v2 1/2] net/ipv6: insert a f6i to a GC list only if the f6i is in a fib6_table tree.

Quoted 23 lines · Kui-Feng Lee
Quoted 13 lines · David Ahern
Quoted 11 lines · On 12/8/23 12:45 PM, [email protected] wrote:

From: Kui-Feng Lee <[email protected]>

Check f6i->fib6_node and hlist_unhashed(&f6i->gc_link) before inserting a f6i (fib6_info) to tb6_gc_hlist.

The current implementation checks if f6i->fib6_table is not NULL to determines if a f6i is on a tree, however it is not enough. When a f6i is removed from a fib6_table, f6i->fib6_table is not reset. However, fib6_node is always reset when a f6i is removed from a fib6_table and is set when a f6i is added to a fib6_table. So, f6i->fib6_node is a reliable way to determine if a f6i is on a tree.

Quoted 6 lines

Which is an indication that the table is not the right check but neither is the fib6_node. If expires is set on a route entry, add it to the gc_list; if expires is reset on a route entry, remove it from the gc_list. If the value of expires is changed while on the gc_list list, just update the expires value.

Quoted 8 lines

I don't quite follow you.
If an entry is not on a tree, why do we still add the entry to the gc list? (This is the reason to check f6i->fib6_node.)

The changes in this patch rely on two indications, 1. if a f6i is on a tree, 2. if a f6i is on a gc list (described in the 3rd paragraph of the comment log.)
An entry is added to a gc list only if it has expires and is not on the list yet. An entry is removed from a gc list only if it is on a gc list. And, just like what you said earlier, it just updates the expires value
while an entry is already on a gc list.

Add more context here.

Use rt6_route_rcv() as an example. It looks up or adds a route first.
Then it changes expires of the route at the very end of the function.
There is gap between looking up and the modification. The f6i found here
can be removed from the tree in-between. If the f6i here is added to the
gc list even it has been removed from the tree, fib6_info_release() at the end of rt6_route_rcv() might free the f6i while the f6i is still in the gc list.

This is why it checks if a f6i is on the tree with the protection of tb6_lock.

#6 lore raw

Re: [PATCH net-next v2 2/2] selftests: fib_tests: Add tests for toggling between w/ and w/o expires.

In reply to [email protected]
Quoted 38 lines · On Fri, Dec 08, 2023 at 11:45:23AM -0800, [email protected] wrote:

From: Kui-Feng Lee <[email protected]>

Make sure that toggling routes between w/ expires and w/o expires works properly with GC list.

When a route with expires is replaced by a permanent route, the entry should be removed from the gc list. When a permanent routes is replaced by a temporary route, the new entry should be added to the gc list. The new tests check if these basic operators work properly.

---
 tools/testing/selftests/net/fib_tests.sh | 69 +++++++++++++++++++++++-
 1 file changed, 67 insertions(+), 2 deletions(-)
tools/testing/selftests/net/fib_tests.sh +11 -2
index 66d0db7a2614..a8b4628fd7d2 100755
@@ -806,10 +806,75 @@ fib6_gc_test()
 	    ret=0
 	fi
 
-	set +e
-
 	log_test $ret 0 "ipv6 route garbage collection"
 
+	# Delete permanent routes
+	for i in $(seq 1 5000); do
+	    $IP -6 route del 2001:30::$i \
+		via 2001:10::2 dev dummy_10
+	done
+
+	# Permanent routes
+	for i in $(seq 1 100); do
+	    # Expire route after $EXPIRE seconds
+	    $IP -6 route add 2001:20::$i \
+		via 2001:10::2 dev dummy_10

tools/testing/selftests/net/fib_tests.sh fib6_gc_test() · line 831

Quoted 10 lines
tools/testing/selftests/net/fib_tests.sh +10 -0
+	done
+	# Replace with temporary routes
+	for i in $(seq 1 100); do
+	    # Expire route after $EXPIRE seconds
+	    $IP -6 route replace 2001:20::$i \
+		via 2001:10::2 dev dummy_10 expires $EXPIRE
+	done
+	N_EXP_SLEEP=$($IP -6 route list |grep expires|wc -l)
+	if [ $N_EXP_SLEEP -ne 100 ]; then
+	    echo "FAIL: expected 100 routes with expires, got $N_EXP_SLEEP"

Hi,

Here the test failed, but ret is not updated.

tools/testing/selftests/net/fib_tests.sh fib6_gc_test() · line 838

Quoted 7 lines
tools/testing/selftests/net/fib_tests.sh +7 -0
+	fi
+	sleep $(($EXPIRE * 2 + 1))
+	N_EXP_SLEEP=$($IP -6 route list |grep expires|wc -l)
+	if [ $N_EXP_SLEEP -ne 0 ]; then
+	    echo "FAIL: expected 0 routes with expires," \
+		 "got $N_EXP_SLEEP"
+	    ret=1

Here the ret is updated.

Quoted 13 lines
tools/testing/selftests/net/fib_tests.sh +13 -0
+	else
+	    ret=0
+	fi
+
+	log_test $ret 0 "ipv6 route garbage collection (replace with expires)"
+
+	PERM_BASE=$($IP -6 route list |grep -v expires|wc -l)
+	# Temporary routes
+	for i in $(seq 1 100); do
+	    # Expire route after $EXPIRE seconds
+	    $IP -6 route add 2001:20::$i \
+		via 2001:10::2 dev dummy_10 expires $EXPIRE
+	done

tools/testing/selftests/net/fib_tests.sh fib6_gc_test() · line 861

Quoted 10 lines
tools/testing/selftests/net/fib_tests.sh +10 -0
+	# Replace with permanent routes
+	for i in $(seq 1 100); do
+	    # Expire route after $EXPIRE seconds
+	    $IP -6 route replace 2001:20::$i \
+		via 2001:10::2 dev dummy_10
+	done
+	N_EXP_SLEEP=$($IP -6 route list |grep expires|wc -l)
+	if [ $N_EXP_SLEEP -ne 0 ]; then
+	    echo "FAIL: expected 0 routes with expires," \
+		 "got $N_EXP_SLEEP"

Same here.

Thanks
Hangbin

Quoted 22 lines
tools/testing/selftests/net/fib_tests.sh +16 -0
+	fi
+	sleep $(($EXPIRE * 2 + 1))
+	N_EXP_PERM=$($IP -6 route list |grep -v expires|wc -l)
+	N_EXP_PERM=$(($N_EXP_PERM - $PERM_BASE))
+	if [ $N_EXP_PERM -ne 100 ]; then
+	    echo "FAIL: expected 100 permanent routes," \
+		 "got $N_EXP_PERM"
+	    ret=1
+	else
+	    ret=0
+	fi
+
+	log_test $ret 0 "ipv6 route garbage collection (replace with permanent)"
+
+	set +e
+
 	cleanup &> /dev/null
 }
 
Signature · 1 line
2.34.1
#7 lore raw

Re: [PATCH net-next v2 2/2] selftests: fib_tests: Add tests for toggling between w/ and w/o expires.

Quoted 111 lines · Hangbin Liu
Quoted 38 lines · On Fri, Dec 08, 2023 at 11:45:23AM -0800, [email protected] wrote:

From: Kui-Feng Lee <[email protected]>

Make sure that toggling routes between w/ expires and w/o expires works properly with GC list.

When a route with expires is replaced by a permanent route, the entry should be removed from the gc list. When a permanent routes is replaced by a temporary route, the new entry should be added to the gc list. The new tests check if these basic operators work properly.

---
  tools/testing/selftests/net/fib_tests.sh | 69 +++++++++++++++++++++++-
  1 file changed, 67 insertions(+), 2 deletions(-)
tools/testing/selftests/net/fib_tests.sh +11 -2
index 66d0db7a2614..a8b4628fd7d2 100755
@@ -806,10 +806,75 @@ fib6_gc_test()
  	    ret=0
  	fi
 
-	set +e
-
  	log_test $ret 0 "ipv6 route garbage collection"
 
+	# Delete permanent routes
+	for i in $(seq 1 5000); do
+	    $IP -6 route del 2001:30::$i \
+		via 2001:10::2 dev dummy_10
+	done
+
+	# Permanent routes
+	for i in $(seq 1 100); do
+	    # Expire route after $EXPIRE seconds
+	    $IP -6 route add 2001:20::$i \
+		via 2001:10::2 dev dummy_10

tools/testing/selftests/net/fib_tests.sh fib6_gc_test() · line 831

Quoted 10 lines
tools/testing/selftests/net/fib_tests.sh +10 -0
+	done
+	# Replace with temporary routes
+	for i in $(seq 1 100); do
+	    # Expire route after $EXPIRE seconds
+	    $IP -6 route replace 2001:20::$i \
+		via 2001:10::2 dev dummy_10 expires $EXPIRE
+	done
+	N_EXP_SLEEP=$($IP -6 route list |grep expires|wc -l)
+	if [ $N_EXP_SLEEP -ne 100 ]; then
+	    echo "FAIL: expected 100 routes with expires, got $N_EXP_SLEEP"

Hi,

Here the test failed, but ret is not updated.

tools/testing/selftests/net/fib_tests.sh fib6_gc_test() · line 838

Quoted 7 lines
tools/testing/selftests/net/fib_tests.sh +7 -0
+	fi
+	sleep $(($EXPIRE * 2 + 1))
+	N_EXP_SLEEP=$($IP -6 route list |grep expires|wc -l)
+	if [ $N_EXP_SLEEP -ne 0 ]; then
+	    echo "FAIL: expected 0 routes with expires," \
+		 "got $N_EXP_SLEEP"
+	    ret=1

Here the ret is updated.

Quoted 13 lines
tools/testing/selftests/net/fib_tests.sh +13 -0
+	else
+	    ret=0
+	fi
+
+	log_test $ret 0 "ipv6 route garbage collection (replace with expires)"
+
+	PERM_BASE=$($IP -6 route list |grep -v expires|wc -l)
+	# Temporary routes
+	for i in $(seq 1 100); do
+	    # Expire route after $EXPIRE seconds
+	    $IP -6 route add 2001:20::$i \
+		via 2001:10::2 dev dummy_10 expires $EXPIRE
+	done

tools/testing/selftests/net/fib_tests.sh fib6_gc_test() · line 861

Quoted 10 lines
tools/testing/selftests/net/fib_tests.sh +10 -0
+	# Replace with permanent routes
+	for i in $(seq 1 100); do
+	    # Expire route after $EXPIRE seconds
+	    $IP -6 route replace 2001:20::$i \
+		via 2001:10::2 dev dummy_10
+	done
+	N_EXP_SLEEP=$($IP -6 route list |grep expires|wc -l)
+	if [ $N_EXP_SLEEP -ne 0 ]; then
+	    echo "FAIL: expected 0 routes with expires," \
+		 "got $N_EXP_SLEEP"

Same here.

Thanks
Hangbin

Quoted 19 lines
tools/testing/selftests/net/fib_tests.sh +16 -0
+	fi
+	sleep $(($EXPIRE * 2 + 1))
+	N_EXP_PERM=$($IP -6 route list |grep -v expires|wc -l)
+	N_EXP_PERM=$(($N_EXP_PERM - $PERM_BASE))
+	if [ $N_EXP_PERM -ne 100 ]; then
+	    echo "FAIL: expected 100 permanent routes," \
+		 "got $N_EXP_PERM"
+	    ret=1
+	else
+	    ret=0
+	fi
+
+	log_test $ret 0 "ipv6 route garbage collection (replace with permanent)"
+
+	set +e
+
  	cleanup &> /dev/null
  }
 
Quoted 3 lines
Quoted 3 lines
Signature · 1 line
2.34.1

Got it! Thanks!

#8 lore raw

Re: [PATCH net-next v2 2/2] selftests: fib_tests: Add tests for toggling between w/ and w/o expires.

Quoted 8 lines · Kui-Feng Lee
Quoted 8 lines

tools/testing/selftests/net/fib_tests.sh fib6_gc_test() · line 831

Quoted 3 lines
tools/testing/selftests/net/fib_tests.sh +3 -0
+	N_EXP_SLEEP=$($IP -6 route list |grep expires|wc -l)
+	if [ $N_EXP_SLEEP -ne 100 ]; then
+	    echo "FAIL: expected 100 routes with expires, got $N_EXP_SLEEP"

Hi,

Here the test failed, but ret is not updated.

Quoted 9 lines
Quoted 9 lines

tools/testing/selftests/net/fib_tests.sh fib6_gc_test() · line 838

Quoted 7 lines
tools/testing/selftests/net/fib_tests.sh +7 -0
+	fi
+	sleep $(($EXPIRE * 2 + 1))
+	N_EXP_SLEEP=$($IP -6 route list |grep expires|wc -l)
+	if [ $N_EXP_SLEEP -ne 0 ]; then
+	    echo "FAIL: expected 0 routes with expires," \
+		 "got $N_EXP_SLEEP"
+	    ret=1

Here the ret is updated.

BTW, the current fib6_gc_test() use $ret to store the result. But the latter check would cover the previous one. e.g.

if [ $N_EXP_SLEEP -ne 0 ]; then

	ret=1
else
	ret=0

fi

do_some_other_tests
if [ $N_EXP_SLEEP -ne 0 ]; then

	ret=1
else
	ret=0

fi

If the previous one failed, but later one pass, the ret would be re-write to 0. So I think we can use log_test for each checking.

Thanks
Hangbin

#9 lore raw

Re: [PATCH net-next v2 2/2] selftests: fib_tests: Add tests for toggling between w/ and w/o expires.

Quoted 33 lines · Hangbin Liu
Quoted 8 lines · Kui-Feng Lee
Quoted 8 lines

tools/testing/selftests/net/fib_tests.sh fib6_gc_test() · line 831

Quoted 3 lines
tools/testing/selftests/net/fib_tests.sh +3 -0
+	N_EXP_SLEEP=$($IP -6 route list |grep expires|wc -l)
+	if [ $N_EXP_SLEEP -ne 100 ]; then
+	    echo "FAIL: expected 100 routes with expires, got $N_EXP_SLEEP"

Hi,

Here the test failed, but ret is not updated.

Quoted 9 lines
Quoted 9 lines

tools/testing/selftests/net/fib_tests.sh fib6_gc_test() · line 838

Quoted 7 lines
tools/testing/selftests/net/fib_tests.sh +7 -0
+	fi
+	sleep $(($EXPIRE * 2 + 1))
+	N_EXP_SLEEP=$($IP -6 route list |grep expires|wc -l)
+	if [ $N_EXP_SLEEP -ne 0 ]; then
+	    echo "FAIL: expected 0 routes with expires," \
+		 "got $N_EXP_SLEEP"
+	    ret=1

Here the ret is updated.

BTW, the current fib6_gc_test() use $ret to store the result. But the latter check would cover the previous one. e.g.

if [ $N_EXP_SLEEP -ne 0 ]; then

	ret=1
else
	ret=0

fi

do_some_other_tests
if [ $N_EXP_SLEEP -ne 0 ]; then

	ret=1
else
	ret=0
Quoted 7 lines

fi

If the previous one failed, but later one pass, the ret would be re-write to 0. So I think we can use log_test for each checking.

Thanks
Hangbin

Some of these tests has dependencies. So, what I did is to perform the following commands only if ret = 0.

if [ $N_EXP_SLEEP -ne 0 ]; then

    ret=1
else
    ret=0

fi

if [ $ret -eq 0 ]; then
.....
if [ ...]; then

      ret=1
  else
      ret=0

fi
fi

if [ $ret -eq 0]; then
....
fi

maintainer
#10 lore raw
In reply to [email protected]
Quoted 15 lines · On 12/8/23 12:45 PM, [email protected] wrote:

From: Kui-Feng Lee <[email protected]>

According to a report [1], f6i->gc_link may point to a free block causing use-after-free. According the stacktraces in the report, it is very likely that a f6i was added to the GC list after being removed from the tree of a fib6_table. The reason this can happen is the current implementation determines if a f6i is on a tree in a wrong way. It believes a f6i is on a tree if f6i->fib6_table is not NULL. However, f6i->fib6_table is not reset when f6i is removed from a tree.

The new solution is to check if f6i->fib6_node is not NULL as well. f6i->fib6_node is set/or reset when the f6i is added/or removed from from a tree. It can be used to determines if a f6i is on a tree reliably.

Quoted 7 lines

The other change is to determine if a f6i is on a GC list. The current implementation relies on RTF_EXPIRES on fib6_flags. It needs to consider if a f6i is on a tree as well. The new solution is checking hlist_unhashed() on f6i->gc_link, a clear evidence, instead.

[1] https://lore.kernel.org/all/[email protected]/

Eric: can you release the syzbot report for the backtrace listed in [1]. I would like to make "very likely that a f6i was added to the GC list after being removed from the tree of a fib6_table" more certain. Thanks,

#11 lore raw
Quoted 22 lines · David Ahern
Quoted 20 lines · On 12/8/23 12:45 PM, [email protected] wrote:

From: Kui-Feng Lee <[email protected]>

According to a report [1], f6i->gc_link may point to a free block causing use-after-free. According the stacktraces in the report, it is very likely that a f6i was added to the GC list after being removed from the tree of a fib6_table. The reason this can happen is the current implementation determines if a f6i is on a tree in a wrong way. It believes a f6i is on a tree if f6i->fib6_table is not NULL. However, f6i->fib6_table is not reset when f6i is removed from a tree.

The new solution is to check if f6i->fib6_node is not NULL as well. f6i->fib6_node is set/or reset when the f6i is added/or removed from from a tree. It can be used to determines if a f6i is on a tree reliably.

The other change is to determine if a f6i is on a GC list. The current implementation relies on RTF_EXPIRES on fib6_flags. It needs to consider if a f6i is on a tree as well. The new solution is checking hlist_unhashed() on f6i->gc_link, a clear evidence, instead.

Quoted 6 lines
Quoted 2 lines

[1] https://lore.kernel.org/all/[email protected]/

Eric: can you release the syzbot report for the backtrace listed in [1]. I would like to make "very likely that a f6i was added to the GC list after being removed from the tree of a fib6_table" more certain. Thanks,

I have one, not sure if the tree is recent enough.

maintainer
#12 lore raw
Quoted 1 line · Eric Dumazet

I have one, not sure if the tree is recent enough.

If syzbot is using radvd, can you send that config file?