linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arend Van Spriel <arend.vanspriel@broadcom.com>
To: Xinming Hu <huxinming820@gmail.com>,
	Linux Wireless <linux-wireless@vger.kernel.org>
Cc: Kalle Valo <kvalo@qca.qualcomm.com>,
	Brian Norris <briannorris@google.com>,
	Dmitry Torokhov <dtor@google.com>,
	rajatja@google.com, Zhiyuan Yang <yangzy@marvell.com>,
	Cathy Luo <cluo@marvell.com>, Xinming Hu <huxm@marvell.com>
Subject: Re: [PATCH 2/6] mwifiex: usb: urb->context sanity check in complete handler
Date: Wed, 3 May 2017 20:51:45 +0200	[thread overview]
Message-ID: <af056a38-7fc7-0bb5-d43c-41fa6cc10df9@broadcom.com> (raw)
In-Reply-To: <1493812123-12053-2-git-send-email-huxinming820@gmail.com>

On 3-5-2017 13:48, Xinming Hu wrote:
> From: Xinming Hu <huxm@marvell.com>
> 
> urb/context might be freed in cornel case, add sanity check to avoid
> use-after-free.
> 
> Signed-off-by: Xinming Hu <huxm@marvell.com>
> ---
>  drivers/net/wireless/marvell/mwifiex/usb.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/net/wireless/marvell/mwifiex/usb.c b/drivers/net/wireless/marvell/mwifiex/usb.c
> index 2f7705c..ee5f488 100644
> --- a/drivers/net/wireless/marvell/mwifiex/usb.c
> +++ b/drivers/net/wireless/marvell/mwifiex/usb.c
> @@ -169,6 +169,11 @@ static void mwifiex_usb_rx_complete(struct urb *urb)
>  	int recv_length = urb->actual_length;
>  	int size, status;
>  
> +	if (!urb || !urb->context) {
> +		pr_err("URB or URB context is not valid in USB Rx complete\n");
> +		return;
> +	}

Something is really off if you need !urb here. Furthermore, you are
already initializing stack variables using fields inside the urb before
this check causing a null-deref so it is bogus anyway. The completion
function is a member in struct urb. If your driver has a list of these
urb's somewhere and they are free in parallel then your design is wrong
and this does not solve the use-after-free. The urb here will not be
NULL and still points to the old memory location as it was handed to the
usb subsystem. That piece of memory might already been handed out to
some other piece of the kernel making any access to it invalid and
potentially crashing the kernel.

Regards,
Arend

  reply	other threads:[~2017-05-03 18:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-03 11:48 [PATCH 1/6] mwifiex: use variable interface header length Xinming Hu
2017-05-03 11:48 ` [PATCH 2/6] mwifiex: usb: urb->context sanity check in complete handler Xinming Hu
2017-05-03 18:51   ` Arend Van Spriel [this message]
2017-05-04  9:12     ` Xinming Hu
2017-05-03 11:48 ` [PATCH 3/6] mwifiex: usb: transmit aggregation packets Xinming Hu
2017-05-03 11:48 ` [PATCH 4/6] mwifiex: usb: add timer to flush " Xinming Hu
2017-05-03 11:48 ` [PATCH 5/6] mwifiex: do not aggregate tcp ack in usb tx aggregation queue Xinming Hu
2017-05-03 11:48 ` [PATCH 6/6] mwifiex: check next packet length for usb tx aggregation Xinming Hu

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=af056a38-7fc7-0bb5-d43c-41fa6cc10df9@broadcom.com \
    --to=arend.vanspriel@broadcom.com \
    --cc=briannorris@google.com \
    --cc=cluo@marvell.com \
    --cc=dtor@google.com \
    --cc=huxinming820@gmail.com \
    --cc=huxm@marvell.com \
    --cc=kvalo@qca.qualcomm.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=rajatja@google.com \
    --cc=yangzy@marvell.com \
    /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).