From: Dan Carpenter <dan.carpenter@linaro.org>
To: Su Hui <suhui@nfschina.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
YongSu Yoo <yongsuyoo0215@gmail.com>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] media: dvb_ringbuffer: Return -EFAULT if copy fails
Date: Wed, 24 May 2023 07:47:15 +0300 [thread overview]
Message-ID: <41a9c6a6-4b9a-4d84-9e32-09bf64c65b6c@kili.mountain> (raw)
In-Reply-To: <7af16b9a-09d1-46ff-b9f9-c178173cf940@kili.mountain>
On Wed, May 24, 2023 at 07:23:45AM +0300, Dan Carpenter wrote:
> On Wed, May 24, 2023 at 09:27:33AM +0800, Su Hui wrote:
> > The copy_to/from_user() functions return the number of bytes remaining
> > to be copied, but we want to return -EFAULT to the user.
> >
So basically these bugs are caused because people are used to functions
returning negative error codes and they write some form of:
ret = copy_from_user();
if (ret)
return ret;
If you look at the code and you think, "They author thinks 'ret' is
negative" then probably it is a bug. The common false positives are
in the core kernel where it does:
return copy_from_user();
and the caller checks:
if (function_one() || function_two() || function_three())
return -EFAULT;
Those are done because it's a fast path and adding a lot of if
statements would slow things down. Driver code tends not to do this
because normally drivers are not so performance sensitive and it's more
important to be readable.
So you have to look at the context a bit.
regards,
dan carpenter
next prev parent reply other threads:[~2023-05-24 4:47 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-24 1:27 Su Hui
2023-05-24 4:23 ` Dan Carpenter
2023-05-24 4:47 ` Dan Carpenter [this message]
2023-05-24 5:20 ` Su Hui
2023-05-24 7:20 ` Dan Carpenter
2023-05-24 8:23 ` Longsuhui
2023-05-26 10:45 ` Mauro Carvalho Chehab
2023-05-29 1:08 ` Longsuhui
2023-05-29 1:54 ` Su Hui
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=41a9c6a6-4b9a-4d84-9e32-09bf64c65b6c@kili.mountain \
--to=dan.carpenter@linaro.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=suhui@nfschina.com \
--cc=yongsuyoo0215@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®