linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: Natalia Petrova <n.petrova@fintech.ru>
Cc: Andreas Noever <andreas.noever@gmail.com>,
	Michael Jamet <michael.jamet@intel.com>,
	Yehezkel Bernat <YehezkelShB@gmail.com>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	lvc-project@linuxtesting.org
Subject: Re: [PATCH] thunderbolt_tb: add check for return value of 'tb_switch_find_port'
Date: Fri, 17 Feb 2023 15:41:56 +0200	[thread overview]
Message-ID: <Y++EJArOnOenkZxw@black.fi.intel.com> (raw)
In-Reply-To: <20230217132432.487106-1-n.petrova@fintech.ru>

Hi,

On Fri, Feb 17, 2023 at 04:24:32PM +0300, Natalia Petrova wrote:
> Return value of 'tb_switch_find_port' has to be checked to avoid
> null pointer dereferences in functions tb_tunnel_alloc_dma() and

NULL

> tb_port_info().
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: 386e5e29d81c ("thunderbolt: Make tb_find_port() available to other files")
> Signed-off-by: Natalia Petrova <n.petrova@fintech.ru>
> ---
>  drivers/thunderbolt/tb.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c
> index 9853f6c7e81d..5d6cded68d46 100644
> --- a/drivers/thunderbolt/tb.c
> +++ b/drivers/thunderbolt/tb.c
> @@ -1156,6 +1156,8 @@ static int tb_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
>  	sw = tb_to_switch(xd->dev.parent);
>  	dst_port = tb_port_at(xd->route, sw);
>  	nhi_port = tb_switch_find_port(tb->root_switch, TB_TYPE_NHI);
> +	if (!nhi_port)

This really cannot happen in real life. All host routers must have a
host interface adapter so I'm not sure if adding these checks do
anything else than adding dead code.

> +		return -EIO;
>  
>  	mutex_lock(&tb->lock);
>  	tunnel = tb_tunnel_alloc_dma(tb, nhi_port, dst_port, transmit_path,
> -- 
> 2.34.1

      reply	other threads:[~2023-02-17 13:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-17 13:24 [PATCH] thunderbolt_tb: add check for return value of 'tb_switch_find_port' Natalia Petrova
2023-02-17 13:41 ` Mika Westerberg [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=Y++EJArOnOenkZxw@black.fi.intel.com \
    --to=mika.westerberg@linux.intel.com \
    --cc=YehezkelShB@gmail.com \
    --cc=andreas.noever@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=michael.jamet@intel.com \
    --cc=n.petrova@fintech.ru \
    /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;
as well as URLs for NNTP newsgroup(s).