lkml.org 
[lkml]   [2019]   [Dec]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] infiniband: i40iw: fix a potential NULL pointer dereference
On Thu, Dec 26, 2019 at 10:52:52AM +0800, xiyuyang19@fudan.edu.cn wrote:
> From: Xiyu Yang <xiyuyang19@fudan.edu.cn>
>
> in_dev_get may return a NULL object. The fix handles the situation
> by adding a check to avoid NULL pointer dereference on idev,
> as pick_local_ipaddrs does.
>
> Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
> Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
> ---
> drivers/infiniband/hw/i40iw/i40iw_main.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/infiniband/hw/i40iw/i40iw_main.c b/drivers/infiniband/hw/i40iw/i40iw_main.c
> index d44cf33d..18587cc 100644
> --- a/drivers/infiniband/hw/i40iw/i40iw_main.c
> +++ b/drivers/infiniband/hw/i40iw/i40iw_main.c
> @@ -1225,6 +1225,8 @@ static void i40iw_add_ipv4_addr(struct i40iw_device *iwdev)
> const struct in_ifaddr *ifa;
>
> idev = in_dev_get(dev);
> + if (!idev)
> + return;

1. You forgot to release rtnl lock.
2. The rtnl_trylock()/rtnl_unlock() scheme is wrong in this function.
That lock is global and any devices can take it and prevent from i40iw
to success in rtnl_trylock(), after that in_dev_for_each_ifa_rtnl() will
be incorrect.

> in_dev_for_each_ifa_rtnl(ifa, idev) {
> i40iw_debug(&iwdev->sc_dev, I40IW_DEBUG_CM,
> "IP=%pI4, vlan_id=%d, MAC=%pM\n", &ifa->ifa_address,
> --
> 2.7.4
>

\
 
 \ /
  Last update: 2019-12-26 09:14    [W:0.028 / U:1.648 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site