linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Add support compat in dvb_frontend.c
@ 2017-12-01 12:31 Jaedon Shin
  2017-12-01 12:31 ` [PATCH 1/3] media: dvb_frontend: Add unlocked_ioctl " Jaedon Shin
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Jaedon Shin @ 2017-12-01 12:31 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Shuah Khan, Colin Ian King, Satendra Singh Thakur, linux-media,
	Jaedon Shin

This patch series supports compat ioctl for 32-bit user space applications
in 64-bit system.

Jaedon Shin (3):
  media: dvb_frontend: Add unlocked_ioctl in dvb_frontend.c
  media: dvb_frontend: Add compat_ioctl callback
  media: dvb_frontend: Add commands implementation for compat ioct

 drivers/media/dvb-core/dvb_frontend.c | 159 +++++++++++++++++++++++++++++++++-
 fs/compat_ioctl.c                     |  17 ----
 2 files changed, 156 insertions(+), 20 deletions(-)

-- 
2.15.0

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

* [PATCH 1/3] media: dvb_frontend: Add unlocked_ioctl in dvb_frontend.c
  2017-12-01 12:31 [PATCH 0/3] Add support compat in dvb_frontend.c Jaedon Shin
@ 2017-12-01 12:31 ` Jaedon Shin
  2017-12-01 12:31 ` [PATCH 2/3] media: dvb_frontend: Add compat_ioctl callback Jaedon Shin
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Jaedon Shin @ 2017-12-01 12:31 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Shuah Khan, Colin Ian King, Satendra Singh Thakur, linux-media,
	Jaedon Shin

Adds unlocked ioctl function directly in dvb_frontend.c instead of using
dvb_generic_ioctl().

Signed-off-by: Jaedon Shin <jaedon.shin@gmail.com>
---
 drivers/media/dvb-core/dvb_frontend.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c
index 3ad83359098b..6d8f4dd39c0c 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -1920,7 +1920,8 @@ static int dtv_property_process_set(struct dvb_frontend *fe,
 	return r;
 }
 
-static int dvb_frontend_ioctl(struct file *file, unsigned int cmd, void *parg)
+static int dvb_frontend_do_ioctl(struct file *file, unsigned int cmd,
+				 void *parg)
 {
 	struct dvb_device *dvbdev = file->private_data;
 	struct dvb_frontend *fe = dvbdev->priv;
@@ -1963,6 +1964,17 @@ static int dvb_frontend_ioctl(struct file *file, unsigned int cmd, void *parg)
 	return err;
 }
 
+static long dvb_frontend_ioctl(struct file *file, unsigned int cmd,
+			       unsigned long arg)
+{
+	struct dvb_device *dvbdev = file->private_data;
+
+	if (!dvbdev)
+		return -ENODEV;
+
+	return dvb_usercopy(file, cmd, arg, dvb_frontend_do_ioctl);
+}
+
 static int dtv_set_frontend(struct dvb_frontend *fe)
 {
 	struct dvb_frontend_private *fepriv = fe->frontend_priv;
@@ -2644,7 +2656,7 @@ static int dvb_frontend_release(struct inode *inode, struct file *file)
 
 static const struct file_operations dvb_frontend_fops = {
 	.owner		= THIS_MODULE,
-	.unlocked_ioctl	= dvb_generic_ioctl,
+	.unlocked_ioctl	= dvb_frontend_ioctl,
 	.poll		= dvb_frontend_poll,
 	.open		= dvb_frontend_open,
 	.release	= dvb_frontend_release,
@@ -2712,7 +2724,6 @@ int dvb_register_frontend(struct dvb_adapter* dvb,
 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
 		.name = fe->ops.info.name,
 #endif
-		.kernel_ioctl = dvb_frontend_ioctl
 	};
 
 	dev_dbg(dvb->device, "%s:\n", __func__);
-- 
2.15.0

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

* [PATCH 2/3] media: dvb_frontend: Add compat_ioctl callback
  2017-12-01 12:31 [PATCH 0/3] Add support compat in dvb_frontend.c Jaedon Shin
  2017-12-01 12:31 ` [PATCH 1/3] media: dvb_frontend: Add unlocked_ioctl " Jaedon Shin
@ 2017-12-01 12:31 ` Jaedon Shin
  2017-12-04 14:29   ` kbuild test robot
  2017-12-01 12:31 ` [PATCH 3/3] media: dvb_frontend: Add commands implementation for compat ioct Jaedon Shin
  2017-12-02  7:50 ` [PATCH 0/3] Add support compat in dvb_frontend.c Mauro Carvalho Chehab
  3 siblings, 1 reply; 10+ messages in thread
From: Jaedon Shin @ 2017-12-01 12:31 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Shuah Khan, Colin Ian King, Satendra Singh Thakur, linux-media,
	Jaedon Shin

Adds compat_ioctl for 32-bit user space applications on a 64-bit system.

Signed-off-by: Jaedon Shin <jaedon.shin@gmail.com>
---
 drivers/media/dvb-core/dvb_frontend.c | 11 +++++++++++
 fs/compat_ioctl.c                     | 17 -----------------
 2 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c
index 6d8f4dd39c0c..1ae23403a0ab 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -1975,6 +1975,14 @@ static long dvb_frontend_ioctl(struct file *file, unsigned int cmd,
 	return dvb_usercopy(file, cmd, arg, dvb_frontend_do_ioctl);
 }
 
