From: "ira.weiny" <ira.weiny-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
To: Jason Gunthorpe
<jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
Cc: Dennis Dalessandro
<dennis.dalessandro-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
Mike Marciniszyn
<mike.marciniszyn-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Mitko Haralanov
<mitko.haralanov-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v2 3/5] IB/hfi1: Add ioctl() interface for user commands
Date: Fri, 13 May 2016 16:54:01 -0400 [thread overview]
Message-ID: <20160513205400.GA25995@phlsvsds.ph.intel.com> (raw)
In-Reply-To: <20160512194006.GA6364-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
On Thu, May 12, 2016 at 01:40:06PM -0600, Jason Gunthorpe wrote:
> On Thu, May 12, 2016 at 03:27:27PM -0400, Dennis Dalessandro wrote:
>
> > >>+static inline int check_ioctl_access(unsigned int cmd, unsigned long arg)
> > >>+{
> > >>+ int read_cmd, write_cmd, read_ok, write_ok;
> > >>+
> > >>+ read_cmd = _IOC_DIR(cmd) & _IOC_READ;
> > >>+ write_cmd = _IOC_DIR(cmd) & _IOC_WRITE;
> > >>+ write_ok = access_ok(VERIFY_WRITE, (void __user *)arg, _IOC_SIZE(cmd));
> > >>+ read_ok = access_ok(VERIFY_READ, (void __user *)arg, _IOC_SIZE(cmd));
> > >>+
> > >>+ if ((read_cmd && !write_ok) || (write_cmd && !read_ok))
> > >>+ return -EFAULT;
> > >
> > >This seems kind of goofy, didn't Ira say this is performance senstive?
>
> Well, calling access_ok twice when only once is typically needed is
> certainly not performant. Typically this check is done at every access
> via get_user/put_user/copy_to/from_user - why is it being hoisted like
> this?
>
>
> > >Driver shouldn't be open coding __get_user like that, IMHO.
> >
> > Can you explain what you mean here? We should not use __get_user()?
>
> Generally speaking, yes. Use get_user() that includes the correct
> access_ok. Unless there is a good reason to avoid it, the standard API
> should be used.
I know this code was refactored while we were still submitting patches to Greg
KH back in Nov/Dec. Part of this was cleaning up branch on error rather than
success. Hence the check for access at the top of the function and early
return.
At that time I _thought_ there were multiple __get_users in some of the
operations so a single common access_ok would speed those up. However, I don't
see that happening any longer, so either I don't remember correctly, or we have
made this cleaner.
As it stands now I think you are correct we could use get_user and
copy_to/from_user.
Ira
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
WARNING: multiple messages have this Message-ID (diff)
From: "ira.weiny" <ira.weiny@intel.com>
To: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Cc: Dennis Dalessandro <dennis.dalessandro@intel.com>,
dledford@redhat.com,
Mike Marciniszyn <mike.marciniszyn@intel.com>,
linux-rdma@vger.kernel.org,
Mitko Haralanov <mitko.haralanov@intel.com>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH v2 3/5] IB/hfi1: Add ioctl() interface for user commands
Date: Fri, 13 May 2016 16:54:01 -0400 [thread overview]
Message-ID: <20160513205400.GA25995@phlsvsds.ph.intel.com> (raw)
In-Reply-To: <20160512194006.GA6364@obsidianresearch.com>
On Thu, May 12, 2016 at 01:40:06PM -0600, Jason Gunthorpe wrote:
> On Thu, May 12, 2016 at 03:27:27PM -0400, Dennis Dalessandro wrote:
>
> > >>+static inline int check_ioctl_access(unsigned int cmd, unsigned long arg)
> > >>+{
> > >>+ int read_cmd, write_cmd, read_ok, write_ok;
> > >>+
> > >>+ read_cmd = _IOC_DIR(cmd) & _IOC_READ;
> > >>+ write_cmd = _IOC_DIR(cmd) & _IOC_WRITE;
> > >>+ write_ok = access_ok(VERIFY_WRITE, (void __user *)arg, _IOC_SIZE(cmd));
> > >>+ read_ok = access_ok(VERIFY_READ, (void __user *)arg, _IOC_SIZE(cmd));
> > >>+
> > >>+ if ((read_cmd && !write_ok) || (write_cmd && !read_ok))
> > >>+ return -EFAULT;
> > >
> > >This seems kind of goofy, didn't Ira say this is performance senstive?
>
> Well, calling access_ok twice when only once is typically needed is
> certainly not performant. Typically this check is done at every access
> via get_user/put_user/copy_to/from_user - why is it being hoisted like
> this?
>
>
> > >Driver shouldn't be open coding __get_user like that, IMHO.
> >
> > Can you explain what you mean here? We should not use __get_user()?
>
> Generally speaking, yes. Use get_user() that includes the correct
> access_ok. Unless there is a good reason to avoid it, the standard API
> should be used.
I know this code was refactored while we were still submitting patches to Greg
KH back in Nov/Dec. Part of this was cleaning up branch on error rather than
success. Hence the check for access at the top of the function and early
return.
At that time I _thought_ there were multiple __get_users in some of the
operations so a single common access_ok would speed those up. However, I don't
see that happening any longer, so either I don't remember correctly, or we have
made this cleaner.
As it stands now I think you are correct we could use get_user and
copy_to/from_user.
Ira
next prev parent reply other threads:[~2016-05-13 20:54 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-12 17:18 [PATCH v2 0/5] IB/hfi1: Remove write() and use ioctl() for user access Dennis Dalessandro
2016-05-12 17:18 ` Dennis Dalessandro
2016-05-12 17:18 ` [PATCH v2 1/5] IB/hfi1: Export drivers user sw version via sysfs Dennis Dalessandro
2016-05-12 17:18 ` [PATCH v2 2/5] IB/hfi1: Remove unused user command Dennis Dalessandro
2016-05-12 17:18 ` [PATCH v2 3/5] IB/hfi1: Add ioctl() interface for user commands Dennis Dalessandro
[not found] ` <20160512171846.6198.31415.stgit-9QXIwq+3FY+1XWohqUldA0EOCMrvLtNR@public.gmane.org>
2016-05-12 17:43 ` Jason Gunthorpe
2016-05-12 17:43 ` Jason Gunthorpe
[not found] ` <20160512174332.GB13553-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-05-12 18:12 ` Hefty, Sean
2016-05-12 18:12 ` Hefty, Sean
2016-05-12 19:27 ` Dennis Dalessandro
2016-05-12 19:27 ` Dennis Dalessandro
2016-05-12 19:40 ` Jason Gunthorpe
[not found] ` <20160512194006.GA6364-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-05-12 19:48 ` Doug Ledford
2016-05-12 19:48 ` Doug Ledford
[not found] ` <f96bfe93-6bcc-7d55-8f7a-1792d12d41d9-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-05-12 21:28 ` Jason Gunthorpe
2016-05-12 21:28 ` Jason Gunthorpe
2016-05-13 14:33 ` Dennis Dalessandro
2016-05-13 20:54 ` ira.weiny [this message]
2016-05-13 20:54 ` ira.weiny
2016-05-12 17:18 ` [PATCH v2 4/5] IB/hfi1: Remove write(), use ioctl() for user cmds Dennis Dalessandro
2016-05-12 17:18 ` [PATCH v2 5/5] IB/hfi1: Add trace message in user IOCTL handling Dennis Dalessandro
[not found] ` <20160512171115.6198.77458.stgit-9QXIwq+3FY+1XWohqUldA0EOCMrvLtNR@public.gmane.org>
2016-05-12 17:34 ` [PATCH v2 0/5] IB/hfi1: Remove write() and use ioctl() for user access Jason Gunthorpe
2016-05-12 17:34 ` Jason Gunthorpe
2016-05-12 19:07 ` Dennis Dalessandro
2016-05-12 19:25 ` Jason Gunthorpe
[not found] ` <20160512192508.GA17319-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-05-12 19:53 ` Dennis Dalessandro
2016-05-12 19:53 ` Dennis Dalessandro
[not found] ` <20160512195304.GA10419-W4f6Xiosr+yv7QzWx2u06xL4W9x8LtSr@public.gmane.org>
2016-05-12 20:31 ` Doug Ledford
2016-05-12 20:31 ` Doug Ledford
2016-05-12 21:27 ` Jason Gunthorpe
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=20160513205400.GA25995@phlsvsds.ph.intel.com \
--to=ira.weiny-ral2jqcrhueavxtiumwx3w@public.gmane.org \
--cc=dennis.dalessandro-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org \
--cc=linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mike.marciniszyn-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=mitko.haralanov-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.