diff mbox

Input: uinput - handle compat ioctl for UI_SET_PHYS

Message ID 1463499587-21346-1-git-send-email-jcliang@chromium.org (mailing list archive)
State Superseded
Headers show

Commit Message

Ricky Liang May 17, 2016, 3:39 p.m. UTC
When running a 32-bit userspace on a 64-bit kernel, the UI_SET_PHYS
ioctl needs to be treated with special care, as it has the pointer
size encoded in the command.

Signed-off-by: Ricky Liang <jcliang@chromium.org>
---
 drivers/input/misc/uinput.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Dmitry Torokhov May 20, 2016, 4:32 p.m. UTC | #1
Hi Ricky,

On Tue, May 17, 2016 at 11:39:45PM +0800, Ricky Liang wrote:
> When running a 32-bit userspace on a 64-bit kernel, the UI_SET_PHYS
> ioctl needs to be treated with special care, as it has the pointer
> size encoded in the command.
> 
> Signed-off-by: Ricky Liang <jcliang@chromium.org>
> ---
>  drivers/input/misc/uinput.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
> index abe1a92..b4d1b1d 100644
> --- a/drivers/input/misc/uinput.c
> +++ b/drivers/input/misc/uinput.c
> @@ -984,6 +984,15 @@ static long uinput_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
>  static long uinput_compat_ioctl(struct file *file,
>  				unsigned int cmd, unsigned long arg)
>  {
> +	switch (_IOC_NR(cmd)) {
> +		case _IOC_NR(UI_SET_PHYS):
> +			if (_IOC_SIZE(cmd) == sizeof(compat_uptr_t)) {
> +				cmd &= ~IOCSIZE_MASK;
> +				cmd |= sizeof(void *) << IOCSIZE_SHIFT;
> +			}
> +			break;
> +	}
> +

This looks quite complicated... Can we do this:

#define UI_SET_PHYS_COMPAT __IOW(UINPUT_IOCTL_BASE, 108, compat_uptr_t)

...

	if (cmd == UI_SET_PHYS_COMPAT)
		cmd = UI_SET_PHYS;

>  	return uinput_ioctl_handler(file, cmd, arg, compat_ptr(arg));
>  }
>  #endif

We can use the local define instead of manipulating cmd size because we
will never going to change UI_SET_PHYS definition, since it is part of
uapi.

Thanks.
Ricky Liang May 20, 2016, 5:50 p.m. UTC | #2
Hi Dmitry,

On Sat, May 21, 2016 at 12:32 AM, Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> Hi Ricky,
>
> On Tue, May 17, 2016 at 11:39:45PM +0800, Ricky Liang wrote:
>> When running a 32-bit userspace on a 64-bit kernel, the UI_SET_PHYS
>> ioctl needs to be treated with special care, as it has the pointer
>> size encoded in the command.
>>
>> Signed-off-by: Ricky Liang <jcliang@chromium.org>
>> ---
>>  drivers/input/misc/uinput.c | 9 +++++++++
>>  1 file changed, 9 insertions(+)
>>
>> diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
>> index abe1a92..b4d1b1d 100644
>> --- a/drivers/input/misc/uinput.c
>> +++ b/drivers/input/misc/uinput.c
>> @@ -984,6 +984,15 @@ static long uinput_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
>>  static long uinput_compat_ioctl(struct file *file,
>>                               unsigned int cmd, unsigned long arg)
>>  {
>> +     switch (_IOC_NR(cmd)) {
>> +             case _IOC_NR(UI_SET_PHYS):
>> +                     if (_IOC_SIZE(cmd) == sizeof(compat_uptr_t)) {
>> +                             cmd &= ~IOCSIZE_MASK;
>> +                             cmd |= sizeof(void *) << IOCSIZE_SHIFT;
>> +                     }
>> +                     break;
>> +     }
>> +
>
> This looks quite complicated... Can we do this:
>
> #define UI_SET_PHYS_COMPAT __IOW(UINPUT_IOCTL_BASE, 108, compat_uptr_t)
>
> ...
>
>         if (cmd == UI_SET_PHYS_COMPAT)
>                 cmd = UI_SET_PHYS;
>
>>       return uinput_ioctl_handler(file, cmd, arg, compat_ptr(arg));
>>  }
>>  #endif
>
> We can use the local define instead of manipulating cmd size because we
> will never going to change UI_SET_PHYS definition, since it is part of
> uapi.

Sounds good. I'll send v2 to implement this.

Thanks,
Ricky

>
> Thanks.
>
> --
> Dmitry
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
index abe1a92..b4d1b1d 100644
--- a/drivers/input/misc/uinput.c
+++ b/drivers/input/misc/uinput.c
@@ -984,6 +984,15 @@  static long uinput_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 static long uinput_compat_ioctl(struct file *file,
 				unsigned int cmd, unsigned long arg)
 {
+	switch (_IOC_NR(cmd)) {
+		case _IOC_NR(UI_SET_PHYS):
+			if (_IOC_SIZE(cmd) == sizeof(compat_uptr_t)) {
+				cmd &= ~IOCSIZE_MASK;
+				cmd |= sizeof(void *) << IOCSIZE_SHIFT;
+			}
+			break;
+	}
+
 	return uinput_ioctl_handler(file, cmd, arg, compat_ptr(arg));
 }
 #endif