+#ifdef CONFIG_COMPAT
+static long dvb_frontend_compat_ioctl(struct file *file, unsigned int cmd,
+				      unsigned long arg)
+{
+	return dvb_frontend_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
+}
+#endif
+
 static int dtv_set_frontend(struct dvb_frontend *fe)
 {
 	struct dvb_frontend_private *fepriv = fe->frontend_priv;
@@ -2657,6 +2665,9 @@ static int dvb_frontend_release(struct inode *inode, struct file *file)
 static const struct file_operations dvb_frontend_fops = {
 	.owner		= THIS_MODULE,
 	.unlocked_ioctl	= dvb_frontend_ioctl,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl	= dvb_frontend_compat_ioctl,
+#endif
 	.poll		= dvb_frontend_poll,
 	.open		= dvb_frontend_open,
 	.release	= dvb_frontend_release,
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index 5fc5dc660600..9a1fe60cce9a 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -1218,23 +1218,6 @@ COMPATIBLE_IOCTL(DMX_SET_PES_FILTER)
 COMPATIBLE_IOCTL(DMX_SET_BUFFER_SIZE)
 COMPATIBLE_IOCTL(DMX_GET_PES_PIDS)
 COMPATIBLE_IOCTL(DMX_GET_STC)
-COMPATIBLE_IOCTL(FE_GET_INFO)
-COMPATIBLE_IOCTL(FE_DISEQC_RESET_OVERLOAD)
-COMPATIBLE_IOCTL(FE_DISEQC_SEND_MASTER_CMD)
-COMPATIBLE_IOCTL(FE_DISEQC_RECV_SLAVE_REPLY)
-COMPATIBLE_IOCTL(FE_DISEQC_SEND_BURST)
-COMPATIBLE_IOCTL(FE_SET_TONE)
-COMPATIBLE_IOCTL(FE_SET_VOLTAGE)
-COMPATIBLE_IOCTL(FE_ENABLE_HIGH_LNB_VOLTAGE)
-COMPATIBLE_IOCTL(FE_READ_STATUS)
-COMPATIBLE_IOCTL(FE_READ_BER)
-COMPATIBLE_IOCTL(FE_READ_SIGNAL_STRENGTH)
-COMPATIBLE_IOCTL(FE_READ_SNR)
-COMPATIBLE_IOCTL(FE_READ_UNCORRECTED_BLOCKS)
-COMPATIBLE_IOCTL(FE_SET_FRONTEND)
-COMPATIBLE_IOCTL(FE_GET_FRONTEND)
-COMPATIBLE_IOCTL(FE_GET_EVENT)
-COMPATIBLE_IOCTL(FE_DISHNETWORK_SEND_LEGACY_CMD)
 COMPATIBLE_IOCTL(VIDEO_STOP)
 COMPATIBLE_IOCTL(VIDEO_PLAY)
 COMPATIBLE_IOCTL(VIDEO_FREEZE)
-- 
2.15.0

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

* [PATCH 3/3] media: dvb_frontend: Add commands implementation for compat ioct
  2017-12-01 12:31 [PATCH 0/3] Add support compat in dvb_frontend.c Jaedon Shin
  2017-12-01 12:31 ` [PATCH 1/3] media: dvb_frontend: Add unlocked_ioctl " Jaedon Shin
  2017-12-01 12:31 ` [PATCH 2/3] media: dvb_frontend: Add compat_ioctl callback Jaedon Shin
@ 2017-12-01 12:31 ` Jaedon Shin
  2017-12-04 12:56   ` kbuild test robot
                     ` (2 more replies)
  2017-12-02  7:50 ` [PATCH 0/3] Add support compat in dvb_frontend.c Mauro Carvalho Chehab
  3 siblings, 3 replies; 10+ messages in thread
From: Jaedon Shin @ 2017-12-01 12:31 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Shuah Khan, Colin Ian King, Satendra Singh Thakur, linux-media,
	Jaedon Shin

The dtv_properties structure and the dtv_property structure are
different sizes in 32-bit and 64-bit system. This patch provides
FE_SET_PROPERTY and FE_GET_PROPERTY ioctl commands implementation for
32-bit user space applications.

Signed-off-by: Jaedon Shin <jaedon.shin@gmail.com>
---
 drivers/media/dvb-core/dvb_frontend.c | 131 ++++++++++++++++++++++++++++++++++
 1 file changed, 131 insertions(+)

diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c
index 1ae23403a0ab..f3751a573dfe 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -1976,9 +1976,140 @@ static long dvb_frontend_ioctl(struct file *file, unsigned int cmd,
 }
 
 #ifdef CONFIG_COMPAT
+struct compat_dtv_property {
+	__u32 cmd;
+	__u32 reserved[3];
+	union {
+		__u32 data;
+		struct dtv_fe_stats st;
+		struct {
+			__u8 data[32];
+			__u32 len;
+			__u32 reserved1[3];
+			compat_uptr_t reserved2;
+		} buffer;
+	} u;
+	int result;
+} __attribute__ ((packed));
+
+struct compat_dtv_properties {
+	__u32 num;
+	compat_uptr_t props;
+};
+
+#define COMPAT_FE_SET_PROPERTY	   _IOW('o', 82, struct compat_dtv_properties)
+#define COMPAT_FE_GET_PROPERTY	   _IOR('o', 83, struct compat_dtv_properties)
+
+static int dvb_frontend_handle_compat_ioctl(struct file *file, unsigned int cmd,
+					    unsigned long arg)
+{
+	struct dvb_device *dvbdev = file->private_data;
+	struct dvb_frontend *fe = dvbdev->priv;
+	struct dvb_frontend_private *fepriv = fe->frontend_priv;
+	int i, err = 0;
+
+	if (cmd == COMPAT_FE_SET_PROPERTY) {
+		struct compat_dtv_properties prop, *tvps = NULL;
+		struct compat_dtv_property *tvp = NULL;
+
+		if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
+			return -EFAULT;
+
+		tvps = &prop;
+
+		/*
+		 * Put an arbitrary limit on the number of messages that can
+		 * be sent at once
+		 */
+		if (!tvps->num || (tvps->num > DTV_IOCTL_MAX_MSGS))
+			return -EINVAL;
+
+		tvp = memdup_user(compat_ptr(tvps->props), tvps->num * sizeof(*tvp));
+		if (IS_ERR(tvp))
+			return PTR_ERR(tvp);
+
+		for (i = 0; i < tvps->num; i++) {
+			err = dtv_property_process_set(fe, file,
+							(tvp + i)->cmd,
+							(tvp + i)->u.data);
+			if (err < 0) {
+				kfree(tvp);
+				return err;
+			}
+		}
+		kfree(tvp);
+	} else if (cmd == COMPAT_FE_GET_PROPERTY) {
+		struct compat_dtv_properties prop, *tvps = NULL;
+		struct compat_dtv_property *tvp = NULL;
+		struct dtv_frontend_properties getp = fe->dtv_property_cache;
+
+		if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
+			return -EFAULT;
+
+		tvps = &prop;
+
+		/*
+		 * Put an arbitrary limit on the number of messages that can
+		 * be sent at once
+		 */
+		if (!tvps->num || (tvps->num > DTV_IOCTL_MAX_MSGS))
+			return -EINVAL;
+
+		tvp = memdup_user(compat_ptr(tvps->props), tvps->num * sizeof(*tvp));
+		if (IS_ERR(tvp))
+			return PTR_ERR(tvp);
+
+		/*
+		 * Let's use our own copy of property cache, in order to
+		 * avoid mangling with DTV zigzag logic, as drivers might
+		 * return crap, if they don't check if the data is available
+		 * before updating the properties cache.
+		 */
+		if (fepriv->state != FESTATE_IDLE) {
+			err = dtv_get_frontend(fe, &getp, NULL);
+			if (err < 0) {
+				kfree(tvp);
+				return err;
+			}
+		}
+		for (i = 0; i < tvps->num; i++) {
+			err = dtv_property_process_get(
+			    fe, &getp, (struct dtv_property *)tvp + i, file);
+			if (err < 0) {
+				kfree(tvp);
+				return err;
+			}
+		}
+
+		if (copy_to_user((void __user *)compat_ptr(tvps->props), tvp,
+				 tvps->num * sizeof(struct compat_dtv_property))) {
+			kfree(tvp);
+			return -EFAULT;
+		}
+		kfree(tvp);
+	}
+
+	return err;
+}
+
 static long dvb_frontend_compat_ioctl(struct file *file, unsigned int cmd,
 				      unsigned long arg)
 {
+	struct dvb_device *dvbdev = file->private_data;
+	struct dvb_frontend *fe = dvbdev->priv;
+	struct dvb_frontend_private *fepriv = fe->frontend_priv;
+	int err;
+
+	if (cmd == COMPAT_FE_SET_PROPERTY || cmd == COMPAT_FE_GET_PROPERTY) {
+		if (down_interruptible(&fepriv->sem))
+			return -ERESTARTSYS;
+
+		err = dvb_frontend_handle_compat_ioctl(file, cmd, arg);
+
+		up(&fepriv->sem);
+		return err;
+	}
+
 	return dvb_frontend_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
 }
 #endif
-- 
2.15.0

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

* Re: [PATCH 0/3] Add support compat in dvb_frontend.c
  2017-12-01 12:31 [PATCH 0/3] Add support compat in dvb_frontend.c Jaedon Shin
                   ` (2 preceding siblings ...)
  2017-12-01 12:31 ` [PATCH 3/3] media: dvb_frontend: Add commands implementation for compat ioct Jaedon Shin
@ 2017-12-02  7:50 ` Mauro Carvalho Chehab
  2017-12-13 14:30   ` Mauro Carvalho Chehab
  3 siblings, 1 reply; 10+ messages in thread
From: Mauro Carvalho Chehab @ 2017-12-02  7:50 UTC (permalink / raw)
  To: Jaedon Shin
  Cc: Shuah Khan, Colin Ian King, Satendra Singh Thakur, linux-media,
	Michael Ira Krufky, Sean Young

Hi Jaedon,

Em Fri,  1 Dec 2017 21:31:27 +0900
Jaedon Shin <jaedon.shin@gmail.com> escreveu:

> This patch series supports compat ioctl for 32-bit user space applications
> in 64-bit system.
> 
> Jaedon Shin (3):
>   media: dvb_frontend: Add unlocked_ioctl in dvb_frontend.c
>   media: dvb_frontend: Add compat_ioctl callback
>   media: dvb_frontend: Add commands implementation for compat ioct

Thanks for the series. Yeah, indeed we need something like that.

Yet, I suspect that you should also move the logic inside
dvb_frontend_handle_ioctl() with copies from/to userspace.

We don't want the logic there to be called when a 32-bit userspace
copy happens, as it should now use the new compat32 code.


Thanks,
Mauro

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

* Re: [PATCH 3/3] media: dvb_frontend: Add commands implementation for compat ioct
  2017-12-01 12:31 ` [PATCH 3/3] media: dvb_frontend: Add commands implementation for compat ioct Jaedon Shin
@ 2017-12-04 12:56   ` kbuild test robot
  2017-12-04 13:46   ` Menion
  2017-12-04 18:33   ` kbuild test robot
  2 siblings, 0 replies; 10+ messages in thread
From: kbuild test robot @ 2017-12-04 12:56 UTC (permalink / raw)
  To: Jaedon Shin
  Cc: kbuild-all, Mauro Carvalho Chehab, Shuah Khan, Colin Ian King,
	Satendra Singh Thakur, linux-media, Jaedon Shin

[-- Attachment #1: Type: text/plain, Size: 7610 bytes --]

Hi Jaedon,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on v4.15-rc2 next-20171204]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Jaedon-Shin/Add-support-compat-in-dvb_frontend-c/20171204-201817
base:   git://linuxtv.org/media_tree.git master
config: x86_64-randconfig-x014-201749 (attached as .config)
compiler: gcc-7 (Debian 7.2.0-12) 7.2.1 20171025
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All error/warnings (new ones prefixed by >>):

>> drivers/media//dvb-core/dvb_frontend.c:1992:4: error: unknown type name 'compat_uptr_t'
       compat_uptr_t reserved2;
       ^~~~~~~~~~~~~
   drivers/media//dvb-core/dvb_frontend.c:2000:2: error: unknown type name 'compat_uptr_t'
     compat_uptr_t props;
     ^~~~~~~~~~~~~
   drivers/media//dvb-core/dvb_frontend.c: In function 'dvb_frontend_handle_compat_ioctl':
   drivers/media//dvb-core/dvb_frontend.c:2018:29: error: implicit declaration of function 'compat_ptr'; did you mean 'complete'? [-Werror=implicit-function-declaration]
      if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
                                ^~~~~~~~~~
                                complete
>> drivers/media//dvb-core/dvb_frontend.c:2018:29: warning: passing argument 2 of 'copy_from_user' makes pointer from integer without a cast [-Wint-conversion]
   In file included from include/linux/poll.h:12:0,
                    from drivers/media//dvb-core/dvb_frontend.c:35:
   include/linux/uaccess.h:144:1: note: expected 'const void *' but argument is of type 'int'
    copy_from_user(void *to, const void __user *from, unsigned long n)
    ^~~~~~~~~~~~~~
>> drivers/media//dvb-core/dvb_frontend.c:2030:21: warning: passing argument 1 of 'memdup_user' makes pointer from integer without a cast [-Wint-conversion]
      tvp = memdup_user(compat_ptr(tvps->props), tvps->num * sizeof(*tvp));
                        ^~~~~~~~~~
   In file included from drivers/media//dvb-core/dvb_frontend.c:30:0:
   include/linux/string.h:13:14: note: expected 'const void *' but argument is of type 'int'
    extern void *memdup_user(const void __user *, size_t);
                 ^~~~~~~~~~~
   drivers/media//dvb-core/dvb_frontend.c:2049:29: warning: passing argument 2 of 'copy_from_user' makes pointer from integer without a cast [-Wint-conversion]
      if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
                                ^~~~~~~~~~
   In file included from include/linux/poll.h:12:0,
                    from drivers/media//dvb-core/dvb_frontend.c:35:
   include/linux/uaccess.h:144:1: note: expected 'const void *' but argument is of type 'int'
    copy_from_user(void *to, const void __user *from, unsigned long n)
    ^~~~~~~~~~~~~~
   drivers/media//dvb-core/dvb_frontend.c:2061:21: warning: passing argument 1 of 'memdup_user' makes pointer from integer without a cast [-Wint-conversion]
      tvp = memdup_user(compat_ptr(tvps->props), tvps->num * sizeof(*tvp));
                        ^~~~~~~~~~
   In file included from drivers/media//dvb-core/dvb_frontend.c:30:0:
   include/linux/string.h:13:14: note: expected 'const void *' but argument is of type 'int'
    extern void *memdup_user(const void __user *, size_t);
                 ^~~~~~~~~~~
>> drivers/media//dvb-core/dvb_frontend.c:2087:20: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
      if (copy_to_user((void __user *)compat_ptr(tvps->props), tvp,
                       ^
   cc1: some warnings being treated as errors

vim +/compat_uptr_t +1992 drivers/media//dvb-core/dvb_frontend.c

  1980	
  1981	#ifdef CONFIG_COMPAT
  1982	struct compat_dtv_property {
  1983		__u32 cmd;
  1984		__u32 reserved[3];
  1985		union {
  1986			__u32 data;
  1987			struct dtv_fe_stats st;
  1988			struct {
  1989				__u8 data[32];
  1990				__u32 len;
  1991				__u32 reserved1[3];
> 1992				compat_uptr_t reserved2;
  1993			} buffer;
  1994		} u;
  1995		int result;
  1996	} __attribute__ ((packed));
  1997	
  1998	struct compat_dtv_properties {
  1999		__u32 num;
> 2000		compat_uptr_t props;
  2001	};
  2002	
  2003	#define COMPAT_FE_SET_PROPERTY	   _IOW('o', 82, struct compat_dtv_properties)
  2004	#define COMPAT_FE_GET_PROPERTY	   _IOR('o', 83, struct compat_dtv_properties)
  2005	
  2006	static int dvb_frontend_handle_compat_ioctl(struct file *file, unsigned int cmd,
  2007						    unsigned long arg)
  2008	{
  2009		struct dvb_device *dvbdev = file->private_data;
  2010		struct dvb_frontend *fe = dvbdev->priv;
  2011		struct dvb_frontend_private *fepriv = fe->frontend_priv;
  2012		int i, err = 0;
  2013	
  2014		if (cmd == COMPAT_FE_SET_PROPERTY) {
  2015			struct compat_dtv_properties prop, *tvps = NULL;
  2016			struct compat_dtv_property *tvp = NULL;
  2017	
> 2018			if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
  2019				return -EFAULT;
  2020	
  2021			tvps = &prop;
  2022	
  2023			/*
  2024			 * Put an arbitrary limit on the number of messages that can
  2025			 * be sent at once
  2026			 */
  2027			if (!tvps->num || (tvps->num > DTV_IOCTL_MAX_MSGS))
  2028				return -EINVAL;
  2029	
> 2030			tvp = memdup_user(compat_ptr(tvps->props), tvps->num * sizeof(*tvp));
  2031			if (IS_ERR(tvp))
  2032				return PTR_ERR(tvp);
  2033	
  2034			for (i = 0; i < tvps->num; i++) {
  2035				err = dtv_property_process_set(fe, file,
  2036								(tvp + i)->cmd,
  2037								(tvp + i)->u.data);
  2038				if (err < 0) {
  2039					kfree(tvp);
  2040					return err;
  2041				}
  2042			}
  2043			kfree(tvp);
  2044		} else if (cmd == COMPAT_FE_GET_PROPERTY) {
  2045			struct compat_dtv_properties prop, *tvps = NULL;
  2046			struct compat_dtv_property *tvp = NULL;
  2047			struct dtv_frontend_properties getp = fe->dtv_property_cache;
  2048	
  2049			if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
  2050				return -EFAULT;
  2051	
  2052			tvps = &prop;
  2053	
  2054			/*
  2055			 * Put an arbitrary limit on the number of messages that can
  2056			 * be sent at once
  2057			 */
  2058			if (!tvps->num || (tvps->num > DTV_IOCTL_MAX_MSGS))
  2059				return -EINVAL;
  2060	
> 2061			tvp = memdup_user(compat_ptr(tvps->props), tvps->num * sizeof(*tvp));
  2062			if (IS_ERR(tvp))
  2063				return PTR_ERR(tvp);
  2064	
  2065			/*
  2066			 * Let's use our own copy of property cache, in order to
  2067			 * avoid mangling with DTV zigzag logic, as drivers might
  2068			 * return crap, if they don't check if the data is available
  2069			 * before updating the properties cache.
  2070			 */
  2071			if (fepriv->state != FESTATE_IDLE) {
  2072				err = dtv_get_frontend(fe, &getp, NULL);
  2073				if (err < 0) {
  2074					kfree(tvp);
  2075					return err;
  2076				}
  2077			}
  2078			for (i = 0; i < tvps->num; i++) {
  2079				err = dtv_property_process_get(
  2080				    fe, &getp, (struct dtv_property *)tvp + i, file);
  2081				if (err < 0) {
  2082					kfree(tvp);
  2083					return err;
  2084				}
  2085			}
  2086	
> 2087			if (copy_to_user((void __user *)compat_ptr(tvps->props), tvp,
  2088					 tvps->num * sizeof(struct compat_dtv_property))) {
  2089				kfree(tvp);
  2090				return -EFAULT;
  2091			}
  2092			kfree(tvp);
  2093		}
  2094	
  2095		return err;
  2096	}
  2097	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 32180 bytes --]

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

* Re: [PATCH 3/3] media: dvb_frontend: Add commands implementation for compat ioct
  2017-12-01 12:31 ` [PATCH 3/3] media: dvb_frontend: Add commands implementation for compat ioct Jaedon Shin
  2017-12-04 12:56   ` kbuild test robot
@ 2017-12-04 13:46   ` Menion
  2017-12-04 18:33   ` kbuild test robot
  2 siblings, 0 replies; 10+ messages in thread
From: Menion @ 2017-12-04 13:46 UTC (permalink / raw)
  To: Jaedon Shin
  Cc: Mauro Carvalho Chehab, Shuah Khan, Colin Ian King,
	Satendra Singh Thakur, linux-media

Hello
Sorry if I say something completely wrong here, I was thinking to
implement the same on my own
As far as I understand from the patch, you have added two "compact"
specific ioctl commands
As far as I know, the compact_ioctl is called automatically when the
userland is 32 bit and kernel is 64 bit and it must be transparent
With compact specific ioctl command, the application should know if it
is running on top of 64 bit kernel and use them in case
I am not sure if this is the correct approach (also the userland
application should be all upgraded to make use of these new commands)
As far as I have understood, the compatc_ioctl body should adapt the
structures in and out, using the compact_ types
Bye

2017-12-01 13:31 GMT+01:00 Jaedon Shin <jaedon.shin@gmail.com>:
> The dtv_properties structure and the dtv_property structure are
> different sizes in 32-bit and 64-bit system. This patch provides
> FE_SET_PROPERTY and FE_GET_PROPERTY ioctl commands implementation for
> 32-bit user space applications.
>
> Signed-off-by: Jaedon Shin <jaedon.shin@gmail.com>
> ---
>  drivers/media/dvb-core/dvb_frontend.c | 131 ++++++++++++++++++++++++++++++++++
>  1 file changed, 131 insertions(+)
>
> diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c
> index 1ae23403a0ab..f3751a573dfe 100644
> --- a/drivers/media/dvb-core/dvb_frontend.c
> +++ b/drivers/media/dvb-core/dvb_frontend.c
> @@ -1976,9 +1976,140 @@ static long dvb_frontend_ioctl(struct file *file, unsigned int cmd,
>  }
>
>  #ifdef CONFIG_COMPAT
> +struct compat_dtv_property {
> +       __u32 cmd;
> +       __u32 reserved[3];
> +       union {
> +               __u32 data;
> +               struct dtv_fe_stats st;
> +               struct {
> +                       __u8 data[32];
> +                       __u32 len;
> +                       __u32 reserved1[3];
> +                       compat_uptr_t reserved2;
> +               } buffer;
> +       } u;
> +       int result;
> +} __attribute__ ((packed));
> +
> +struct compat_dtv_properties {
> +       __u32 num;
> +       compat_uptr_t props;
> +};
> +
> +#define COMPAT_FE_SET_PROPERTY    _IOW('o', 82, struct compat_dtv_properties)
> +#define COMPAT_FE_GET_PROPERTY    _IOR('o', 83, struct compat_dtv_properties)
> +
> +static int dvb_frontend_handle_compat_ioctl(struct file *file, unsigned int cmd,
> +                                           unsigned long arg)
> +{
> +       struct dvb_device *dvbdev = file->private_data;
> +       struct dvb_frontend *fe = dvbdev->priv;
> +       struct dvb_frontend_private *fepriv = fe->frontend_priv;
> +       int i, err = 0;
> +
> +       if (cmd == COMPAT_FE_SET_PROPERTY) {
> +               struct compat_dtv_properties prop, *tvps = NULL;
> +               struct compat_dtv_property *tvp = NULL;
> +
> +               if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
> +                       return -EFAULT;
> +
> +               tvps = &prop;
> +
> +               /*
> +                * Put an arbitrary limit on the number of messages that can
> +                * be sent at once
> +                */
> +               if (!tvps->num || (tvps->num > DTV_IOCTL_MAX_MSGS))
> +                       return -EINVAL;
> +
> +               tvp = memdup_user(compat_ptr(tvps->props), tvps->num * sizeof(*tvp));
> +               if (IS_ERR(tvp))
> +                       return PTR_ERR(tvp);
> +
> +               for (i = 0; i < tvps->num; i++) {
> +                       err = dtv_property_process_set(fe, file,
> +                                                       (tvp + i)->cmd,
> +                                                       (tvp + i)->u.data);
> +                       if (err < 0) {
> +                               kfree(tvp);
> +                               return err;
> +                       }
> +               }
> +               kfree(tvp);
> +       } else if (cmd == COMPAT_FE_GET_PROPERTY) {
> +               struct compat_dtv_properties prop, *tvps = NULL;
> +               struct compat_dtv_property *tvp = NULL;
> +               struct dtv_frontend_properties getp = fe->dtv_property_cache;
> +
> +               if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
> +                       return -EFAULT;
> +
> +               tvps = &prop;
> +
> +               /*
> +                * Put an arbitrary limit on the number of messages that can
> +                * be sent at once
> +                */
> +               if (!tvps->num || (tvps->num > DTV_IOCTL_MAX_MSGS))
> +                       return -EINVAL;
> +
> +               tvp = memdup_user(compat_ptr(tvps->props), tvps->num * sizeof(*tvp));
> +               if (IS_ERR(tvp))
> +                       return PTR_ERR(tvp);
> +
> +               /*
> +                * Let's use our own copy of property cache, in order to
> +                * avoid mangling with DTV zigzag logic, as drivers might
> +                * return crap, if they don't check if the data is available
> +                * before updating the properties cache.
> +                */
> +               if (fepriv->state != FESTATE_IDLE) {
> +                       err = dtv_get_frontend(fe, &getp, NULL);
> +                       if (err < 0) {
> +                               kfree(tvp);
> +                               return err;
> +                       }
> +               }
> +               for (i = 0; i < tvps->num; i++) {
> +                       err = dtv_property_process_get(
> +                           fe, &getp, (struct dtv_property *)tvp + i, file);
> +                       if (err < 0) {
> +                               kfree(tvp);
> +                               return err;
> +                       }
> +               }
> +
> +               if (copy_to_user((void __user *)compat_ptr(tvps->props), tvp,
> +                                tvps->num * sizeof(struct compat_dtv_property))) {
> +                       kfree(tvp);
> +                       return -EFAULT;
> +               }
> +               kfree(tvp);
> +       }
> +
> +       return err;
> +}
> +
>  static long dvb_frontend_compat_ioctl(struct file *file, unsigned int cmd,
>                                       unsigned long arg)
>  {
> +       struct dvb_device *dvbdev = file->private_data;
> +       struct dvb_frontend *fe = dvbdev->priv;
> +       struct dvb_frontend_private *fepriv = fe->frontend_priv;
> +       int err;
> +
> +       if (cmd == COMPAT_FE_SET_PROPERTY || cmd == COMPAT_FE_GET_PROPERTY) {
> +               if (down_interruptible(&fepriv->sem))
> +                       return -ERESTARTSYS;
> +
> +               err = dvb_frontend_handle_compat_ioctl(file, cmd, arg);
> +
> +               up(&fepriv->sem);
> +               return err;
> +       }
> +
>         return dvb_frontend_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
>  }
>  #endif
> --
> 2.15.0
>

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

* Re: [PATCH 2/3] media: dvb_frontend: Add compat_ioctl callback
  2017-12-01 12:31 ` [PATCH 2/3] media: dvb_frontend: Add compat_ioctl callback Jaedon Shin
@ 2017-12-04 14:29   ` kbuild test robot
  0 siblings, 0 replies; 10+ messages in thread
From: kbuild test robot @ 2017-12-04 14:29 UTC (permalink / raw)
  To: Jaedon Shin
  Cc: kbuild-all, Mauro Carvalho Chehab, Shuah Khan, Colin Ian King,
	Satendra Singh Thakur, linux-media, Jaedon Shin

[-- Attachment #1: Type: text/plain, Size: 1657 bytes --]

Hi Jaedon,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on v4.15-rc2 next-20171204]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Jaedon-Shin/Add-support-compat-in-dvb_frontend-c/20171204-201817
base:   git://linuxtv.org/media_tree.git master
config: x86_64-randconfig-x014-201749 (attached as .config)
compiler: gcc-7 (Debian 7.2.0-12) 7.2.1 20171025
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

   drivers/media/dvb-core/dvb_frontend.c: In function 'dvb_frontend_compat_ioctl':
>> drivers/media/dvb-core/dvb_frontend.c:1985:54: error: implicit declaration of function 'compat_ptr'; did you mean 'complete'? [-Werror=implicit-function-declaration]
     return dvb_frontend_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
                                                         ^~~~~~~~~~
                                                         complete
   cc1: some warnings being treated as errors

vim +1985 drivers/media/dvb-core/dvb_frontend.c

  1980	
  1981	#ifdef CONFIG_COMPAT
  1982	static long dvb_frontend_compat_ioctl(struct file *file, unsigned int cmd,
  1983					      unsigned long arg)
  1984	{
> 1985		return dvb_frontend_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
  1986	}
  1987	#endif
  1988	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 32180 bytes --]

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

* Re: [PATCH 3/3] media: dvb_frontend: Add commands implementation for compat ioct
  2017-12-01 12:31 ` [PATCH 3/3] media: dvb_frontend: Add commands implementation for compat ioct Jaedon Shin
  2017-12-04 12:56   ` kbuild test robot
  2017-12-04 13:46   ` Menion
@ 2017-12-04 18:33   ` kbuild test robot
  2 siblings, 0 replies; 10+ messages in thread
From: kbuild test robot @ 2017-12-04 18:33 UTC (permalink / raw)
  To: Jaedon Shin
  Cc: kbuild-all, Mauro Carvalho Chehab, Shuah Khan, Colin Ian King,
	Satendra Singh Thakur, linux-media, Jaedon Shin

[-- Attachment #1: Type: text/plain, Size: 13775 bytes --]

Hi Jaedon,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linuxtv-media/master]
[also build test WARNING on v4.15-rc2 next-20171204]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Jaedon-Shin/Add-support-compat-in-dvb_frontend-c/20171204-201817
base:   git://linuxtv.org/media_tree.git master
config: x86_64-randconfig-ne0-12042359 (attached as .config)
compiler: gcc-6 (Debian 6.4.0-9) 6.4.0 20171026
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All warnings (new ones prefixed by >>):

   drivers/media/dvb-core/dvb_frontend.c:1992:4: error: unknown type name 'compat_uptr_t'
       compat_uptr_t reserved2;
       ^~~~~~~~~~~~~
   drivers/media/dvb-core/dvb_frontend.c:2000:2: error: unknown type name 'compat_uptr_t'
     compat_uptr_t props;
     ^~~~~~~~~~~~~
   In file included from include/linux/string.h:6:0,
                    from drivers/media/dvb-core/dvb_frontend.c:30:
   drivers/media/dvb-core/dvb_frontend.c: In function 'dvb_frontend_handle_compat_ioctl':
   drivers/media/dvb-core/dvb_frontend.c:2018:29: error: implicit declaration of function 'compat_ptr' [-Werror=implicit-function-declaration]
      if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
                                ^
   include/linux/compiler.h:58:30: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                 ^~~~
>> drivers/media/dvb-core/dvb_frontend.c:2018:3: note: in expansion of macro 'if'
      if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
      ^~
   drivers/media/dvb-core/dvb_frontend.c:2018:29: warning: passing argument 2 of 'copy_from_user' makes pointer from integer without a cast [-Wint-conversion]
      if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
                                ^
   include/linux/compiler.h:58:30: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                 ^~~~
>> drivers/media/dvb-core/dvb_frontend.c:2018:3: note: in expansion of macro 'if'
      if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
      ^~
   In file included from include/linux/poll.h:12:0,
                    from drivers/media/dvb-core/dvb_frontend.c:35:
   include/linux/uaccess.h:144:1: note: expected 'const void *' but argument is of type 'int'
    copy_from_user(void *to, const void __user *from, unsigned long n)
    ^~~~~~~~~~~~~~
   In file included from include/linux/string.h:6:0,
                    from drivers/media/dvb-core/dvb_frontend.c:30:
   drivers/media/dvb-core/dvb_frontend.c:2018:29: warning: passing argument 2 of 'copy_from_user' makes pointer from integer without a cast [-Wint-conversion]
      if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
                                ^
   include/linux/compiler.h:58:42: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                             ^~~~
>> drivers/media/dvb-core/dvb_frontend.c:2018:3: note: in expansion of macro 'if'
      if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
      ^~
   In file included from include/linux/poll.h:12:0,
                    from drivers/media/dvb-core/dvb_frontend.c:35:
   include/linux/uaccess.h:144:1: note: expected 'const void *' but argument is of type 'int'
    copy_from_user(void *to, const void __user *from, unsigned long n)
    ^~~~~~~~~~~~~~
   In file included from include/linux/string.h:6:0,
                    from drivers/media/dvb-core/dvb_frontend.c:30:
   drivers/media/dvb-core/dvb_frontend.c:2018:29: warning: passing argument 2 of 'copy_from_user' makes pointer from integer without a cast [-Wint-conversion]
      if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
                                ^
   include/linux/compiler.h:69:16: note: in definition of macro '__trace_if'
      ______r = !!(cond);     \
                   ^~~~
>> drivers/media/dvb-core/dvb_frontend.c:2018:3: note: in expansion of macro 'if'
      if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
      ^~
   In file included from include/linux/poll.h:12:0,
                    from drivers/media/dvb-core/dvb_frontend.c:35:
   include/linux/uaccess.h:144:1: note: expected 'const void *' but argument is of type 'int'
    copy_from_user(void *to, const void __user *from, unsigned long n)
    ^~~~~~~~~~~~~~
   drivers/media/dvb-core/dvb_frontend.c:2030:21: warning: passing argument 1 of 'memdup_user' makes pointer from integer without a cast [-Wint-conversion]
      tvp = memdup_user(compat_ptr(tvps->props), tvps->num * sizeof(*tvp));
                        ^~~~~~~~~~
   In file included from drivers/media/dvb-core/dvb_frontend.c:30:0:
   include/linux/string.h:13:14: note: expected 'const void *' but argument is of type 'int'
    extern void *memdup_user(const void __user *, size_t);
                 ^~~~~~~~~~~
   In file included from include/linux/string.h:6:0,
                    from drivers/media/dvb-core/dvb_frontend.c:30:
   drivers/media/dvb-core/dvb_frontend.c:2049:29: warning: passing argument 2 of 'copy_from_user' makes pointer from integer without a cast [-Wint-conversion]
      if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
                                ^
   include/linux/compiler.h:58:30: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                 ^~~~
   drivers/media/dvb-core/dvb_frontend.c:2049:3: note: in expansion of macro 'if'
      if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
      ^~
   In file included from include/linux/poll.h:12:0,
                    from drivers/media/dvb-core/dvb_frontend.c:35:
   include/linux/uaccess.h:144:1: note: expected 'const void *' but argument is of type 'int'
    copy_from_user(void *to, const void __user *from, unsigned long n)
    ^~~~~~~~~~~~~~
   In file included from include/linux/string.h:6:0,
                    from drivers/media/dvb-core/dvb_frontend.c:30:
   drivers/media/dvb-core/dvb_frontend.c:2049:29: warning: passing argument 2 of 'copy_from_user' makes pointer from integer without a cast [-Wint-conversion]
      if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
                                ^
   include/linux/compiler.h:58:42: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                             ^~~~
   drivers/media/dvb-core/dvb_frontend.c:2049:3: note: in expansion of macro 'if'
      if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
      ^~
   In file included from include/linux/poll.h:12:0,
                    from drivers/media/dvb-core/dvb_frontend.c:35:
   include/linux/uaccess.h:144:1: note: expected 'const void *' but argument is of type 'int'
    copy_from_user(void *to, const void __user *from, unsigned long n)
    ^~~~~~~~~~~~~~
   In file included from include/linux/string.h:6:0,
                    from drivers/media/dvb-core/dvb_frontend.c:30:
   drivers/media/dvb-core/dvb_frontend.c:2049:29: warning: passing argument 2 of 'copy_from_user' makes pointer from integer without a cast [-Wint-conversion]
      if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
                                ^
   include/linux/compiler.h:69:16: note: in definition of macro '__trace_if'
      ______r = !!(cond);     \
                   ^~~~
   drivers/media/dvb-core/dvb_frontend.c:2049:3: note: in expansion of macro 'if'
      if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
      ^~
   In file included from include/linux/poll.h:12:0,
                    from drivers/media/dvb-core/dvb_frontend.c:35:
   include/linux/uaccess.h:144:1: note: expected 'const void *' but argument is of type 'int'
    copy_from_user(void *to, const void __user *from, unsigned long n)
    ^~~~~~~~~~~~~~
   drivers/media/dvb-core/dvb_frontend.c:2061:21: warning: passing argument 1 of 'memdup_user' makes pointer from integer without a cast [-Wint-conversion]
      tvp = memdup_user(compat_ptr(tvps->props), tvps->num * sizeof(*tvp));
                        ^~~~~~~~~~
   In file included from drivers/media/dvb-core/dvb_frontend.c:30:0:
   include/linux/string.h:13:14: note: expected 'const void *' but argument is of type 'int'
    extern void *memdup_user(const void __user *, size_t);
                 ^~~~~~~~~~~
   In file included from include/linux/string.h:6:0,
                    from drivers/media/dvb-core/dvb_frontend.c:30:
   drivers/media/dvb-core/dvb_frontend.c:2087:20: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
      if (copy_to_user((void __user *)compat_ptr(tvps->props), tvp,
                       ^
   include/linux/compiler.h:58:30: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                 ^~~~
   drivers/media/dvb-core/dvb_frontend.c:2087:3: note: in expansion of macro 'if'
      if (copy_to_user((void __user *)compat_ptr(tvps->props), tvp,
      ^~
   drivers/media/dvb-core/dvb_frontend.c:2087:20: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
      if (copy_to_user((void __user *)compat_ptr(tvps->props), tvp,
                       ^
   include/linux/compiler.h:58:42: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                             ^~~~
   drivers/media/dvb-core/dvb_frontend.c:2087:3: note: in expansion of macro 'if'
      if (copy_to_user((void __user *)compat_ptr(tvps->props), tvp,
      ^~
   drivers/media/dvb-core/dvb_frontend.c:2087:20: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
      if (copy_to_user((void __user *)compat_ptr(tvps->props), tvp,
                       ^
   include/linux/compiler.h:69:16: note: in definition of macro '__trace_if'
      ______r = !!(cond);     \
                   ^~~~
   drivers/media/dvb-core/dvb_frontend.c:2087:3: note: in expansion of macro 'if'
      if (copy_to_user((void __user *)compat_ptr(tvps->props), tvp,
      ^~
   drivers/media/dvb-core/dvb_frontend.c: At top level:
   include/linux/compiler.h:64:4: warning: '______f' is static but declared in inline function 'strcpy' which is not static

vim +/if +2018 drivers/media/dvb-core/dvb_frontend.c

  2005	
  2006	static int dvb_frontend_handle_compat_ioctl(struct file *file, unsigned int cmd,
  2007						    unsigned long arg)
  2008	{
  2009		struct dvb_device *dvbdev = file->private_data;
  2010		struct dvb_frontend *fe = dvbdev->priv;
  2011		struct dvb_frontend_private *fepriv = fe->frontend_priv;
  2012		int i, err = 0;
  2013	
  2014		if (cmd == COMPAT_FE_SET_PROPERTY) {
  2015			struct compat_dtv_properties prop, *tvps = NULL;
  2016			struct compat_dtv_property *tvp = NULL;
  2017	
> 2018			if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
  2019				return -EFAULT;
  2020	
  2021			tvps = &prop;
  2022	
  2023			/*
  2024			 * Put an arbitrary limit on the number of messages that can
  2025			 * be sent at once
  2026			 */
  2027			if (!tvps->num || (tvps->num > DTV_IOCTL_MAX_MSGS))
  2028				return -EINVAL;
  2029	
  2030			tvp = memdup_user(compat_ptr(tvps->props), tvps->num * sizeof(*tvp));
  2031			if (IS_ERR(tvp))
  2032				return PTR_ERR(tvp);
  2033	
  2034			for (i = 0; i < tvps->num; i++) {
  2035				err = dtv_property_process_set(fe, file,
  2036								(tvp + i)->cmd,
  2037								(tvp + i)->u.data);
  2038				if (err < 0) {
  2039					kfree(tvp);
  2040					return err;
  2041				}
  2042			}
  2043			kfree(tvp);
  2044		} else if (cmd == COMPAT_FE_GET_PROPERTY) {
  2045			struct compat_dtv_properties prop, *tvps = NULL;
  2046			struct compat_dtv_property *tvp = NULL;
  2047			struct dtv_frontend_properties getp = fe->dtv_property_cache;
  2048	
  2049			if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
  2050				return -EFAULT;
  2051	
  2052			tvps = &prop;
  2053	
  2054			/*
  2055			 * Put an arbitrary limit on the number of messages that can
  2056			 * be sent at once
  2057			 */
  2058			if (!tvps->num || (tvps->num > DTV_IOCTL_MAX_MSGS))
  2059				return -EINVAL;
  2060	
  2061			tvp = memdup_user(compat_ptr(tvps->props), tvps->num * sizeof(*tvp));
  2062			if (IS_ERR(tvp))
  2063				return PTR_ERR(tvp);
  2064	
  2065			/*
  2066			 * Let's use our own copy of property cache, in order to
  2067			 * avoid mangling with DTV zigzag logic, as drivers might
  2068			 * return crap, if they don't check if the data is available
  2069			 * before updating the properties cache.
  2070			 */
  2071			if (fepriv->state != FESTATE_IDLE) {
  2072				err = dtv_get_frontend(fe, &getp, NULL);
  2073				if (err < 0) {
  2074					kfree(tvp);
  2075					return err;
  2076				}
  2077			}
  2078			for (i = 0; i < tvps->num; i++) {
  2079				err = dtv_property_process_get(
  2080				    fe, &getp, (struct dtv_property *)tvp + i, file);
  2081				if (err < 0) {
  2082					kfree(tvp);
  2083					return err;
  2084				}
  2085			}
  2086	
  2087			if (copy_to_user((void __user *)compat_ptr(tvps->props), tvp,
  2088					 tvps->num * sizeof(struct compat_dtv_property))) {
  2089				kfree(tvp);
  2090				return -EFAULT;
  2091			}
  2092			kfree(tvp);
  2093		}
  2094	
  2095		return err;
  2096	}
  2097	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 32179 bytes --]

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

* Re: [PATCH 0/3] Add support compat in dvb_frontend.c
  2017-12-02  7:50 ` [PATCH 0/3] Add support compat in dvb_frontend.c Mauro Carvalho Chehab
@ 2017-12-13 14:30   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 10+ messages in thread
From: Mauro Carvalho Chehab @ 2017-12-13 14:30 UTC (permalink / raw)
  To: Jaedon Shin
  Cc: Shuah Khan, Colin Ian King, Satendra Singh Thakur, linux-media,
	Michael Ira Krufky, Sean Young

Em Sat, 2 Dec 2017 05:50:47 -0200
Mauro Carvalho Chehab <mchehab@kernel.org> escreveu:

> Hi Jaedon,
> 
> Em Fri,  1 Dec 2017 21:31:27 +0900
> Jaedon Shin <jaedon.shin@gmail.com> escreveu:
> 
> > This patch series supports compat ioctl for 32-bit user space applications
> > in 64-bit system.
> > 
> > Jaedon Shin (3):
> >   media: dvb_frontend: Add unlocked_ioctl in dvb_frontend.c
> >   media: dvb_frontend: Add compat_ioctl callback
> >   media: dvb_frontend: Add commands implementation for compat ioct  
> 
> Thanks for the series. Yeah, indeed we need something like that.
> 
> Yet, I suspect that you should also move the logic inside
> dvb_frontend_handle_ioctl() with copies from/to userspace.
> 
> We don't want the logic there to be called when a 32-bit userspace
> copy happens, as it should now use the new compat32 code.

Nevermind. After reviewing it carefully, the way you handled is OK.

It seems that only thing you missed were to add an include
to linux/compat.h.

I'll add it and apply this patchset.

Thanks,
Mauro

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

end of thread, other threads:[~2017-12-13 14:30 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-01 12:31 [PATCH 0/3] Add support compat in dvb_frontend.c Jaedon Shin
2017-12-01 12:31 ` [PATCH 1/3] media: dvb_frontend: Add unlocked_ioctl " Jaedon Shin
2017-12-01 12:31 ` [PATCH 2/3] media: dvb_frontend: Add compat_ioctl callback Jaedon Shin
2017-12-04 14:29   ` kbuild test robot
2017-12-01 12:31 ` [PATCH 3/3] media: dvb_frontend: Add commands implementation for compat ioct Jaedon Shin
2017-12-04 12:56   ` kbuild test robot
2017-12-04 13:46   ` Menion
2017-12-04 18:33   ` kbuild test robot
2017-12-02  7:50 ` [PATCH 0/3] Add support compat in dvb_frontend.c Mauro Carvalho Chehab
2017-12-13 14:30   ` Mauro Carvalho Chehab

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).