Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1669940
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!news.servidellagleba.it!bofh.it!news.nic.it!robomod |
|---|---|
| From | Al Viro <viro@ZenIV.linux.org.uk> |
| Newsgroups | linux.kernel |
| Subject | Re: __user with scalar data types |
| Date | Mon, 19 Jun 2017 22:50:02 +0200 |
| Message-ID | <tUbMu-7Ag-33@gated-at.bofh.it> (permalink) |
| References | <tU7ze-4Y3-59@gated-at.bofh.it> <tUbCO-7vX-19@gated-at.bofh.it> |
| X-Original-To | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Disposition | inline |
| User-Agent | Mutt/1.8.0 (2017-02-23) |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 56 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | linux-sparse@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org |
| X-Original-Date | Mon, 19 Jun 2017 21:46:37 +0100 |
| X-Original-Message-ID | <20170619204637.GJ10672@ZenIV.linux.org.uk> |
| X-Original-References | <20170619161509.GA25997@jcrouse-lnx.qualcomm.com> <20170619203217.yj55siq433mt2x5i@ltop.local> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1669940 |
Show key headers only | View raw
On Mon, Jun 19, 2017 at 10:32:18PM +0200, Luc Van Oostenryck wrote:
> On Mon, Jun 19, 2017 at 10:15:09AM -0600, Jordan Crouse wrote:
> > struct uapistruct {
> > ...
> > __u64 __user myptr;
> > ---
> > };
> >
> > And then converting it for use in the kernel as such:
> >
> > {
> > void __user *userptr = (void __user *)(uintptr_t)args->myptr;
> >
> > copy_from_user(local, userptr, size);
> > ...
> > }
> >
> > The problem is that sparse doesn't like the momentary switch to
> > uintptr_t:
> >
> > warning: dereference of noderef expression
>
> This warning doesn't come from the cast to uintptr_t but
> simply from dereferencing the field which can't be dereferenced
> since it's marked as '__user'. In other words, doing
> 'args->myptr' rightfully trigger the warning and no cast
> will or should stop that.
>
> Also, you can't expect the '__user' to be transmitted from
> 'myptr' to the pointer (without taking the address of 'myptr').
> It's exactly like 'const int' vs. 'const int *': the '__user' or
> the 'const' is not at the same level in the type hierarchy
> ('const object' vs. 'non-const pointer to const object').
Besides, suppose you add a special type for that. How would it
have to behave, really? AFAICS, you want something similar to
__bitwise, except that (assuming this type is T)
T + integer => T
T - integer => T
T & integer => integer
T | integer => T
T - T => integer (quietly decay to underlying type for both
arguments, then treat as normal -)
T & T => T (probably, but might be worth a warning)
T | T => T (ditto)
comparison - same as for __bitwise
constant conversion: 0 should convert clean, anything else - a warning
cast to pointer => warn unless the target type is __user? But that's
not going to help with cast through uintptr_t...
?: as usual
any other arithmetics => warn and decay to underlying integer type
It might be not impossible to implement, but it sure as hell won't be __user
and it'll need careful thinking about the semantics of those annotations.
The outline above is just that - figuring out if there are any nasty corner
cases will take some work.
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
__user with scalar data types Jordan Crouse <jcrouse@codeaurora.org> - 2017-06-19 18:20 +0200
Re: __user with scalar data types Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-19 18:40 +0200
Re: __user with scalar data types Daniel Vetter <daniel@ffwll.ch> - 2017-06-20 09:20 +0200
Re: __user with scalar data types Gerd Hoffmann <kraxel@redhat.com> - 2017-06-20 09:50 +0200
Re: __user with scalar data types Daniel Vetter <daniel@ffwll.ch> - 2017-06-20 10:40 +0200
Re: __user with scalar data types Luc Van Oostenryck <luc.vanoostenryck@gmail.com> - 2017-06-19 21:30 +0200
Re: __user with scalar data types Luc Van Oostenryck <luc.vanoostenryck@gmail.com> - 2017-06-19 22:40 +0200
Re: __user with scalar data types Al Viro <viro@ZenIV.linux.org.uk> - 2017-06-19 22:50 +0200
Re: __user with scalar data types Luc Van Oostenryck <luc.vanoostenryck@gmail.com> - 2017-06-20 00:40 +0200
csiph-web