mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Oliver Neukum <oneukum@suse.com>
To: Dan Carpenter <dan.carpenter@oracle.com>,
	Oliver Neukum <oneukum@suse.com>
Cc: David Kahurani <k.kahurani@gmail.com>,
	netdev@vger.kernel.org,
	syzbot <syzbot+d3dbdf31fbe9d8f5f311@syzkaller.appspotmail.com>,
	davem@davemloft.net, jgg@ziepe.ca, kuba@kernel.org,
	linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
	Phillip Potter <phil@philpotter.co.uk>,
	syzkaller-bugs@googlegroups.com, arnd@arndb.de,
	Pavel Skripkin <paskripkin@gmail.com>
Subject: Re: [PATCH] net: ax88179: add proper error handling of usb read errors
Date: Thu, 14 Apr 2022 11:13:25 +0200	[thread overview]
Message-ID: <0ece0ee4-baca-bff6-89e0-ad10483a5f8e@suse.com> (raw)
In-Reply-To: <20220414082115.GA12805@kadam>



On 14.04.22 10:21, Dan Carpenter wrote:
> On Thu, Apr 14, 2022 at 09:31:56AM +0200, Oliver Neukum wrote:
>>
>> On 13.04.22 17:32, Dan Carpenter wrote:
>>> Bug: buffer partially filled.  Information leak.
>>>
>>> If you return the bytes then the only correct way to write error
>>> handling is:
>>>
>>> 	if (ret < 0)
>>> 		return ret;
>>> 	if (ret != size)
>>> 		return -EIO;
>>>
>> You have to make up your mind on whether you ever need to read
>> answer of a length not known before you try it. The alternative of
>> passing a pointer to an integer for length is worse.
> How is it worse?  Can you give an example, so I will write a static
> checker rule for it?
My favorite example would be:

int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
                void *data, int len, int *actual_length, int timeout)

The actual_length parameter is horrible. Now, there are situations like this
where this pattern is unavoidable, because in addition to an error you
can get a partial completion of an operation.

Do I see it correctly that you would prefer this pattern even if
you could report either an error or a result in the function?
> There used to be more APIs that consistently caused bug after bug where
> we mixed positives success values with negative error codes.  We
> converted some bad offenders to return the positive as a parameter
> and I was really happy about that.
>
> Another example I used to see a lot is request_irq() saved to an
> unsigned.  These days I think GCC warns about that?  Maybe the build
> bots get to it before I do.
>
That needs to be checked for.. In fact while we are at it, do we check
for integer overflows?

    Regards
        Oliver


  reply	other threads:[~2022-04-14  9:13 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-04 15:10 David Kahurani
2022-04-04 15:31 ` Dan Carpenter
2022-04-13 12:36   ` David Kahurani
2022-04-13 15:32     ` Dan Carpenter
2022-04-14  7:31       ` Oliver Neukum
2022-04-14  8:21         ` Dan Carpenter
2022-04-14  9:13           ` Oliver Neukum [this message]
2022-04-04 16:50 ` Pavel Skripkin
2022-04-11 15:11   ` Andy Shevchenko
2022-04-05  9:44 ` Paolo Abeni
2022-04-05 20:44 ` kernel test robot
2022-04-16  7:48 David Kahurani
2022-04-16 11:05 ` Pavel Skripkin
2022-04-16 11:10 ` Pavel Skripkin
2022-04-16 11:49   ` David Kahurani
2022-04-16 11:53     ` Pavel Skripkin
2022-04-16 11:57       ` Pavel Skripkin
2022-04-19 13:41 ` Paolo Abeni
2022-05-14 13:32 David Kahurani
2022-05-14 16:51 ` Pavel Skripkin
2022-05-14 18:54   ` Dan Carpenter
2022-05-14 18:57     ` Pavel Skripkin
2022-05-16 19:31 ` Jakub Kicinski

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=0ece0ee4-baca-bff6-89e0-ad10483a5f8e@suse.com \
    --to=oneukum@suse.com \
    --cc=arnd@arndb.de \
    --cc=dan.carpenter@oracle.com \
    --cc=davem@davemloft.net \
    --cc=jgg@ziepe.ca \
    --cc=k.kahurani@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=paskripkin@gmail.com \
    --cc=phil@philpotter.co.uk \
    --cc=syzbot+d3dbdf31fbe9d8f5f311@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.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®