linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpio: handle compatible ioctl() pointers
@ 2016-05-27 12:32 Linus Walleij
  2016-05-27 17:22 ` Dmitry Torokhov
  0 siblings, 1 reply; 2+ messages in thread
From: Linus Walleij @ 2016-05-27 12:32 UTC (permalink / raw)
  To: linux-gpio, Alexandre Courbot, Dmitry Torokhov; +Cc: Linus Walleij

If we're using the compatible ioctl() we need to handle the
argument pointer in a special way or there will be trouble.

Fixes: 3c702e9987e2 ("gpio: add a userspace chardev ABI for GPIOs")
Reported-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/gpio/gpiolib.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index e901d2666b46..f1ef27014e6e 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -20,6 +20,7 @@
 #include <linux/cdev.h>
 #include <linux/fs.h>
 #include <linux/uaccess.h>
+#include <linux/compat.h>
 #include <uapi/linux/gpio.h>
 
 #include "gpiolib.h"
@@ -316,7 +317,7 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
 	struct gpio_device *gdev = filp->private_data;
 	struct gpio_chip *chip = gdev->chip;
-	int __user *ip = (int __user *)arg;
+	void __user *ip = (void __user *)arg;
 
 	/* We fail any subsequent ioctl():s when the chip is gone */
 	if (!chip)
@@ -388,6 +389,14 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 	return -EINVAL;
 }
 
+#ifdef CONFIG_COMPAT
+static long gpio_ioctl_compat(struct file *filp, unsigned int cmd,
+			      unsigned long arg)
+{
+	return gpio_ioctl(filep, cmd, (unsigned long)compat_ptr(arg));
+}
+#endif
+
 /**
  * gpio_chrdev_open() - open the chardev for ioctl operations
  * @inode: inode for this chardev
@@ -431,7 +440,9 @@ static const struct file_operations gpio_fileops = {
 	.owner = THIS_MODULE,
 	.llseek = noop_llseek,
 	.unlocked_ioctl = gpio_ioctl,
-	.compat_ioctl = gpio_ioctl,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl = gpio_ioctl_compat,
+#endif
 };
 
 static void gpiodevice_release(struct device *dev)
-- 
2.4.11


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] gpio: handle compatible ioctl() pointers
  2016-05-27 12:32 [PATCH] gpio: handle compatible ioctl() pointers Linus Walleij
@ 2016-05-27 17:22 ` Dmitry Torokhov
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Torokhov @ 2016-05-27 17:22 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-gpio, Alexandre Courbot

On Fri, May 27, 2016 at 02:32:53PM +0200, Linus Walleij wrote:
> If we're using the compatible ioctl() we need to handle the
> argument pointer in a special way or there will be trouble.
> 
> Fixes: 3c702e9987e2 ("gpio: add a userspace chardev ABI for GPIOs")
> Reported-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

Reviewed-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

> ---
>  drivers/gpio/gpiolib.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index e901d2666b46..f1ef27014e6e 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -20,6 +20,7 @@
>  #include <linux/cdev.h>
>  #include <linux/fs.h>
>  #include <linux/uaccess.h>
> +#include <linux/compat.h>
>  #include <uapi/linux/gpio.h>
>  
>  #include "gpiolib.h"
> @@ -316,7 +317,7 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
>  {
>  	struct gpio_device *gdev = filp->private_data;
>  	struct gpio_chip *chip = gdev->chip;
> -	int __user *ip = (int __user *)arg;
> +	void __user *ip = (void __user *)arg;
>  
>  	/* We fail any subsequent ioctl():s when the chip is gone */
>  	if (!chip)
> @@ -388,6 +389,14 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
>  	return -EINVAL;
>  }
>  
> +#ifdef CONFIG_COMPAT
> +static long gpio_ioctl_compat(struct file *filp, unsigned int cmd,
> +			      unsigned long arg)
> +{
> +	return gpio_ioctl(filep, cmd, (unsigned long)compat_ptr(arg));
> +}
> +#endif
> +
>  /**
>   * gpio_chrdev_open() - open the chardev for ioctl operations
>   * @inode: inode for this chardev
> @@ -431,7 +440,9 @@ static const struct file_operations gpio_fileops = {
>  	.owner = THIS_MODULE,
>  	.llseek = noop_llseek,
>  	.unlocked_ioctl = gpio_ioctl,
> -	.compat_ioctl = gpio_ioctl,
> +#ifdef CONFIG_COMPAT
> +	.compat_ioctl = gpio_ioctl_compat,
> +#endif
>  };
>  
>  static void gpiodevice_release(struct device *dev)
> -- 
> 2.4.11
> 

-- 
Dmitry

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-05-27 17:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-27 12:32 [PATCH] gpio: handle compatible ioctl() pointers Linus Walleij
2016-05-27 17:22 ` Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).