hc
2024-05-16 8d2a02b24d66aa359e83eebc1ed3c0f85367a1cb
kernel/net/ipv4/fib_semantics.c
....@@ -30,6 +30,7 @@
3030 #include <linux/slab.h>
3131 #include <linux/netlink.h>
3232 #include <linux/hash.h>
33
+#include <linux/nospec.h>
3334
3435 #include <net/arp.h>
3536 #include <net/ip.h>
....@@ -277,7 +278,8 @@
277278 hlist_del(&nexthop_nh->nh_hash);
278279 } endfor_nexthops(fi)
279280 }
280
- fi->fib_dead = 1;
281
+ /* Paired with READ_ONCE() from fib_table_lookup() */
282
+ WRITE_ONCE(fi->fib_dead, 1);
281283 fib_info_put(fi);
282284 }
283285 spin_unlock_bh(&fib_info_lock);
....@@ -1021,6 +1023,7 @@
10211023 if (type > RTAX_MAX)
10221024 return false;
10231025
1026
+ type = array_index_nospec(type, RTAX_MAX + 1);
10241027 if (type == RTAX_CC_ALGO) {
10251028 char tmp[TCP_CA_NAME_MAX];
10261029 bool ecn_ca = false;
....@@ -1597,6 +1600,7 @@
15971600 link_it:
15981601 ofi = fib_find_info(fi);
15991602 if (ofi) {
1603
+ /* fib_table_lookup() should not see @fi yet. */
16001604 fi->fib_dead = 1;
16011605 free_fib_info(fi);
16021606 ofi->fib_treeref++;
....@@ -1635,6 +1639,7 @@
16351639
16361640 failure:
16371641 if (fi) {
1642
+ /* fib_table_lookup() should not see @fi yet. */
16381643 fi->fib_dead = 1;
16391644 free_fib_info(fi);
16401645 }