public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: xiyuyang19@fudan.edu.cn
Cc: yuanxzhang@fudan.edu.cn, kjlu@umn.edu,
	Xin Tan <tanxin.ctf@gmail.com>,
	Faisal Latif <faisal.latif@intel.com>,
	Shiraz Saleem <shiraz.saleem@intel.com>,
	Doug Ledford <dledford@redhat.com>,
	Jason Gunthorpe <jgg@ziepe.ca>,
	linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] infiniband: i40iw: fix a potential NULL pointer dereference
Date: Thu, 26 Dec 2019 15:05:52 +0200	[thread overview]
Message-ID: <20191226130552.GD6285@unreal> (raw)
In-Reply-To: <1577364757-18385-1-git-send-email-xiyuyang19@fudan.edu.cn>

On Thu, Dec 26, 2019 at 08:52:37PM +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>
> ---
> 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
>

      reply	other threads:[~2019-12-26 13:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-26 12:52 [PATCH v2] infiniband: i40iw: fix a potential NULL pointer dereference xiyuyang19
2019-12-26 13:05 ` Leon Romanovsky [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191226130552.GD6285@unreal \
    --to=leon@kernel.org \
    --cc=dledford@redhat.com \
    --cc=faisal.latif@intel.com \
    --cc=jgg@ziepe.ca \
    --cc=kjlu@umn.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=shiraz.saleem@intel.com \
    --cc=tanxin.ctf@gmail.com \
    --cc=xiyuyang19@fudan.edu.cn \
    --cc=yuanxzhang@fudan.edu.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox