netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Pavel Skripkin <paskripkin@gmail.com>
Cc: davem@davemloft.net, kuba@kernel.org, linux@rempel-privat.de,
	andrew@lunn.ch, oneukum@suse.com, robert.foss@collabora.com,
	linux-usb@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	syzbot+6ca9f7867b77c2d316ac@syzkaller.appspotmail.com,
	Oleksij Rempel <o.rempel@pengutronix.de>
Subject: Re: [PATCH net-next] net: asix: add proper error handling of usb read errors
Date: Mon, 7 Feb 2022 11:27:26 +0100	[thread overview]
Message-ID: <YgD0Dln2R0dPJX/L@kroah.com> (raw)
In-Reply-To: <20220206180516.28439-1-paskripkin@gmail.com>

On Sun, Feb 06, 2022 at 09:05:16PM +0300, Pavel Skripkin wrote:
> Syzbot once again hit uninit value in asix driver. The problem still the
> same -- asix_read_cmd() reads less bytes, than was requested by caller.
> 
> Since all read requests are performed via asix_read_cmd() let's catch
> usb related error there and add __must_check notation to be sure all
> callers actually check return value.
> 
> So, this patch adds sanity check inside asix_read_cmd(), that simply
> checks if bytes read are not less, than was requested and adds missing
> error handling of asix_read_cmd() all across the driver code.
> 
> Fixes: d9fe64e51114 ("net: asix: Add in_pm parameter")
> Reported-and-tested-by: syzbot+6ca9f7867b77c2d316ac@syzkaller.appspotmail.com
> Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
> Tested-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
> 
> Changes since RFT:
> 	- Added Tested-by: tag
> 
> ---
>  drivers/net/usb/asix.h         |  4 ++--
>  drivers/net/usb/asix_common.c  | 19 +++++++++++++------
>  drivers/net/usb/asix_devices.c | 21 ++++++++++++++++++---
>  3 files changed, 33 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/net/usb/asix.h b/drivers/net/usb/asix.h
> index 2a1e31def..4334aafab 100644
> --- a/drivers/net/usb/asix.h
> +++ b/drivers/net/usb/asix.h
> @@ -192,8 +192,8 @@ extern const struct driver_info ax88172a_info;
>  /* ASIX specific flags */
>  #define FLAG_EEPROM_MAC		(1UL << 0)  /* init device MAC from eeprom */
>  
> -int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
> -		  u16 size, void *data, int in_pm);
> +int __must_check asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
> +			       u16 size, void *data, int in_pm);
>  
>  int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
>  		   u16 size, void *data, int in_pm);
> diff --git a/drivers/net/usb/asix_common.c b/drivers/net/usb/asix_common.c
> index 71682970b..524805285 100644
> --- a/drivers/net/usb/asix_common.c
> +++ b/drivers/net/usb/asix_common.c
> @@ -11,8 +11,8 @@
>  
>  #define AX_HOST_EN_RETRIES	30
>  
> -int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
> -		  u16 size, void *data, int in_pm)
> +int __must_check asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
> +			       u16 size, void *data, int in_pm)
>  {
>  	int ret;
>  	int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16);
> @@ -27,9 +27,12 @@ int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
>  	ret = fn(dev, cmd, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
>  		 value, index, data, size);
>  
> -	if (unlikely(ret < 0))
> +	if (unlikely(ret < size)) {
> +		ret = ret < 0 ? ret : -ENODATA;
> +

Didn't I suggest using the proper USB core functions for this instead of
rolling your own functions?  We now have usb_control_msg_read() and
usb_control_msg_send() that prevents this type of thing from happening.

Ah, it's a bit more tangled up than that it seems, the number of layers
of abstractions here is odd and deep.  This change looks fine for now to
keep syzbot happy:

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

  reply	other threads:[~2022-02-07 10:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-05 13:19 [PATCH RFT] net: asix: add proper error handling of usb read errors Pavel Skripkin
2022-01-05 14:15 ` Oleksij Rempel
2022-01-17 19:31 ` Pavel Skripkin
2022-01-18  6:18   ` Greg KH
2022-01-18 19:00     ` Pavel Skripkin
2022-02-06 17:23 ` Pavel Skripkin
2022-02-06 17:48   ` Oleksij Rempel
2022-02-06 18:05     ` [PATCH net-next] " Pavel Skripkin
2022-02-07 10:27       ` Greg KH [this message]
2022-02-07 12:30       ` patchwork-bot+netdevbpf

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=YgD0Dln2R0dPJX/L@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux@rempel-privat.de \
    --cc=netdev@vger.kernel.org \
    --cc=o.rempel@pengutronix.de \
    --cc=oneukum@suse.com \
    --cc=paskripkin@gmail.com \
    --cc=robert.foss@collabora.com \
    --cc=syzbot+6ca9f7867b77c2d316ac@syzkaller.appspotmail.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).