linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Skripkin <paskripkin@gmail.com>
To: Andrew Lunn <andrew@lunn.ch>
Cc: davem@davemloft.net, kuba@kernel.org, linux@rempel-privat.de,
	himadrispandya@gmail.com, linux-usb@vger.kernel.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	syzbot+a631ec9e717fb0423053@syzkaller.appspotmail.com
Subject: Re: [PATCH] net: asix: fix uninit value in asix_mdio_read
Date: Sat, 14 Aug 2021 01:29:05 +0300	[thread overview]
Message-ID: <22130c0e-5966-f76d-5ce1-f92ec4750155@gmail.com> (raw)
In-Reply-To: <YRbw1psAc8jQu4ob@lunn.ch>

On 8/14/21 1:23 AM, Andrew Lunn wrote:
> On Fri, Aug 13, 2021 at 07:01:08PM +0300, Pavel Skripkin wrote:
>> Syzbot reported uninit-value in asix_mdio_read(). The problem was in
>> missing error handling. asix_read_cmd() should initialize passed stack
>> variable smsr, but it can fail in some cases. Then while condidition
>> checks possibly uninit smsr variable.
>> 
>> Since smsr is uninitialized stack variable, driver can misbehave,
>> because smsr will be random in case of asix_read_cmd() failure.
>> Fix it by adding error cheking and just continue the loop instead of
>> checking uninit value.
>> 
>> Fixes: 8a46f665833a ("net: asix: Avoid looping when the device is disconnected")
>> Reported-and-tested-by: syzbot+a631ec9e717fb0423053@syzkaller.appspotmail.com
>> Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
>> ---
>>  drivers/net/usb/asix_common.c | 8 +++++++-
>>  1 file changed, 7 insertions(+), 1 deletion(-)
>> 
>> diff --git a/drivers/net/usb/asix_common.c b/drivers/net/usb/asix_common.c
>> index ac92bc52a85e..572ca3077f8f 100644
>> --- a/drivers/net/usb/asix_common.c
>> +++ b/drivers/net/usb/asix_common.c
>> @@ -479,7 +479,13 @@ int asix_mdio_read(struct net_device *netdev, int phy_id, int loc)
>>  		usleep_range(1000, 1100);
>>  		ret = asix_read_cmd(dev, AX_CMD_STATMNGSTS_REG,
>>  				    0, 0, 1, &smsr, 0);
>> -	} while (!(smsr & AX_HOST_EN) && (i++ < 30) && (ret != -ENODEV));
>> +		if (ret == -ENODEV) {
>> +			break;
>> +		} else if (ret < 0) {
>> +			++i;
>> +			continue;
>> +		}
>> +	} while (!(smsr & AX_HOST_EN) && (i++ < 30));
> 
> No ret < 0, don't you end up with a double increment of i? So it will
> only retry 15 times, not 30?
> 
> Humm.
> 
> If ret < 0 is true, smsr is uninitialized? The continue statement
> causes a jump into the condition expression, where we evaluate smsr &
> AX_HOST_EN. Isn't this just as broken as the original version?
> 
>        Andrew
> 

Yes, you are right, I missed that, sorry. I will rewrote this loop into 
for loop in v2.

Im wondering why this wrong patch passed KMSAN testing...



With regards,
Pavel Skripkin

  reply	other threads:[~2021-08-13 22:29 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-13 16:01 [PATCH] net: asix: fix uninit value in asix_mdio_read Pavel Skripkin
2021-08-13 22:23 ` Andrew Lunn
2021-08-13 22:29   ` Pavel Skripkin [this message]
2021-08-13 22:42   ` [PATCH v2] " Pavel Skripkin
2021-08-13 22:52     ` Jakub Kicinski
2021-08-14 13:55       ` [PATCH v3] net: asix: fix uninit value bugs Pavel Skripkin
2021-08-14 15:36         ` Andrew Lunn
2021-08-14 15:40           ` Pavel Skripkin
2021-08-14 16:20           ` Pavel Skripkin
2021-08-17 16:37           ` [PATCH v4] " Pavel Skripkin
2021-08-18 10:50             ` patchwork-bot+netdevbpf
2021-08-13 22:57     ` [PATCH v2] net: asix: fix uninit value in asix_mdio_read Andrew Lunn

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=22130c0e-5966-f76d-5ce1-f92ec4750155@gmail.com \
    --to=paskripkin@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=himadrispandya@gmail.com \
    --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=syzbot+a631ec9e717fb0423053@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).