All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/3] Convert ppdev to y2038 safe
@ 2016-01-08  7:50 Bamvor Jian Zhang
  2016-01-08  7:50 ` [PATCH v4 1/3] ppdev: convert " Bamvor Jian Zhang
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Bamvor Jian Zhang @ 2016-01-08  7:50 UTC (permalink / raw)
  To: linux-kernel
  Cc: y2038, gregkh, arnd, sudipm.mukherjee, broonie, Bamvor Jian Zhang

These series of patches try to convert parport device(ppdev) to
y2038 safe, and support y2038 safe and unsafe application at the
same time. The first two version is here[1][2][3].

An y2038 safe application/kernel use 64bit time_t(aka time64_t)
to avoid 32-bit time types broken in the year 2038. Given that
some time relative struct(e.g. timeval in ppdev.c) is mainly the
offset of the real time, the old 32bit time_t in such application
is safe. We need to handle the 32bit time_t and 64bit time_t
application at the same time. My approach here is handle them as
different ioctl command for different size of timeval.

Build successful on arm64, arm and x86_64 with C=1.

Changes since v3:
1.  Remove the useless compat ioctl in fs/compat_ioctl.c for
    parport device.

Changes since v2:
1.  Fix the wrong parameter in copy_to_user.

Changes since v1:
1.  Fix the warning when build against x86_64.

[1] https://lkml.org/lkml/2015/12/9/32
[2] https://lkml.org/lkml/2015/12/17/111
[3] http://www.spinics.net/lists/y2038/msg01059.html

Bamvor Jian Zhang (3):
  ppdev: convert to y2038 safe
  ppdev: add support for compat ioctl
  fs/compat: remove useless compat ioctl for parport device

 drivers/char/ppdev.c | 87 ++++++++++++++++++++++++++++++++++++++++------------
 fs/compat_ioctl.c    | 22 -------------
 2 files changed, 67 insertions(+), 42 deletions(-)

-- 
2.1.4

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

* [PATCH v4 1/3] ppdev: convert to y2038 safe
  2016-01-08  7:50 [PATCH v4 0/3] Convert ppdev to y2038 safe Bamvor Jian Zhang
@ 2016-01-08  7:50 ` Bamvor Jian Zhang
  2016-01-08  7:50 ` [PATCH v4 2/3] ppdev: add support for compat ioctl Bamvor Jian Zhang
  2016-01-08  7:50 ` [PATCH v4 3/3] fs/compat: remove useless compat ioctl for parport device Bamvor Jian Zhang
  2 siblings, 0 replies; 4+ messages in thread
From: Bamvor Jian Zhang @ 2016-01-08  7:50 UTC (permalink / raw)
  To: linux-kernel
  Cc: y2038, gregkh, arnd, sudipm.mukherjee, broonie, Bamvor Jian Zhang

The y2038 issue for ppdev is changes of timeval in the ioctl
(PPSETTIME and PPGETTIME). The size of struct timeval changes from
8bytes to 16bytes due to the changes of time_t. It lead to the
changes of the command of ioctl, e.g. for PPGETTIME, We have:

on 32-bit (old): 0x80087095
on 32-bit (new): 0x80107095
on 64-bit      : 0x80107095

This patch define these two ioctl commands to support the 32bit
and 64bit time_t application at the same time. And, introduce
pp_set_timeout to remove some duplicated code.

Signed-off-by: Bamvor Jian Zhang <bamvor.zhangjian@linaro.org>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Tested-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
---
 drivers/char/ppdev.c | 75 ++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 55 insertions(+), 20 deletions(-)

diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c
index ae0b42b..c03d998 100644
--- a/drivers/char/ppdev.c
+++ b/drivers/char/ppdev.c
@@ -98,6 +98,13 @@ struct pp_struct {
 #define ROUND_UP(x,y) (((x)+(y)-1)/(y))
 
 static DEFINE_MUTEX(pp_do_mutex);
+
+/* define fixed sized ioctl cmd for y2038 migration */
+#define PPGETTIME32	_IOR(PP_IOCTL, 0x95, s32[2])
+#define PPSETTIME32	_IOW(PP_IOCTL, 0x96, s32[2])
+#define PPGETTIME64	_IOR(PP_IOCTL, 0x95, s64[2])
+#define PPSETTIME64	_IOW(PP_IOCTL, 0x96, s64[2])
+
 static inline void pp_enable_irq (struct pp_struct *pp)
 {
 	struct parport *port = pp->pdev->port;
@@ -322,6 +329,22 @@ static enum ieee1284_phase init_phase (int mode)
 	return IEEE1284_PH_FWD_IDLE;
 }
 
+static int pp_set_timeout(struct pardevice *pdev, long tv_sec, int tv_usec)
+{
+	long to_jiffies;
+
+	if ((tv_sec < 0) || (tv_usec < 0))
+		return -EINVAL;
+
+	to_jiffies = usecs_to_jiffies(tv_usec);
+	to_jiffies += tv_sec * HZ;
+	if (to_jiffies <= 0)
+		return -EINVAL;
+
+	pdev->timeout = to_jiffies;
+	return 0;
+}
+
 static int pp_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
 	unsigned int minor = iminor(file_inode(file));
@@ -495,9 +518,10 @@ static int pp_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 		unsigned char reg;
 		unsigned char mask;
 		int mode;
+		s32 time32[2];
+		s64 time64[2];
+		struct timespec64 ts;
 		int ret;
-		struct timeval par_timeout;
-		long to_jiffies;
 
 	case PPRSTATUS:
 		reg = parport_read_status (port);
@@ -592,29 +616,40 @@ static int pp_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 		atomic_sub (ret, &pp->irqc);
 		return 0;
 
-	case PPSETTIME:
-		if (copy_from_user (&par_timeout, argp, sizeof(struct timeval))) {
+	case PPSETTIME32:
+		if (copy_from_user(time32, argp, sizeof(time32)))
 			return -EFAULT;
-		}
-		/* Convert to jiffies, place in pp->pdev->timeout */
-		if ((par_timeout.tv_sec < 0) || (par_timeout.tv_usec < 0)) {
-			return -EINVAL;
-		}
-		to_jiffies = ROUND_UP(par_timeout.tv_usec, 1000000/HZ);
-		to_jiffies += par_timeout.tv_sec * (long)HZ;
-		if (to_jiffies <= 0) {
+
+		return pp_set_timeout(pp->pdev, time32[0], time32[1]);
+
+	case PPSETTIME64:
+		if (copy_from_user(time64, argp, sizeof(time64)))
+			return -EFAULT;
+
+		return pp_set_timeout(pp->pdev, time64[0], time64[1]);
+
+	case PPGETTIME32:
+		jiffies_to_timespec64(pp->pdev->timeout, &ts);
+		time32[0] = ts.tv_sec;
+		time32[1] = ts.tv_nsec / NSEC_PER_USEC;
+		if ((time32[0] < 0) || (time32[1] < 0))
 			return -EINVAL;
-		}
-		pp->pdev->timeout = to_jiffies;
+
+		if (copy_to_user(argp, time32, sizeof(time32)))
+			return -EFAULT;
+
 		return 0;
 
-	case PPGETTIME:
-		to_jiffies = pp->pdev->timeout;
-		memset(&par_timeout, 0, sizeof(par_timeout));
-		par_timeout.tv_sec = to_jiffies / HZ;
-		par_timeout.tv_usec = (to_jiffies % (long)HZ) * (1000000/HZ);
-		if (copy_to_user (argp, &par_timeout, sizeof(struct timeval)))
+	case PPGETTIME64:
+		jiffies_to_timespec64(pp->pdev->timeout, &ts);
+		time64[0] = ts.tv_sec;
+		time64[1] = ts.tv_nsec / NSEC_PER_USEC;
+		if ((time64[0] < 0) || (time64[1] < 0))
+			return -EINVAL;
+
+		if (copy_to_user(argp, time64, sizeof(time64)))
 			return -EFAULT;
+
 		return 0;
 
 	default:
-- 
2.1.4

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

* [PATCH v4 2/3] ppdev: add support for compat ioctl
  2016-01-08  7:50 [PATCH v4 0/3] Convert ppdev to y2038 safe Bamvor Jian Zhang
  2016-01-08  7:50 ` [PATCH v4 1/3] ppdev: convert " Bamvor Jian Zhang
@ 2016-01-08  7:50 ` Bamvor Jian Zhang
  2016-01-08  7:50 ` [PATCH v4 3/3] fs/compat: remove useless compat ioctl for parport device Bamvor Jian Zhang
  2 siblings, 0 replies; 4+ messages in thread
From: Bamvor Jian Zhang @ 2016-01-08  7:50 UTC (permalink / raw)
  To: linux-kernel
  Cc: y2038, gregkh, arnd, sudipm.mukherjee, broonie, Bamvor Jian Zhang

The arg of ioctl in ppdev is the pointer of integer except the
timeval in PPSETTIME, PPGETTIME. Different size of timeval
is already supported by the previous patches. So, it is safe
to add compat support.

Signed-off-by: Bamvor Jian Zhang <bamvor.zhangjian@linaro.org>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Tested-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
---
 drivers/char/ppdev.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c
index c03d998..9e98d01 100644
--- a/drivers/char/ppdev.c
+++ b/drivers/char/ppdev.c
@@ -69,6 +69,7 @@
 #include <linux/ppdev.h>
 #include <linux/mutex.h>
 #include <linux/uaccess.h>
+#include <linux/compat.h>
 
 #define PP_VERSION "ppdev: user-space parallel port driver"
 #define CHRDEV "ppdev"
@@ -670,6 +671,14 @@ static long pp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 	return ret;
 }
 
+#ifdef CONFIG_COMPAT
+static long pp_compat_ioctl(struct file *file, unsigned int cmd,
+		unsigned long arg)
+{
+	return pp_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
+}
+#endif
+
 static int pp_open (struct inode * inode, struct file * file)
 {
 	unsigned int minor = iminor(inode);
@@ -779,6 +788,9 @@ static const struct file_operations pp_fops = {
 	.write		= pp_write,
 	.poll		= pp_poll,
 	.unlocked_ioctl	= pp_ioctl,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl   = pp_compat_ioctl,
+#endif
 	.open		= pp_open,
 	.release	= pp_release,
 };
-- 
2.1.4

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

* [PATCH v4 3/3] fs/compat: remove useless compat ioctl for parport device
  2016-01-08  7:50 [PATCH v4 0/3] Convert ppdev to y2038 safe Bamvor Jian Zhang
  2016-01-08  7:50 ` [PATCH v4 1/3] ppdev: convert " Bamvor Jian Zhang
  2016-01-08  7:50 ` [PATCH v4 2/3] ppdev: add support for compat ioctl Bamvor Jian Zhang
@ 2016-01-08  7:50 ` Bamvor Jian Zhang
  2 siblings, 0 replies; 4+ messages in thread
From: Bamvor Jian Zhang @ 2016-01-08  7:50 UTC (permalink / raw)
  To: linux-kernel
  Cc: y2038, gregkh, arnd, sudipm.mukherjee, broonie, Bamvor Jian Zhang

Compat ioctl is already introduced in drivers/char/ppdev.c in order to
fix y2038 issue for PP[GS]ETTIME. There is no need to define these
here.

Suggested-by: Arnd Bergmann <arnd@arndb.de>
Tested-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Signed-off-by: Bamvor Jian Zhang <bamvor.zhangjian@linaro.org>
---
 fs/compat_ioctl.c | 22 ----------------------
 1 file changed, 22 deletions(-)

diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index eab31e7..1f2ae50 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -1019,28 +1019,6 @@ COMPATIBLE_IOCTL(PPPIOCGL2TPSTATS)
 /* PPPOX */
 COMPATIBLE_IOCTL(PPPOEIOCSFWD)
 COMPATIBLE_IOCTL(PPPOEIOCDFWD)
-/* ppdev */
-COMPATIBLE_IOCTL(PPSETMODE)
-COMPATIBLE_IOCTL(PPRSTATUS)
-COMPATIBLE_IOCTL(PPRCONTROL)
-COMPATIBLE_IOCTL(PPWCONTROL)
-COMPATIBLE_IOCTL(PPFCONTROL)
-COMPATIBLE_IOCTL(PPRDATA)
-COMPATIBLE_IOCTL(PPWDATA)
-COMPATIBLE_IOCTL(PPCLAIM)
-COMPATIBLE_IOCTL(PPRELEASE)
-COMPATIBLE_IOCTL(PPYIELD)
-COMPATIBLE_IOCTL(PPEXCL)
-COMPATIBLE_IOCTL(PPDATADIR)
-COMPATIBLE_IOCTL(PPNEGOT)
-COMPATIBLE_IOCTL(PPWCTLONIRQ)
-COMPATIBLE_IOCTL(PPCLRIRQ)
-COMPATIBLE_IOCTL(PPSETPHASE)
-COMPATIBLE_IOCTL(PPGETMODES)
-COMPATIBLE_IOCTL(PPGETMODE)
-COMPATIBLE_IOCTL(PPGETPHASE)
-COMPATIBLE_IOCTL(PPGETFLAGS)
-COMPATIBLE_IOCTL(PPSETFLAGS)
 /* Big A */
 /* sparc only */
 /* Big Q for sound/OSS */
-- 
2.1.4

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

end of thread, other threads:[~2016-01-08  7:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-08  7:50 [PATCH v4 0/3] Convert ppdev to y2038 safe Bamvor Jian Zhang
2016-01-08  7:50 ` [PATCH v4 1/3] ppdev: convert " Bamvor Jian Zhang
2016-01-08  7:50 ` [PATCH v4 2/3] ppdev: add support for compat ioctl Bamvor Jian Zhang
2016-01-08  7:50 ` [PATCH v4 3/3] fs/compat: remove useless compat ioctl for parport device Bamvor Jian Zhang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.