Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1400261

Re: [PATCH v2 3/5] IB/hfi1: Add ioctl() interface for user commands

From Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Newsgroups linux.kernel
Subject Re: [PATCH v2 3/5] IB/hfi1: Add ioctl() interface for user commands
Date 2016-05-12 19:50 +0200
Message-ID <ry2Uh-24P-3@gated-at.bofh.it> (permalink)
References <ry2rf-1NT-3@gated-at.bofh.it> <ry2rg-1NT-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Thu, May 12, 2016 at 10:18:47AM -0700, Dennis Dalessandro wrote:
> +	case HFI1_IOCTL_EP_INFO:
> +	case HFI1_IOCTL_EP_ERASE_CHIP:
> +	case HFI1_IOCTL_EP_ERASE_RANGE:
> +	case HFI1_IOCTL_EP_READ_RANGE:
> +	case HFI1_IOCTL_EP_WRITE_RANGE:
> +		if (!capable(CAP_SYS_ADMIN))
> +			return -EPERM;
> +		if (copy_from_user(&ucmd,
> +				   (struct hfi11_cmd __user *)arg,
> +				   sizeof(ucmd)))
> +			return -EFAULT;
> +		return handle_eprom_command(fp, &ucmd);

I thought we agreed to get rid of this as well? It certainly does not
belong here, and as a general rule, I don't think ioctls should be
doing capable tests..

> +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?

Driver shouldn't be open coding __get_user like that, IMHO.

> +#define HFI1_IOCTL_RECV_CTRL \
> +	_IOW(IB_IOCTL_MAGIC, HFI1_CMD_RECV_CTRL, int)

Have you audited this? Confused why this is marked IOW when I see
this:

+       case HFI1_IOCTL_RECV_CTRL:
+               ret = __get_user(uval, (int __user *)arg);

Seeing many other examples.

I stopped looking again

Jason

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2 0/5] IB/hfi1: Remove write() and use ioctl() for user  access Dennis Dalessandro <dennis.dalessandro@intel.com> - 2016-05-12 19:20 +0200
  [PATCH v2 3/5] IB/hfi1: Add ioctl() interface for user commands Dennis Dalessandro <dennis.dalessandro@intel.com> - 2016-05-12 19:20 +0200
    Re: [PATCH v2 3/5] IB/hfi1: Add ioctl() interface for user commands Jason Gunthorpe <jgunthorpe@obsidianresearch.com> - 2016-05-12 19:50 +0200
      RE: [PATCH v2 3/5] IB/hfi1: Add ioctl() interface for user commands "Hefty, Sean" <sean.hefty@intel.com> - 2016-05-12 20:20 +0200
      Re: [PATCH v2 3/5] IB/hfi1: Add ioctl() interface for user commands Dennis Dalessandro <dennis.dalessandro@intel.com> - 2016-05-12 21:30 +0200
        Re: [PATCH v2 3/5] IB/hfi1: Add ioctl() interface for user commands Jason Gunthorpe <jgunthorpe@obsidianresearch.com> - 2016-05-12 21:50 +0200
          Re: [PATCH v2 3/5] IB/hfi1: Add ioctl() interface for user commands Doug Ledford <dledford@redhat.com> - 2016-05-12 21:50 +0200
            Re: [PATCH v2 3/5] IB/hfi1: Add ioctl() interface for user commands Jason Gunthorpe <jgunthorpe@obsidianresearch.com> - 2016-05-12 23:30 +0200
              Re: [PATCH v2 3/5] IB/hfi1: Add ioctl() interface for user commands Dennis Dalessandro <dennis.dalessandro@intel.com> - 2016-05-13 16:40 +0200
          Re: [PATCH v2 3/5] IB/hfi1: Add ioctl() interface for user commands "ira.weiny" <ira.weiny@intel.com> - 2016-05-13 23:00 +0200
  [PATCH v2 1/5] IB/hfi1: Export drivers user sw version via sysfs Dennis Dalessandro <dennis.dalessandro@intel.com> - 2016-05-12 19:20 +0200
  [PATCH v2 2/5] IB/hfi1: Remove unused user command Dennis Dalessandro <dennis.dalessandro@intel.com> - 2016-05-12 19:20 +0200
  [PATCH v2 4/5] IB/hfi1: Remove write(), use ioctl() for user cmds Dennis Dalessandro <dennis.dalessandro@intel.com> - 2016-05-12 19:20 +0200
  [PATCH v2 5/5] IB/hfi1: Add trace message in user IOCTL handling Dennis Dalessandro <dennis.dalessandro@intel.com> - 2016-05-12 19:20 +0200
  Re: [PATCH v2 0/5] IB/hfi1: Remove write() and use ioctl() for user  access Jason Gunthorpe <jgunthorpe@obsidianresearch.com> - 2016-05-12 19:40 +0200
    Re: [PATCH v2 0/5] IB/hfi1: Remove write() and use ioctl() for user access Dennis Dalessandro <dennis.dalessandro@intel.com> - 2016-05-12 21:10 +0200
      Re: [PATCH v2 0/5] IB/hfi1: Remove write() and use ioctl() for user  access Jason Gunthorpe <jgunthorpe@obsidianresearch.com> - 2016-05-12 21:30 +0200
        Re: [PATCH v2 0/5] IB/hfi1: Remove write() and use ioctl() for user access Dennis Dalessandro <dennis.dalessandro@intel.com> - 2016-05-12 22:00 +0200
          Re: [PATCH v2 0/5] IB/hfi1: Remove write() and use ioctl() for user  access Doug Ledford <dledford@redhat.com> - 2016-05-12 22:40 +0200
          Re: [PATCH v2 0/5] IB/hfi1: Remove write() and use ioctl() for user  access Jason Gunthorpe <jgunthorpe@obsidianresearch.com> - 2016-05-12 23:30 +0200

csiph-web