From: Wang Cheng <wanngchenng@gmail.com>
To: Pavel Skripkin <paskripkin@gmail.com>
Cc: dan.carpenter@oracle.com, linux-staging@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 1/3] staging: rtl8712: fix uninit-value in usb_read8() and friends
Date: Tue, 10 May 2022 11:34:25 +0800 [thread overview]
Message-ID: <20220510033425.6uzanqtejdlmtwl2@ppc.localdomain> (raw)
In-Reply-To: <dba1acfa-1e82-7b6b-928a-beff18c51f5b@gmail.com>
On 22/05/06 03:12PM, Pavel Skripkin wrote:
> Hi Wang,
>
> On 5/6/22 14:59, Wang Cheng wrote:
> > Reported-and-tested-by: syzbot+6f5ecd144854c0d8580b@syzkaller.appspotmail.com
> > Signed-off-by: Wang Cheng <wanngchenng@gmail.com>
> > ---
> > drivers/staging/rtl8712/usb_ops.c | 27 ++++++++++++++++++---------
> > 1 file changed, 18 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/staging/rtl8712/usb_ops.c b/drivers/staging/rtl8712/usb_ops.c
> > index e64845e6adf3..af9966d03979 100644
> > --- a/drivers/staging/rtl8712/usb_ops.c
> > +++ b/drivers/staging/rtl8712/usb_ops.c
> > @@ -29,7 +29,8 @@ static u8 usb_read8(struct intf_hdl *intfhdl, u32 addr)
> > u16 wvalue;
> > u16 index;
> > u16 len;
> > - __le32 data;
> > + int status;
> > + __le32 data = 0;
> > struct intf_priv *intfpriv = intfhdl->pintfpriv;
> > request = 0x05;
> > @@ -37,8 +38,10 @@ static u8 usb_read8(struct intf_hdl *intfhdl, u32 addr)
> > index = 0;
> > wvalue = (u16)(addr & 0x0000ffff);
> > len = 1;
> > - r8712_usbctrl_vendorreq(intfpriv, request, wvalue, index, &data, len,
> > - requesttype);
> > + status = r8712_usbctrl_vendorreq(intfpriv, request, wvalue, index,
> > + &data, len, requesttype);
> > + if (status < 0)
> > + return 0;
>
> Wait, but what about partial reads? I see that r8712_usbctrl_vendorreq()
> uses `usb_control_msg()` which can read less data than was requested.
>
> So here you are just hiding these error by zeroing data
>
> > return (u8)(le32_to_cpu(data) & 0x0ff);
> > }
>
> And as i said in previous email: caller can't see an error.
>
> Imagine caller waits for some register to become 0. Caller sees that
> usb_read8() returned 0. Is it an error? Is register really become 0?
>
>
> Generic read API prototype looks like following:
>
> int read_something(struct my_cool_dev *dev, void *data, size_t size);
>
> and it returns 0 on success and -errno on failure and data returned via
> passed pointer. So, if API returned an error caller should not touch @data,
> since likely it's uninitialized
Thank you for your remind, sorry I didnt understand your previous reply
about "register and 0" that you explain very clearly above. I am thinking
about it standing on that the return type of usb_read8() is u8.
thanks,
- w
next prev parent reply other threads:[~2022-05-10 3:38 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-06 11:59 [PATCH v3 0/3] staging: rtl8712: fix KMSAN: uninit-value in r871xu_drv_init Wang Cheng
2022-05-06 11:59 ` [PATCH v3 1/3] staging: rtl8712: fix uninit-value in usb_read8() and friends Wang Cheng
2022-05-06 12:12 ` Pavel Skripkin
2022-05-10 3:34 ` Wang Cheng [this message]
2022-05-06 11:59 ` [PATCH v3 2/3] staging: rtl8712: fix uninit-value in r871xu_drv_init() Wang Cheng
2022-05-06 12:27 ` Pavel Skripkin
2022-05-06 12:35 ` Pavel Skripkin
2022-05-06 12:01 ` [PATCH v3 3/3] staging: rtl8712: add error handler in r8712_usbctrl_vendorreq() Wang Cheng
2022-05-06 12:13 ` Pavel Skripkin
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=20220510033425.6uzanqtejdlmtwl2@ppc.localdomain \
--to=wanngchenng@gmail.com \
--cc=dan.carpenter@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=paskripkin@gmail.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
all inboxes | Powered by JetHome®