Re: [PATCH net] net: prevent NULL pointer dereference in rt_fibinfo_free() and rt_fibinfo_free_cpus()

From: kernel test robot
Date: Tue Sep 10 2024 - 11:01:06 EST


Hi Jeongjun,

kernel test robot noticed the following build warnings:

[auto build test WARNING on net/main]

url: https://github.com/intel-lab-lkp/linux/commits/Jeongjun-Park/net-prevent-NULL-pointer-dereference-in-rt_fibinfo_free-and-rt_fibinfo_free_cpus/20240910-025008
base: net/main
patch link: https://lore.kernel.org/r/20240909184827.123071-1-aha310510%40gmail.com
patch subject: [PATCH net] net: prevent NULL pointer dereference in rt_fibinfo_free() and rt_fibinfo_free_cpus()
config: arc-randconfig-002-20240910 (https://download.01.org/0day-ci/archive/20240910/202409102210.krjQJVRr-lkp@xxxxxxxxx/config)
compiler: arc-elf-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240910/202409102210.krjQJVRr-lkp@xxxxxxxxx/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Closes: https://lore.kernel.org/oe-kbuild-all/202409102210.krjQJVRr-lkp@xxxxxxxxx/

All warnings (new ones prefixed by >>):

net/ipv4/fib_semantics.c: In function 'rt_fibinfo_free':
>> net/ipv4/fib_semantics.c:156:13: warning: the comparison will always evaluate as 'true' for the address of 'dst' will never be NULL [-Waddress]
156 | if (!&rt->dst)
| ^
In file included from include/net/ip.h:30,
from net/ipv4/fib_semantics.c:37:
include/net/route.h:56:33: note: 'dst' declared here
56 | struct dst_entry dst;
| ^~~
net/ipv4/fib_semantics.c: In function 'rt_fibinfo_free_cpus':
net/ipv4/fib_semantics.c:209:21: warning: the comparison will always evaluate as 'true' for the address of 'dst' will never be NULL [-Waddress]
209 | if (!&rt->dst)
| ^
include/net/route.h:56:33: note: 'dst' declared here
56 | struct dst_entry dst;
| ^~~


vim +156 net/ipv4/fib_semantics.c

149
150 static void rt_fibinfo_free(struct rtable __rcu **rtp)
151 {
152 struct rtable *rt = rcu_dereference_protected(*rtp, 1);
153
154 if (!rt)
155 return;
> 156 if (!&rt->dst)
157 return;
158
159 /* Not even needed : RCU_INIT_POINTER(*rtp, NULL);
160 * because we waited an RCU grace period before calling
161 * free_fib_info_rcu()
162 */
163
164 dst_dev_put(&rt->dst);
165 dst_release_immediate(&rt->dst);
166 }
167

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki