2019-12-26 12:54:41

by Xiyu Yang

[permalink] [raw]
Subject: [PATCH v2] infiniband: i40iw: fix a potential NULL pointer dereference

From: Xiyu Yang <[email protected]>

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 <[email protected]>
Signed-off-by: Xin Tan <[email protected]>
---
Changes in v2:
- Release rtnl lock when in_dev_get return NULL

drivers/infiniband/hw/i40iw/i40iw_main.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/infiniband/hw/i40iw/i40iw_main.c b/drivers/infiniband/hw/i40iw/i40iw_main.c
index d44cf33d..d7146fdf 100644
--- a/drivers/infiniband/hw/i40iw/i40iw_main.c
+++ b/drivers/infiniband/hw/i40iw/i40iw_main.c
@@ -1225,6 +1225,10 @@ static void i40iw_add_ipv4_addr(struct i40iw_device *iwdev)
const struct in_ifaddr *ifa;

idev = in_dev_get(dev);
+ if (!idev) {
+ i40iw_pr_err("ipv4 inet device not found\n");
+ break;
+ }
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


2019-12-26 13:07:46

by Leon Romanovsky

[permalink] [raw]
Subject: Re: [PATCH v2] infiniband: i40iw: fix a potential NULL pointer dereference

On Thu, Dec 26, 2019 at 08:52:37PM +0800, [email protected] wrote:
> From: Xiyu Yang <[email protected]>
>
> 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 <[email protected]>
> Signed-off-by: Xin Tan <[email protected]>
> ---
> Changes in v2:
> - Release rtnl lock when in_dev_get return NULL
>
> drivers/infiniband/hw/i40iw/i40iw_main.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/infiniband/hw/i40iw/i40iw_main.c b/drivers/infiniband/hw/i40iw/i40iw_main.c
> index d44cf33d..d7146fdf 100644
> --- a/drivers/infiniband/hw/i40iw/i40iw_main.c
> +++ b/drivers/infiniband/hw/i40iw/i40iw_main.c
> @@ -1225,6 +1225,10 @@ static void i40iw_add_ipv4_addr(struct i40iw_device *iwdev)
> const struct in_ifaddr *ifa;
>
> idev = in_dev_get(dev);
> + if (!idev) {
> + i40iw_pr_err("ipv4 inet device not found\n");
> + break;
> + }

It continues to be wrong. You shouldn't get out of the loop, but skip
in_dev_for_each_ifa_rtnl() section. Also, error print shouldn't be added
too.

Thanks

> 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
>