public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Pete Zaitcev <zaitcev@redhat.com>
To: Greg KH <greg@kroah.com>
Cc: linux-usb-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, zaitcev@redhat.com
Subject: Re: usb: Patch for USBDEVFS_IOCTL from 32-bit programs
Date: Tue, 18 Oct 2005 11:49:33 -0700	[thread overview]
Message-ID: <20051018114933.276781da.zaitcev@redhat.com> (raw)
In-Reply-To: <20051018171333.GA29504@kroah.com>

On Tue, 18 Oct 2005 10:13:33 -0700, Greg KH <greg@kroah.com> wrote:

> On Mon, Oct 17, 2005 at 06:15:54PM -0700, Pete Zaitcev wrote:
> > I'm cross-posting to l-k because someone I know was making sounds at
> > a notion of #ifdef CONFIG_COMPAT. But I think this solutions is superior
> > to adding anything outside of devio.c.
> 
> Why not put this in fs/compat_ioctl.c where the other usbfs 32bit ioctls
> are?

This is what Dell people did originally. Here is their code:

+static int do_usbdevfs_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
+{
+  struct usbdevfs_ioctl kioc;
+  struct usbdevfs_ioctl32 __user *uioc;
+  mm_segment_t old_fs;
+  u32 udata;
+  int err;
+
+  uioc = compat_ptr(arg);
+  if (get_user(kioc.ifno, &uioc->ifno) ||
+      get_user(kioc.ioctl_code, &uioc->ioctl_code) ||
+      __get_user(udata, &uioc->data))
+    return -EFAULT;
+  
+  kioc.data = compat_ptr(udata);
+
+  old_fs = get_fs();
+  set_fs(KERNEL_DS);
+  err = sys_ioctl(fd, USBDEVFS_IOCTL, (unsigned long)&kioc);
+  set_fs(old_fs);
+
+  return err;
+}

The problem here is that compat_ptr does NOT turn user data pointer
into a kernel pointer. It's still a user pointer, only sized
differently. So, when you do set_fs(KERNEL_DS), this pointer
is invalid (miraclously, it does work on AMD64, so Dell's tests
pass on their new Xeons).

So, you cannot simply to have a small shim. Instead, you have to allocate
the buffer, do copy_from_user(), and then call the ioctl. But then,
it would be a double-copy, when the ioctl allocates the buffer again.

I tweaked this in various ways, and the patch I posted looks like
the cleanest solution. But please tell me if I miss something obvious.

-- Pete

  parent reply	other threads:[~2005-10-18 18:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-18  1:15 usb: Patch for USBDEVFS_IOCTL from 32-bit programs Pete Zaitcev
2005-10-18 17:13 ` Greg KH
2005-10-18 15:05   ` Christopher Li
2005-10-19  3:33     ` Pete Zaitcev
2005-10-18 18:49   ` Pete Zaitcev [this message]
2005-10-18 18:51     ` Arjan van de Ven
2005-10-18 19:08       ` Mikael Pettersson

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=20051018114933.276781da.zaitcev@redhat.com \
    --to=zaitcev@redhat.com \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb-devel@lists.sourceforge.net \
    /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