compat_ioctl.c removal, part 2/3
Subsystems (33)
v5 cover compat_ioctl.c removal, part 2/3
This is a follow-up to part 1/3 that I posted after -rc2. I hope these are still largely uncontroversial changes, and I would like to get them into linux-5.4.
Part 1 was in
https://lore.kernel.org/lkml/CAPcyv4i_nHzV155RcgnAQ189aq2Lfd2g8pA1D5NbZqo9E_u+Dw at mail.gmail.com/
Part 3 will be one kernel release after part 2 is merged, as that still needs a little extra work.
The entire series is available at
git://git.kernel.org/pub/scm/linux/kernel/git/arnd/playground.git compat_ioctl
Arnd
Al Viro (2):
compat_ioctl: unify copy-in of ppp filters
compat_ioctl: move PPPIOCSCOMPRESS to ppp_generic
Arnd Bergmann (16):
xfs: compat_ioctl: use compat_ptr()
xfs: compat_ioctl: add missing conversions
gfs2: add compat_ioctl support
fs: compat_ioctl: move FITRIM emulation into file systems
watchdog: cpwd: use generic compat_ptr_ioctl
compat_ioctl: move WDIOC handling into wdt drivers
compat_ioctl: reimplement SG_IO handling
af_unix: add compat_ioctl support
compat_ioctl: handle SIOCOUTQNSD
compat_ioctl: move SIOCOUTQ out of compat_ioctl.c
tty: handle compat PPP ioctls
compat_ioctl: handle PPPIOCGIDLE for 64-bit time_t
compat_ioctl: ppp: move simple commands into ppp_generic.c
compat_ioctl: move SG_GET_REQUEST_TABLE handling
pktcdvd: add compat_ioctl handler
scsi: sd: enable compat ioctls for sed-opal
Documentation/networking/ppp_generic.txt | 2 + arch/powerpc/platforms/52xx/mpc52xx_gpt.c | 1 + arch/um/drivers/harddog_kern.c | 1 + block/scsi_ioctl.c | 132 ++++++++- drivers/block/pktcdvd.c | 25 ++ drivers/char/ipmi/ipmi_watchdog.c | 1 + drivers/hwmon/fschmd.c | 1 + drivers/net/ppp/ppp_generic.c | 245 ++++++++++----- drivers/rtc/rtc-ds1374.c | 1 + drivers/scsi/sd.c | 14 +- drivers/scsi/sg.c | 59 +++- drivers/tty/tty_io.c | 5 + drivers/watchdog/acquirewdt.c | 1 + drivers/watchdog/advantechwdt.c | 1 + drivers/watchdog/alim1535_wdt.c | 1 + drivers/watchdog/alim7101_wdt.c | 1 + drivers/watchdog/ar7_wdt.c | 1 + drivers/watchdog/at91rm9200_wdt.c | 1 + drivers/watchdog/ath79_wdt.c | 1 + drivers/watchdog/bcm63xx_wdt.c | 1 + drivers/watchdog/cpu5wdt.c | 1 + drivers/watchdog/cpwd.c | 25 +- drivers/watchdog/eurotechwdt.c | 1 + drivers/watchdog/f71808e_wdt.c | 1 + drivers/watchdog/gef_wdt.c | 1 + drivers/watchdog/geodewdt.c | 1 + drivers/watchdog/ib700wdt.c | 1 + drivers/watchdog/ibmasr.c | 1 + drivers/watchdog/indydog.c | 1 + drivers/watchdog/intel_scu_watchdog.c | 1 + drivers/watchdog/iop_wdt.c | 1 + drivers/watchdog/it8712f_wdt.c | 1 + drivers/watchdog/ixp4xx_wdt.c | 1 + drivers/watchdog/ks8695_wdt.c | 1 + drivers/watchdog/m54xx_wdt.c | 1 + drivers/watchdog/machzwd.c | 1 + drivers/watchdog/mixcomwd.c | 1 + drivers/watchdog/mtx-1_wdt.c | 1 + drivers/watchdog/mv64x60_wdt.c | 1 + drivers/watchdog/nuc900_wdt.c | 1 + drivers/watchdog/nv_tco.c | 1 + drivers/watchdog/pc87413_wdt.c | 1 + drivers/watchdog/pcwd.c | 1 + drivers/watchdog/pcwd_pci.c | 1 + drivers/watchdog/pcwd_usb.c | 1 + drivers/watchdog/pika_wdt.c | 1 + drivers/watchdog/pnx833x_wdt.c | 1 + drivers/watchdog/rc32434_wdt.c | 1 + drivers/watchdog/rdc321x_wdt.c | 1 + drivers/watchdog/riowd.c | 1 + drivers/watchdog/sa1100_wdt.c | 1 + drivers/watchdog/sb_wdog.c | 1 + drivers/watchdog/sbc60xxwdt.c | 1 + drivers/watchdog/sbc7240_wdt.c | 1 + drivers/watchdog/sbc_epx_c3.c | 1 + drivers/watchdog/sbc_fitpc2_wdt.c | 1 + drivers/watchdog/sc1200wdt.c | 1 + drivers/watchdog/sc520_wdt.c | 1 + drivers/watchdog/sch311x_wdt.c | 1 + drivers/watchdog/scx200_wdt.c | 1 + drivers/watchdog/smsc37b787_wdt.c | 1 + drivers/watchdog/w83877f_wdt.c | 1 + drivers/watchdog/w83977f_wdt.c | 1 + drivers/watchdog/wafer5823wdt.c | 1 + drivers/watchdog/watchdog_dev.c | 1 + drivers/watchdog/wdrtas.c | 1 + drivers/watchdog/wdt.c | 1 + drivers/watchdog/wdt285.c | 1 + drivers/watchdog/wdt977.c | 1 + drivers/watchdog/wdt_pci.c | 1 + fs/compat_ioctl.c | 346 +--------------------- fs/ecryptfs/file.c | 1 + fs/ext4/ioctl.c | 1 + fs/f2fs/file.c | 1 + fs/gfs2/file.c | 24 ++ fs/hpfs/dir.c | 1 + fs/hpfs/file.c | 1 + fs/nilfs2/ioctl.c | 1 + fs/ocfs2/ioctl.c | 1 + fs/xfs/xfs_ioctl32.c | 11 +- include/linux/blkdev.h | 2 + include/uapi/linux/ppp-ioctl.h | 2 + include/uapi/linux/ppp_defs.h | 14 + lib/iov_iter.c | 1 + net/socket.c | 3 + net/unix/af_unix.c | 19 ++ 86 files changed, 526 insertions(+), 472 deletions(-)
Signature · 41 lines
2.20.0 Cc: davem at davemloft.net Cc: axboe at kernel.dk Cc: linux-block at vger.kernel.org Cc: minyard at acm.org Cc: gregkh at linuxfoundation.org Cc: linux at roeck-us.net Cc: alexandre.belloni at bootlin.com Cc: jejb at linux.ibm.com Cc: martin.petersen at oracle.com Cc: dgilbert at interlog.com Cc: jslaby at suse.com Cc: wim at linux-watchdog.org Cc: viro at zeniv.linux.org.uk Cc: tytso at mit.edu Cc: adilger.kernel at dilger.ca Cc: jaegeuk at kernel.org Cc: rpeterso at redhat.com Cc: agruenba at redhat.com Cc: mikulas at artax.karlin.mff.cuni.cz Cc: konishi.ryusuke at gmail.com Cc: jlbec at evilplan.org Cc: joseph.qi at linux.alibaba.com Cc: darrick.wong at oracle.com Cc: linux-xfs at vger.kernel.org Cc: netdev at vger.kernel.org Cc: linux-kernel at vger.kernel.org Cc: openipmi-developer at lists.sourceforge.net Cc: linux-hwmon at vger.kernel.org Cc: linux-ppp at vger.kernel.org Cc: linux-rtc at vger.kernel.org Cc: linux-scsi at vger.kernel.org Cc: linux-watchdog at vger.kernel.org Cc: linux-fsdevel at vger.kernel.org Cc: ecryptfs at vger.kernel.org Cc: linux-ext4 at vger.kernel.org Cc: linux-f2fs-devel at lists.sourceforge.net Cc: cluster-devel at redhat.com Cc: linux-nilfs at vger.kernel.org Cc: ocfs2-devel at oss.oracle.com
PATCH v5 3/18 gfs2: add compat_ioctl support
Out of the four ioctl commands supported on gfs2, only FITRIM works in compat mode.
Add a proper handler based on the ext4 implementation.
--- fs/gfs2/file.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
fs/gfs2/file.c +24 -0
@@ -6,6 +6,7 @@#include <linux/slab.h> #include <linux/spinlock.h> +#include <linux/compat.h> #include <linux/completion.h> #include <linux/buffer_head.h> #include <linux/pagemap.h>
@@ -354,6 +355,25 @@ static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)return -ENOTTY ; } +#ifdef CONFIG_COMPAT +static long gfs2_compat_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) +{ +/* These are just misnamed, they actually get/put from/to user an int */ +switch (cmd) { +case FS_IOC32_GETFLAGS : + cmd =FS_IOC_GETFLAGS ; +break ; +case FS_IOC32_SETFLAGS : + cmd =FS_IOC_SETFLAGS ; +break ; + } + +return gfs2_ioctl (filp, cmd, (unsigned long )compat_ptr (arg)); +} +#else +#define gfs2_compat_ioctl NULL +#endif +/** * gfs2_size_hint - Give a hint to the size of a write request * @filep: The struct file
@@ -1294,6 +1314,7 @@ const struct file_operations gfs2_file_fops = { .write_iter = gfs2_file_write_iter, .iopoll = iomap_dio_iopoll, .unlocked_ioctl = gfs2_ioctl, + .compat_ioctl = gfs2_compat_ioctl, .mmap = gfs2_mmap, .open = gfs2_open, .release = gfs2_release,
@@ -1309,6 +1330,7 @@ const struct file_operations gfs2_file_fops = {const struct file_operations gfs2_dir_fops = { .iterate_shared = gfs2_readdir, .unlocked_ioctl = gfs2_ioctl, + .compat_ioctl = gfs2_compat_ioctl, .open = gfs2_open, .release = gfs2_release, .fsync = gfs2_fsync,
@@ -1325,6 +1347,7 @@ const struct file_operations gfs2_file_fops_nolock = { .write_iter = gfs2_file_write_iter, .iopoll = iomap_dio_iopoll, .unlocked_ioctl = gfs2_ioctl, + .compat_ioctl = gfs2_compat_ioctl, .mmap = gfs2_mmap, .open = gfs2_open, .release = gfs2_release,
@@ -1338,6 +1361,7 @@ const struct file_operations gfs2_file_fops_nolock = {const struct file_operations gfs2_dir_fops_nolock = { .iterate_shared = gfs2_readdir, .unlocked_ioctl = gfs2_ioctl, + .compat_ioctl = gfs2_compat_ioctl, .open = gfs2_open, .release = gfs2_release, .fsync = gfs2_fsync,
Signature · 1 line
2.20.0
PATCH v5 4/18 fs: compat_ioctl: move FITRIM emulation into file systems
In reply to Arnd BergmannRemove the special case for FITRIM, and make file systems handle that like all other ioctl commands with their own handlers.
--- fs/compat_ioctl.c | 2 -- fs/ecryptfs/file.c | 1 + fs/ext4/ioctl.c | 1 + fs/f2fs/file.c | 1 + fs/hpfs/dir.c | 1 + fs/hpfs/file.c | 1 + fs/nilfs2/ioctl.c | 1 + fs/ocfs2/ioctl.c | 1 + 8 files changed, 7 insertions(+), 2 deletions(-)
fs/compat_ioctl.c +0 -2
@@ -345,8 +345,6 @@ static int ppp_scompress(struct file *file, unsigned int cmd,static unsigned int ioctl_pointer[] = {/* Little t */ COMPATIBLE_IOCTL(TIOCOUTQ) -/* 'X' - originally XFS but some now in the VFS */ -COMPATIBLE_IOCTL(FITRIM) #ifdef CONFIG_BLOCK/* Big S */ COMPATIBLE_IOCTL(SCSI_IOCTL_GET_IDLUN)
fs/ecryptfs/file.c +1 -0
@@ -378,6 +378,7 @@ ecryptfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)return rc;switch (cmd) { +case FITRIM :case FS_IOC32_GETFLAGS :case FS_IOC32_SETFLAGS :case FS_IOC32_GETVERSION :
fs/ext4/ioctl.c +1 -0
@@ -1227,6 +1227,7 @@ long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) }case EXT4_IOC_MOVE_EXT :case EXT4_IOC_RESIZE_FS : +case FITRIM :case EXT4_IOC_PRECACHE_EXTENTS :case EXT4_IOC_SET_ENCRYPTION_POLICY :case EXT4_IOC_GET_ENCRYPTION_PWSALT :
fs/f2fs/file.c +1 -0
@@ -3216,6 +3216,7 @@ long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)case F2FS_IOC_RELEASE_VOLATILE_WRITE :case F2FS_IOC_ABORT_VOLATILE_WRITE :case F2FS_IOC_SHUTDOWN : +case FITRIM :case F2FS_IOC_SET_ENCRYPTION_POLICY :case F2FS_IOC_GET_ENCRYPTION_PWSALT :case F2FS_IOC_GET_ENCRYPTION_POLICY :
fs/hpfs/dir.c +1 -0
@@ -325,4 +325,5 @@ const struct file_operations hpfs_dir_ops = .release = hpfs_dir_release, .fsync = hpfs_file_fsync, .unlocked_ioctl = hpfs_ioctl, + .compat_ioctl = compat_ptr_ioctl, };
fs/hpfs/file.c +1 -0
@@ -215,6 +215,7 @@ const struct file_operations hpfs_file_ops = .fsync = hpfs_file_fsync, .splice_read = generic_file_splice_read, .unlocked_ioctl = hpfs_ioctl, + .compat_ioctl = compat_ptr_ioctl, }; const struct inode_operations hpfs_file_iops =
fs/nilfs2/ioctl.c +1 -0
@@ -1354,6 +1354,7 @@ long nilfs_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)case NILFS_IOCTL_SYNC :case NILFS_IOCTL_RESIZE :case NILFS_IOCTL_SET_ALLOC_RANGE : +case FITRIM :break ;default :return -ENOIOCTLCMD ;
fs/ocfs2/ioctl.c +1 -0
@@ -985,6 +985,7 @@ long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg)return -EFAULT ;return ocfs2_info_handle (inode, &info,1 ); +case FITRIM :case OCFS2_IOC_MOVE_EXT :break ;default :
Signature · 1 line
2.20.0
PATCH v5 1/18 xfs: compat_ioctl: use compat_ptr()
In reply to Arnd BergmannFor 31-bit s390 user space, we have to pass pointer arguments through compat_ptr() in the compat_ioctl handler.
--- fs/xfs/xfs_ioctl32.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/xfs/xfs_ioctl32.c +4 -4
@@ -547,7 +547,7 @@ xfs_file_compat_ioctl(struct inode *inode =file_inode (filp);struct xfs_inode *ip =XFS_I (inode);struct xfs_mount *mp = ip->i_mount; -void __user *arg = (void __user *)p; +void __user *arg =compat_ptr (p);int error;trace_xfs_file_compat_ioctl (ip);
@@ -576,7 +576,7 @@ xfs_file_compat_ioctl(case XFS_IOC_SCRUB_METADATA :case XFS_IOC_BULKSTAT :case XFS_IOC_INUMBERS : -return xfs_file_ioctl (filp, cmd, p); +return xfs_file_ioctl (filp, cmd, (unsigned long )arg);#if !defined(BROKEN_X86_ALIGNMENT ) || defined(CONFIG_X86_X32 )/* * These are handled fine if no alignment issues. To support x32
@@ -602,7 +602,7 @@ xfs_file_compat_ioctl(*/ case XFS_IOC_SWAPEXT :#endif -return xfs_file_ioctl (filp, cmd, p); +return xfs_file_ioctl (filp, cmd, (unsigned long )arg);#endif #if defined(BROKEN_X86_ALIGNMENT )case XFS_IOC_ALLOCSP_32 :
@@ -653,7 +653,7 @@ xfs_file_compat_ioctl(case XFS_IOC_SETXFLAGS_32 :case XFS_IOC_GETVERSION_32 : cmd =_NATIVE_IOC (cmd, long); -return xfs_file_ioctl (filp, cmd, p); +return xfs_file_ioctl (filp, cmd, (unsigned long )arg);case XFS_IOC_SWAPEXT_32 : {struct xfs_swapext sxp;struct compat_xfs_swapext __user *sxu = arg;
Signature · 1 line
2.20.0
PATCH v5 2/18 xfs: compat_ioctl: add missing conversions
In reply to Arnd BergmannFS_IOC_GETFSLABEL/FS_IOC_SETFSLABEL were added in linux-4.18 in xfs, but not in the compat_ioctl case, so add them here.
FITRIM was added earlier and also lacks a line the same function, but this is ok because there is an entry in fs/compat_ioctl.c for it.
Adding all three here to keep the native and compat ioctl handlers in sync.
--- fs/xfs/xfs_ioctl32.c | 3 +++ 1 file changed, 3 insertions(+)
fs/xfs/xfs_ioctl32.c +3 -0
@@ -576,6 +576,9 @@ xfs_file_compat_ioctl(case XFS_IOC_SCRUB_METADATA :case XFS_IOC_BULKSTAT :case XFS_IOC_INUMBERS : +case FITRIM : +case FS_IOC_GETFSLABEL : +case FS_IOC_SETFSLABEL :return xfs_file_ioctl (filp, cmd, (unsigned long )arg);#if !defined(BROKEN_X86_ALIGNMENT ) || defined(CONFIG_X86_X32 )/*
Signature · 1 line
2.20.0
PATCH v5 5/18 watchdog: cpwd: use generic compat_ptr_ioctl
In reply to Arnd BergmannThe cpwd_compat_ioctl() contains a bogus mutex that dates back to a leftover BKL instance.
Simplify the implementation by using the new compat_ptr_ioctl() helper function that will do the right thing for all calls here.
Note that WIOCSTART/WIOCSTOP don't take any arguments, so the compat_ptr() conversion is not needed here, but it also doesn't hurt.
--- drivers/watchdog/cpwd.c | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-)
drivers/watchdog/cpwd.c +1 -24
@@ -473,29 +473,6 @@ static long cpwd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)return 0 ; } -static long cpwd_compat_ioctl (struct file *file,unsigned int cmd, -unsigned long arg) -{ -int rval = -ENOIOCTLCMD ; - -switch (cmd) { -/* solaris ioctls are specific to this driver */ -case WIOCSTART : -case WIOCSTOP : -case WIOCGSTAT : -mutex_lock (&cpwd_mutex); - rval =cpwd_ioctl (file, cmd, arg); -mutex_unlock (&cpwd_mutex); -break ; - -/* everything else is handled by the generic compat layer */ -default : -break ; - } - -return rval; -} -static ssize_t cpwd_write (struct file *file,const char __user *buf,size_t count,loff_t *ppos) {
@@ -520,7 +497,7 @@ static ssize_t cpwd_read(struct file *file, char __user *buffer,static const struct file_operations cpwd_fops = { .owner =THIS_MODULE , .unlocked_ioctl = cpwd_ioctl, - .compat_ioctl = cpwd_compat_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = cpwd_open, .write = cpwd_write, .read = cpwd_read,
Signature · 1 line
2.20.0
PATCH v5 6/18 compat_ioctl: move WDIOC handling into wdt drivers
In reply to Arnd BergmannAll watchdog drivers implement the same set of ioctl commands, and fortunately all of them are compatible between 32-bit and 64-bit architectures.
Modern drivers always go through drivers/watchdog/wdt.c as an abstraction layer, but older ones implement their own file_operations on a character device for this.
Move the handling from fs/compat_ioctl.c into the individual drivers.
Note that most of the legacy drivers will never be used on 64-bit hardware, because they are for an old 32-bit SoC implementation, but doing them all at once is safer than trying to guess which ones do or do not need the compat_ioctl handling.
--- arch/powerpc/platforms/52xx/mpc52xx_gpt.c | 1 + arch/um/drivers/harddog_kern.c | 1 + drivers/char/ipmi/ipmi_watchdog.c | 1 + drivers/hwmon/fschmd.c | 1 + drivers/rtc/rtc-ds1374.c | 1 + drivers/watchdog/acquirewdt.c | 1 + drivers/watchdog/advantechwdt.c | 1 + drivers/watchdog/alim1535_wdt.c | 1 + drivers/watchdog/alim7101_wdt.c | 1 + drivers/watchdog/ar7_wdt.c | 1 + drivers/watchdog/at91rm9200_wdt.c | 1 + drivers/watchdog/ath79_wdt.c | 1 + drivers/watchdog/bcm63xx_wdt.c | 1 + drivers/watchdog/cpu5wdt.c | 1 + drivers/watchdog/eurotechwdt.c | 1 + drivers/watchdog/f71808e_wdt.c | 1 + drivers/watchdog/gef_wdt.c | 1 + drivers/watchdog/geodewdt.c | 1 + drivers/watchdog/ib700wdt.c | 1 + drivers/watchdog/ibmasr.c | 1 + drivers/watchdog/indydog.c | 1 + drivers/watchdog/intel_scu_watchdog.c | 1 + drivers/watchdog/iop_wdt.c | 1 + drivers/watchdog/it8712f_wdt.c | 1 + drivers/watchdog/ixp4xx_wdt.c | 1 + drivers/watchdog/ks8695_wdt.c | 1 + drivers/watchdog/m54xx_wdt.c | 1 + drivers/watchdog/machzwd.c | 1 + drivers/watchdog/mixcomwd.c | 1 + drivers/watchdog/mtx-1_wdt.c | 1 + drivers/watchdog/mv64x60_wdt.c | 1 + drivers/watchdog/nuc900_wdt.c | 1 + drivers/watchdog/nv_tco.c | 1 + drivers/watchdog/pc87413_wdt.c | 1 + drivers/watchdog/pcwd.c | 1 + drivers/watchdog/pcwd_pci.c | 1 + drivers/watchdog/pcwd_usb.c | 1 + drivers/watchdog/pika_wdt.c | 1 + drivers/watchdog/pnx833x_wdt.c | 1 + drivers/watchdog/rc32434_wdt.c | 1 + drivers/watchdog/rdc321x_wdt.c | 1 + drivers/watchdog/riowd.c | 1 + drivers/watchdog/sa1100_wdt.c | 1 + drivers/watchdog/sb_wdog.c | 1 + drivers/watchdog/sbc60xxwdt.c | 1 + drivers/watchdog/sbc7240_wdt.c | 1 + drivers/watchdog/sbc_epx_c3.c | 1 + drivers/watchdog/sbc_fitpc2_wdt.c | 1 + drivers/watchdog/sc1200wdt.c | 1 + drivers/watchdog/sc520_wdt.c | 1 + drivers/watchdog/sch311x_wdt.c | 1 + drivers/watchdog/scx200_wdt.c | 1 + drivers/watchdog/smsc37b787_wdt.c | 1 + drivers/watchdog/w83877f_wdt.c | 1 + drivers/watchdog/w83977f_wdt.c | 1 + drivers/watchdog/wafer5823wdt.c | 1 + drivers/watchdog/watchdog_dev.c | 1 + drivers/watchdog/wdrtas.c | 1 + drivers/watchdog/wdt.c | 1 + drivers/watchdog/wdt285.c | 1 + drivers/watchdog/wdt977.c | 1 + drivers/watchdog/wdt_pci.c | 1 + fs/compat_ioctl.c | 11 ----------- 63 files changed, 62 insertions(+), 11 deletions(-)
arch/powerpc/platforms/52xx/mpc52xx_gpt.c +1 -0
@@ -650,6 +650,7 @@ static const struct file_operations mpc52xx_wdt_fops = { .llseek = no_llseek, .write = mpc52xx_wdt_write, .unlocked_ioctl = mpc52xx_wdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = mpc52xx_wdt_open, .release = mpc52xx_wdt_release, };
arch/um/drivers/harddog_kern.c +1 -0
@@ -165,6 +165,7 @@ static const struct file_operations harddog_fops = { .owner = THIS_MODULE, .write = harddog_write, .unlocked_ioctl = harddog_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = harddog_open, .release = harddog_release, .llseek = no_llseek,
drivers/char/ipmi/ipmi_watchdog.c +1 -0
@@ -893,6 +893,7 @@ static const struct file_operations ipmi_wdog_fops = { .poll = ipmi_poll, .write = ipmi_write, .unlocked_ioctl = ipmi_unlocked_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = ipmi_open, .release = ipmi_close, .fasync = ipmi_fasync,
drivers/hwmon/fschmd.c +1 -0
@@ -954,6 +954,7 @@ static const struct file_operations watchdog_fops = { .release = watchdog_release, .write = watchdog_write, .unlocked_ioctl = watchdog_ioctl, + .compat_ioctl = compat_ptr_ioctl, };
drivers/rtc/rtc-ds1374.c +1 -0
@@ -586,6 +586,7 @@ static const struct file_operations ds1374_wdt_fops = { .owner = THIS_MODULE, .read = ds1374_wdt_read, .unlocked_ioctl = ds1374_wdt_unlocked_ioctl, + .compat_ioctl = compat_ptr_ioctl, .write = ds1374_wdt_write, .open = ds1374_wdt_open, .release = ds1374_wdt_release,
drivers/watchdog/acquirewdt.c +1 -0
@@ -221,6 +221,7 @@ static const struct file_operations acq_fops = { .llseek = no_llseek, .write = acq_write, .unlocked_ioctl = acq_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = acq_open, .release = acq_close, };
drivers/watchdog/advantechwdt.c +1 -0
@@ -220,6 +220,7 @@ static const struct file_operations advwdt_fops = { .llseek = no_llseek, .write = advwdt_write, .unlocked_ioctl = advwdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = advwdt_open, .release = advwdt_close, };
drivers/watchdog/alim1535_wdt.c +1 -0
@@ -362,6 +362,7 @@ static const struct file_operations ali_fops = { .llseek = no_llseek, .write = ali_write, .unlocked_ioctl = ali_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = ali_open, .release = ali_release, };
drivers/watchdog/alim7101_wdt.c +1 -0
@@ -294,6 +294,7 @@ static const struct file_operations wdt_fops = { .open = fop_open, .release = fop_close, .unlocked_ioctl = fop_ioctl, + .compat_ioctl = compat_ptr_ioctl, };static struct miscdevice wdt_miscdev = {
drivers/watchdog/ar7_wdt.c +1 -0
@@ -250,6 +250,7 @@ static const struct file_operations ar7_wdt_fops = { .owner = THIS_MODULE, .write = ar7_wdt_write, .unlocked_ioctl = ar7_wdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = ar7_wdt_open, .release = ar7_wdt_release, .llseek = no_llseek,
drivers/watchdog/at91rm9200_wdt.c +1 -0
@@ -213,6 +213,7 @@ static const struct file_operations at91wdt_fops = { .owner = THIS_MODULE, .llseek = no_llseek, .unlocked_ioctl = at91_wdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = at91_wdt_open, .release = at91_wdt_close, .write = at91_wdt_write,
drivers/watchdog/ath79_wdt.c +1 -0
@@ -234,6 +234,7 @@ static const struct file_operations ath79_wdt_fops = { .llseek = no_llseek, .write = ath79_wdt_write, .unlocked_ioctl = ath79_wdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = ath79_wdt_open, .release = ath79_wdt_release, };
drivers/watchdog/bcm63xx_wdt.c +1 -0
@@ -221,6 +221,7 @@ static const struct file_operations bcm63xx_wdt_fops = { .llseek = no_llseek, .write = bcm63xx_wdt_write, .unlocked_ioctl = bcm63xx_wdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = bcm63xx_wdt_open, .release = bcm63xx_wdt_release, };
drivers/watchdog/cpu5wdt.c +1 -0
@@ -187,6 +187,7 @@ static const struct file_operations cpu5wdt_fops = { .owner = THIS_MODULE, .llseek = no_llseek, .unlocked_ioctl = cpu5wdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = cpu5wdt_open, .write = cpu5wdt_write, .release = cpu5wdt_release,
drivers/watchdog/eurotechwdt.c +1 -0
@@ -371,6 +371,7 @@ static const struct file_operations eurwdt_fops = { .llseek = no_llseek, .write = eurwdt_write, .unlocked_ioctl = eurwdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = eurwdt_open, .release = eurwdt_release, };
drivers/watchdog/f71808e_wdt.c +1 -0
@@ -657,6 +657,7 @@ static const struct file_operations watchdog_fops = { .release = watchdog_release, .write = watchdog_write, .unlocked_ioctl = watchdog_ioctl, + .compat_ioctl = compat_ptr_ioctl, };static struct miscdevice watchdog_miscdev = {
drivers/watchdog/gef_wdt.c +1 -0
@@ -248,6 +248,7 @@ static const struct file_operations gef_wdt_fops = { .llseek = no_llseek, .write = gef_wdt_write, .unlocked_ioctl = gef_wdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = gef_wdt_open, .release = gef_wdt_release, };
drivers/watchdog/geodewdt.c +1 -0
@@ -201,6 +201,7 @@ static const struct file_operations geodewdt_fops = { .llseek = no_llseek, .write = geodewdt_write, .unlocked_ioctl = geodewdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = geodewdt_open, .release = geodewdt_release, };
drivers/watchdog/ib700wdt.c +1 -0
@@ -259,6 +259,7 @@ static const struct file_operations ibwdt_fops = { .llseek = no_llseek, .write = ibwdt_write, .unlocked_ioctl = ibwdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = ibwdt_open, .release = ibwdt_close, };
drivers/watchdog/ibmasr.c +1 -0
@@ -344,6 +344,7 @@ static const struct file_operations asr_fops = { .llseek = no_llseek, .write = asr_write, .unlocked_ioctl = asr_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = asr_open, .release = asr_release, };
drivers/watchdog/indydog.c +1 -0
@@ -152,6 +152,7 @@ static const struct file_operations indydog_fops = { .llseek = no_llseek, .write = indydog_write, .unlocked_ioctl = indydog_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = indydog_open, .release = indydog_release, };
drivers/watchdog/intel_scu_watchdog.c +1 -0
@@ -412,6 +412,7 @@ static const struct file_operations intel_scu_fops = { .llseek = no_llseek, .write = intel_scu_write, .unlocked_ioctl = intel_scu_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = intel_scu_open, .release = intel_scu_release, };
drivers/watchdog/iop_wdt.c +1 -0
@@ -202,6 +202,7 @@ static const struct file_operations iop_wdt_fops = { .llseek = no_llseek, .write = iop_wdt_write, .unlocked_ioctl = iop_wdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = iop_wdt_open, .release = iop_wdt_release, };
drivers/watchdog/it8712f_wdt.c +1 -0
@@ -345,6 +345,7 @@ static const struct file_operations it8712f_wdt_fops = { .llseek = no_llseek, .write = it8712f_wdt_write, .unlocked_ioctl = it8712f_wdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = it8712f_wdt_open, .release = it8712f_wdt_release, };
drivers/watchdog/ixp4xx_wdt.c +1 -0
@@ -163,6 +163,7 @@ static const struct file_operations ixp4xx_wdt_fops = { .llseek = no_llseek, .write = ixp4xx_wdt_write, .unlocked_ioctl = ixp4xx_wdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = ixp4xx_wdt_open, .release = ixp4xx_wdt_release, };
drivers/watchdog/ks8695_wdt.c +1 -0
@@ -221,6 +221,7 @@ static const struct file_operations ks8695wdt_fops = { .owner = THIS_MODULE, .llseek = no_llseek, .unlocked_ioctl = ks8695_wdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = ks8695_wdt_open, .release = ks8695_wdt_close, .write = ks8695_wdt_write,
drivers/watchdog/m54xx_wdt.c +1 -0
@@ -183,6 +183,7 @@ static const struct file_operations m54xx_wdt_fops = { .llseek = no_llseek, .write = m54xx_wdt_write, .unlocked_ioctl = m54xx_wdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = m54xx_wdt_open, .release = m54xx_wdt_release, };
drivers/watchdog/machzwd.c +1 -0
@@ -361,6 +361,7 @@ static const struct file_operations zf_fops = { .llseek = no_llseek, .write = zf_write, .unlocked_ioctl = zf_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = zf_open, .release = zf_close, };
drivers/watchdog/mixcomwd.c +1 -0
@@ -227,6 +227,7 @@ static const struct file_operations mixcomwd_fops = { .llseek = no_llseek, .write = mixcomwd_write, .unlocked_ioctl = mixcomwd_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = mixcomwd_open, .release = mixcomwd_release, };
drivers/watchdog/mtx-1_wdt.c +1 -0
@@ -181,6 +181,7 @@ static const struct file_operations mtx1_wdt_fops = { .owner = THIS_MODULE, .llseek = no_llseek, .unlocked_ioctl = mtx1_wdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = mtx1_wdt_open, .write = mtx1_wdt_write, .release = mtx1_wdt_release,
drivers/watchdog/mv64x60_wdt.c +1 -0
@@ -241,6 +241,7 @@ static const struct file_operations mv64x60_wdt_fops = { .llseek = no_llseek, .write = mv64x60_wdt_write, .unlocked_ioctl = mv64x60_wdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = mv64x60_wdt_open, .release = mv64x60_wdt_release, };
drivers/watchdog/nuc900_wdt.c +1 -0
@@ -225,6 +225,7 @@ static const struct file_operations nuc900wdt_fops = { .owner = THIS_MODULE, .llseek = no_llseek, .unlocked_ioctl = nuc900_wdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = nuc900_wdt_open, .release = nuc900_wdt_close, .write = nuc900_wdt_write,
drivers/watchdog/nv_tco.c +1 -0
@@ -267,6 +267,7 @@ static const struct file_operations nv_tco_fops = { .llseek = no_llseek, .write = nv_tco_write, .unlocked_ioctl = nv_tco_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = nv_tco_open, .release = nv_tco_release, };
drivers/watchdog/pc87413_wdt.c +1 -0
@@ -473,6 +473,7 @@ static const struct file_operations pc87413_fops = { .llseek = no_llseek, .write = pc87413_write, .unlocked_ioctl = pc87413_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = pc87413_open, .release = pc87413_release, };
drivers/watchdog/pcwd.c +1 -0
@@ -752,6 +752,7 @@ static const struct file_operations pcwd_fops = { .llseek = no_llseek, .write = pcwd_write, .unlocked_ioctl = pcwd_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = pcwd_open, .release = pcwd_close, };
drivers/watchdog/pcwd_pci.c +1 -0
@@ -646,6 +646,7 @@ static const struct file_operations pcipcwd_fops = { .llseek = no_llseek, .write = pcipcwd_write, .unlocked_ioctl = pcipcwd_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = pcipcwd_open, .release = pcipcwd_release, };
drivers/watchdog/pcwd_usb.c +1 -0
@@ -550,6 +550,7 @@ static const struct file_operations usb_pcwd_fops = { .llseek = no_llseek, .write = usb_pcwd_write, .unlocked_ioctl = usb_pcwd_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = usb_pcwd_open, .release = usb_pcwd_release, };
drivers/watchdog/pika_wdt.c +1 -0
@@ -214,6 +214,7 @@ static const struct file_operations pikawdt_fops = { .release = pikawdt_release, .write = pikawdt_write, .unlocked_ioctl = pikawdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, };static struct miscdevice pikawdt_miscdev = {
drivers/watchdog/pnx833x_wdt.c +1 -0
@@ -215,6 +215,7 @@ static const struct file_operations pnx833x_wdt_fops = { .llseek = no_llseek, .write = pnx833x_wdt_write, .unlocked_ioctl = pnx833x_wdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = pnx833x_wdt_open, .release = pnx833x_wdt_release, };
drivers/watchdog/rc32434_wdt.c +1 -0
@@ -245,6 +245,7 @@ static const struct file_operations rc32434_wdt_fops = { .llseek = no_llseek, .write = rc32434_wdt_write, .unlocked_ioctl = rc32434_wdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = rc32434_wdt_open, .release = rc32434_wdt_release, };
drivers/watchdog/rdc321x_wdt.c +1 -0
@@ -199,6 +199,7 @@ static const struct file_operations rdc321x_wdt_fops = { .owner = THIS_MODULE, .llseek = no_llseek, .unlocked_ioctl = rdc321x_wdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = rdc321x_wdt_open, .write = rdc321x_wdt_write, .release = rdc321x_wdt_release,
drivers/watchdog/riowd.c +1 -0
@@ -163,6 +163,7 @@ static const struct file_operations riowd_fops = { .owner = THIS_MODULE, .llseek = no_llseek, .unlocked_ioctl = riowd_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = riowd_open, .write = riowd_write, .release = riowd_release,
drivers/watchdog/sa1100_wdt.c +1 -0
@@ -141,6 +141,7 @@ static const struct file_operations sa1100dog_fops = { .llseek = no_llseek, .write = sa1100dog_write, .unlocked_ioctl = sa1100dog_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = sa1100dog_open, .release = sa1100dog_release, };
drivers/watchdog/sb_wdog.c +1 -0
@@ -237,6 +237,7 @@ static const struct file_operations sbwdog_fops = { .llseek = no_llseek, .write = sbwdog_write, .unlocked_ioctl = sbwdog_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = sbwdog_open, .release = sbwdog_release, };
drivers/watchdog/sbc60xxwdt.c +1 -0
@@ -280,6 +280,7 @@ static const struct file_operations wdt_fops = { .open = fop_open, .release = fop_close, .unlocked_ioctl = fop_ioctl, + .compat_ioctl = compat_ptr_ioctl, };static struct miscdevice wdt_miscdev = {
drivers/watchdog/sbc7240_wdt.c +1 -0
@@ -211,6 +211,7 @@ static const struct file_operations wdt_fops = { .open = fop_open, .release = fop_close, .unlocked_ioctl = fop_ioctl, + .compat_ioctl = compat_ptr_ioctl, };static struct miscdevice wdt_miscdev = {
drivers/watchdog/sbc_epx_c3.c +1 -0
@@ -156,6 +156,7 @@ static const struct file_operations epx_c3_fops = { .llseek = no_llseek, .write = epx_c3_write, .unlocked_ioctl = epx_c3_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = epx_c3_open, .release = epx_c3_release, };
drivers/watchdog/sbc_fitpc2_wdt.c +1 -0
@@ -186,6 +186,7 @@ static const struct file_operations fitpc2_wdt_fops = { .llseek = no_llseek, .write = fitpc2_wdt_write, .unlocked_ioctl = fitpc2_wdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = fitpc2_wdt_open, .release = fitpc2_wdt_release, };
drivers/watchdog/sc1200wdt.c +1 -0
@@ -307,6 +307,7 @@ static const struct file_operations sc1200wdt_fops = { .llseek = no_llseek, .write = sc1200wdt_write, .unlocked_ioctl = sc1200wdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = sc1200wdt_open, .release = sc1200wdt_release, };
drivers/watchdog/sc520_wdt.c +1 -0
@@ -336,6 +336,7 @@ static const struct file_operations wdt_fops = { .open = fop_open, .release = fop_close, .unlocked_ioctl = fop_ioctl, + .compat_ioctl = compat_ptr_ioctl, };static struct miscdevice wdt_miscdev = {
drivers/watchdog/sch311x_wdt.c +1 -0
@@ -337,6 +337,7 @@ static const struct file_operations sch311x_wdt_fops = { .llseek = no_llseek, .write = sch311x_wdt_write, .unlocked_ioctl = sch311x_wdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = sch311x_wdt_open, .release = sch311x_wdt_close, };
drivers/watchdog/scx200_wdt.c +1 -0
@@ -201,6 +201,7 @@ static const struct file_operations scx200_wdt_fops = { .llseek = no_llseek, .write = scx200_wdt_write, .unlocked_ioctl = scx200_wdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = scx200_wdt_open, .release = scx200_wdt_release, };
drivers/watchdog/smsc37b787_wdt.c +1 -0
@@ -505,6 +505,7 @@ static const struct file_operations wb_smsc_wdt_fops = { .llseek = no_llseek, .write = wb_smsc_wdt_write, .unlocked_ioctl = wb_smsc_wdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = wb_smsc_wdt_open, .release = wb_smsc_wdt_release, };
drivers/watchdog/w83877f_wdt.c +1 -0
@@ -304,6 +304,7 @@ static const struct file_operations wdt_fops = { .open = fop_open, .release = fop_close, .unlocked_ioctl = fop_ioctl, + .compat_ioctl = compat_ptr_ioctl, };static struct miscdevice wdt_miscdev = {
drivers/watchdog/w83977f_wdt.c +1 -0
@@ -446,6 +446,7 @@ static const struct file_operations wdt_fops = { .llseek = no_llseek, .write = wdt_write, .unlocked_ioctl = wdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = wdt_open, .release = wdt_release, };
drivers/watchdog/wafer5823wdt.c +1 -0
@@ -230,6 +230,7 @@ static const struct file_operations wafwdt_fops = { .llseek = no_llseek, .write = wafwdt_write, .unlocked_ioctl = wafwdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = wafwdt_open, .release = wafwdt_close, };
drivers/watchdog/watchdog_dev.c +1 -0
@@ -933,6 +933,7 @@ static const struct file_operations watchdog_fops = { .owner = THIS_MODULE, .write = watchdog_write, .unlocked_ioctl = watchdog_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = watchdog_open, .release = watchdog_release, };
drivers/watchdog/wdrtas.c +1 -0
@@ -472,6 +472,7 @@ static const struct file_operations wdrtas_fops = { .llseek = no_llseek, .write = wdrtas_write, .unlocked_ioctl = wdrtas_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = wdrtas_open, .release = wdrtas_close, };
drivers/watchdog/wdt.c +1 -0
@@ -523,6 +523,7 @@ static const struct file_operations wdt_fops = { .llseek = no_llseek, .write = wdt_write, .unlocked_ioctl = wdt_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = wdt_open, .release = wdt_release, };
drivers/watchdog/wdt285.c +1 -0
@@ -181,6 +181,7 @@ static const struct file_operations watchdog_fops = { .llseek = no_llseek, .write = watchdog_write, .unlocked_ioctl = watchdog_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = watchdog_open, .release = watchdog_release, };
drivers/watchdog/wdt977.c +1 -0
@@ -422,6 +422,7 @@ static const struct file_operations wdt977_fops = { .llseek = no_llseek, .write = wdt977_write, .unlocked_ioctl = wdt977_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = wdt977_open, .release = wdt977_release, };
drivers/watchdog/wdt_pci.c +1 -0
@@ -566,6 +566,7 @@ static const struct file_operations wdtpci_fops = { .llseek = no_llseek, .write = wdtpci_write, .unlocked_ioctl = wdtpci_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = wdtpci_open, .release = wdtpci_release, };
fs/compat_ioctl.c +0 -11
@@ -412,17 +412,6 @@ COMPATIBLE_IOCTL(PPPIOCDISCONN) COMPATIBLE_IOCTL(PPPIOCATTCHAN) COMPATIBLE_IOCTL(PPPIOCGCHAN) COMPATIBLE_IOCTL(PPPIOCGL2TPSTATS) -/* Watchdog */ -COMPATIBLE_IOCTL(WDIOC_GETSUPPORT) -COMPATIBLE_IOCTL(WDIOC_GETSTATUS) -COMPATIBLE_IOCTL(WDIOC_GETBOOTSTATUS) -COMPATIBLE_IOCTL(WDIOC_GETTEMP) -COMPATIBLE_IOCTL(WDIOC_SETOPTIONS) -COMPATIBLE_IOCTL(WDIOC_KEEPALIVE) -COMPATIBLE_IOCTL(WDIOC_SETTIMEOUT) -COMPATIBLE_IOCTL(WDIOC_GETTIMEOUT) -COMPATIBLE_IOCTL(WDIOC_SETPRETIMEOUT) -COMPATIBLE_IOCTL(WDIOC_GETPRETIMEOUT) };/*
Signature · 7 lines
2.20.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v5 7/18 compat_ioctl: reimplement SG_IO handling
In reply to Arnd BergmannThere are two code locations that implement the SG_IO ioctl: the old sg.c driver, and the generic scsi_ioctl helper that is in turn used by multiple drivers.
To eradicate the old compat_ioctl conversion handler for the SG_IO command, I implement a readable pair of put_sg_io_hdr() /get_sg_io_hdr() helper functions that can be used for both compat and native mode, and then I call this from both drivers.
For the iovec handling, there is already a compat_import_iovec() function that can simply be called in place of import_iovec().
To avoid having to pass the compat/native state through multiple indirections, I mark the SG_IO command itself as compatible in fs/compat_ioctl.c and use in_compat_syscall() to figure out where we are called from.
As a side-effect of this, the sg.c driver now also accepts the 32-bit sg_io_hdr format in compat mode using the read/write interface, not just ioctl. This should improve compatiblity with old 32-bit binaries, but it would break if any application intentionally passes the 64-bit data structure in compat mode here.
--- block/scsi_ioctl.c | 132 ++++++++++++++++++++++++++++++++++-- drivers/scsi/sg.c | 19 +++--- fs/compat_ioctl.c | 148 +---------------------------------------- include/linux/blkdev.h | 2 + lib/iov_iter.c | 1 + 5 files changed, 143 insertions(+), 159 deletions(-)
block/scsi_ioctl.c +128 -4
@@ -2,6 +2,7 @@/* * Copyright (C) 2001 Jens Axboe <[email protected]> */ +#include <linux/compat.h> #include <linux/kernel.h> #include <linux/errno.h> #include <linux/string.h>
@@ -327,7 +328,14 @@ static int sg_io(struct request_queue *q, struct gendisk *bd_disk,struct iov_iter i;struct iovec *iov =NULL ; - ret =import_iovec (rq_data_dir (rq), +#ifdef CONFIG_COMPAT +if (in_compat_syscall ()) + ret =compat_import_iovec (rq_data_dir (rq), + hdr->dxferp, hdr->iovec_count, +0 , &iov, &i); + else +#endif + ret =import_iovec (rq_data_dir (rq), hdr->dxferp, hdr->iovec_count,0 , &iov, &i);if (ret <0 )
@@ -542,6 +550,122 @@ static inline int blk_send_start_stop(struct request_queue *q,return __blk_send_generic (q, bd_disk,GPCMD_START_STOP_UNIT , data); } +#ifdef CONFIG_COMPAT +struct compat_sg_io_hdr { +compat_int_t interface_id;/* [i] 'S' for SCSI generic (required) */ +compat_int_t dxfer_direction;/* [i] data transfer direction */ +unsigned char cmd_len;/* [i] SCSI command length ( <= 16 bytes) */ +unsigned char mx_sb_len;/* [i] max length to write to sbp */ +unsigned short iovec_count;/* [i] 0 implies no scatter gather */ +compat_uint_t dxfer_len;/* [i] byte count of data transfer */ +compat_uint_t dxferp;/* [i], [*io] points to data transfer memory +or scatter gather list */ +compat_uptr_t cmdp;/* [i], [*i] points to command to perform */ +compat_uptr_t sbp;/* [i], [*o] points to sense_buffer memory */ +compat_uint_t timeout;/* [i] MAX_UINT->no timeout (unit: millisec) */ +compat_uint_t flags;/* [i] 0 -> default, see SG_FLAG... */ +compat_int_t pack_id;/* [i->o] unused internally (normally) */ +compat_uptr_t usr_ptr;/* [i->o] unused internally */ +unsigned char status;/* [o] scsi status */ +unsigned char masked_status;/* [o] shifted, masked scsi status */ +unsigned char msg_status;/* [o] messaging level data (optional) */ +unsigned char sb_len_wr;/* [o] byte count actually written to sbp */ +unsigned short host_status;/* [o] errors from host adapter */ +unsigned short driver_status;/* [o] errors from software driver */ +compat_int_t resid;/* [o] dxfer_len - actual_transferred */ +compat_uint_t duration;/* [o] time taken by cmd (unit: millisec) */ +compat_uint_t info;/* [o] auxiliary information */ +}; +#endif + +int put_sg_io_hdr (const struct sg_io_hdr *hdr,void __user *argp) +{ +#ifdef CONFIG_COMPAT +if (in_compat_syscall ()) { +struct compat_sg_io_hdr hdr32 = { + .interface_id = hdr->interface_id, + .dxfer_direction = hdr->dxfer_direction, + .cmd_len = hdr->cmd_len, + .mx_sb_len = hdr->mx_sb_len, + .iovec_count = hdr->iovec_count, + .dxfer_len = hdr->dxfer_len, + .dxferp = (uintptr_t )hdr->dxferp, + .cmdp = (uintptr_t )hdr->cmdp, + .sbp = (uintptr_t )hdr->sbp, + .timeout = hdr->timeout, + .flags = hdr->flags, + .pack_id = hdr->pack_id, + .usr_ptr = (uintptr_t )hdr->usr_ptr, + .status = hdr->status, + .masked_status = hdr->masked_status, + .msg_status = hdr->msg_status, + .sb_len_wr = hdr->sb_len_wr, + .host_status = hdr->host_status, + .driver_status = hdr->driver_status, + .resid = hdr->resid, + .duration = hdr->duration, + .info = hdr->info, + }; + +if (copy_to_user (argp, &hdr32,sizeof (hdr))) +return -EFAULT ; + +return 0 ; + } +#endif + +if (copy_to_user (argp, &hdr,sizeof (hdr))) +return -EFAULT ; + +return 0 ; +} +EXPORT_SYMBOL (put_sg_io_hdr); + +int get_sg_io_hdr (struct sg_io_hdr *hdr,const void __user *argp) +{ +#ifdef CONFIG_COMPAT +struct compat_sg_io_hdr hdr32; + +if (in_compat_syscall ()) { +if (copy_from_user (&hdr32, argp,sizeof (hdr32))) +return -EFAULT ; + + *hdr = (struct sg_io_hdr ) { + .interface_id = hdr32.interface_id, + .dxfer_direction = hdr32.dxfer_direction, + .cmd_len = hdr32.cmd_len, + .mx_sb_len = hdr32.mx_sb_len, + .iovec_count = hdr32.iovec_count, + .dxfer_len = hdr32.dxfer_len, + .dxferp =compat_ptr (hdr32.dxferp), + .cmdp =compat_ptr (hdr32.cmdp), + .sbp =compat_ptr (hdr32.sbp), + .timeout = hdr32.timeout, + .flags = hdr32.flags, + .pack_id = hdr32.pack_id, + .usr_ptr =compat_ptr (hdr32.usr_ptr), + .status = hdr32.status, + .masked_status = hdr32.masked_status, + .msg_status = hdr32.msg_status, + .sb_len_wr = hdr32.sb_len_wr, + .host_status = hdr32.host_status, + .driver_status = hdr32.driver_status, + .resid = hdr32.resid, + .duration = hdr32.duration, + .info = hdr32.info, + }; + +return 0 ; + } +#endif + +if (copy_from_user (&hdr, argp,sizeof (hdr))) +return -EFAULT ; + +return 0 ; +} +EXPORT_SYMBOL (get_sg_io_hdr); +int scsi_cmd_ioctl (struct request_queue *q,struct gendisk *bd_disk,fmode_t mode,unsigned int cmd,void __user *arg) {
@@ -581,14 +705,14 @@ int scsi_cmd_ioctl(struct request_queue *q, struct gendisk *bd_disk, fmode_t modcase SG_IO : {struct sg_io_hdr hdr; - err = -EFAULT ; -if (copy_from_user (&hdr, arg,sizeof (hdr))) + err =get_sg_io_hdr (&hdr, arg); +if (err)break ; err =sg_io (q, bd_disk, &hdr, mode);if (err == -EFAULT )break ; -if (copy_to_user (arg, &hdr,sizeof (hdr))) +if (put_sg_io_hdr (&hdr, arg)) err = -EFAULT ;break ; }
drivers/scsi/sg.c +11 -8
@@ -447,8 +447,7 @@ sg_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos) retval = -ENOMEM ; goto free_old_hdr; } - retval =__copy_from_user - (new_hdr, buf,SZ_SG_IO_HDR ); + retval =get_sg_io_hdr (new_hdr, buf); req_pack_id = new_hdr->pack_id;kfree (new_hdr);if (retval) {
@@ -589,10 +588,7 @@ sg_new_read(Sg_fd * sfp, char __user *buf, size_t count, Sg_request * srp) }if (hp->masked_status || hp->host_status || hp->driver_status) hp->info |=SG_INFO_CHECK ; -if (copy_to_user (buf, hp,SZ_SG_IO_HDR )) { - err = -EFAULT ; - goto err_out; - } + err =put_sg_io_hdr (hp, buf); err_out: err2 =sg_finish_rem_req (srp);sg_remove_request (sfp, srp);
@@ -735,7 +731,7 @@ sg_new_write(Sg_fd *sfp, struct file *file, const char __user *buf, } srp->sg_io_owned = sg_io_owned; hp = &srp->header; -if (__copy_from_user (hp, buf,SZ_SG_IO_HDR )) { +if (get_sg_io_hdr (hp, buf)) {sg_remove_request (sfp, srp);return -EFAULT ; }
@@ -1797,7 +1793,14 @@ sg_start_req(Sg_request *srp, unsigned char *cmd)struct iovec *iov =NULL ;struct iov_iter i; - res =import_iovec (rw, hp->dxferp, iov_count,0 , &iov, &i); +#ifdef CONFIG_COMPAT +if (in_compat_syscall ()) + res =compat_import_iovec (rw, hp->dxferp, iov_count, +0 , &iov, &i); + else +#endif + res =import_iovec (rw, hp->dxferp, iov_count, +0 , &iov, &i);if (res <0 )return res;
fs/compat_ioctl.c +1 -147
166 lines not on this page · raw message
include/linux/blkdev.h +2 -0
@@ -853,6 +853,8 @@ extern int scsi_cmd_ioctl(struct request_queue *, struct gendisk *, fmode_t, unsigned int, void __user *);extern int sg_scsi_ioctl (struct request_queue *,struct gendisk *,fmode_t ,struct scsi_ioctl_command __user *); +extern int get_sg_io_hdr (struct sg_io_hdr *hdr,const void __user *argp); +extern int put_sg_io_hdr (const struct sg_io_hdr *hdr,void __user *argp);extern int blk_queue_enter (struct request_queue *q,blk_mq_req_flags_t flags);extern void blk_queue_exit (struct request_queue *q);
lib/iov_iter.c +1 -0
@@ -1678,6 +1678,7 @@ ssize_t compat_import_iovec(int type, *iov = p == *iov ?NULL : p;return n; } +EXPORT_SYMBOL (compat_import_iovec);#endif int import_single_range(int rw, void __user *buf, size_t len,
Signature · 1 line
2.20.0
PATCH v5 8/18 af_unix: add compat_ioctl support
In reply to Arnd BergmannThe af_unix protocol family has a custom ioctl command (inexplicibly based on SIOCPROTOPRIVATE), but never had a compat_ioctl handler for 32-bit applications.
Since all commands are compatible here, add a trivial wrapper that performs the compat_ptr() conversion for SIOCOUTQ/SIOCINQ. SIOCUNIXFILE does not use the argument, but it doesn't hurt to also use compat_ptr() here.
--- net/unix/af_unix.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
net/unix/af_unix.c +19 -0
@@ -646,6 +646,9 @@ static __poll_t unix_poll(struct file *, struct socket *, poll_table *);static __poll_t unix_dgram_poll (struct file *,struct socket *,poll_table *);static int unix_ioctl (struct socket *,unsigned int ,unsigned long ); +#ifdef CONFIG_COMPAT +static int unix_compat_ioctl (struct socket *sock,unsigned int cmd,unsigned long arg); +#endif static int unix_shutdown (struct socket *,int );static int unix_stream_sendmsg (struct socket *,struct msghdr *,size_t );static int unix_stream_recvmsg (struct socket *,struct msghdr *,size_t ,int );
@@ -687,6 +690,9 @@ static const struct proto_ops unix_stream_ops = { .getname = unix_getname, .poll = unix_poll, .ioctl = unix_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = unix_compat_ioctl, +#endif .listen = unix_listen, .shutdown = unix_shutdown, .setsockopt = sock_no_setsockopt,
@@ -710,6 +716,9 @@ static const struct proto_ops unix_dgram_ops = { .getname = unix_getname, .poll = unix_dgram_poll, .ioctl = unix_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = unix_compat_ioctl, +#endif .listen = sock_no_listen, .shutdown = unix_shutdown, .setsockopt = sock_no_setsockopt,
@@ -732,6 +741,9 @@ static const struct proto_ops unix_seqpacket_ops = { .getname = unix_getname, .poll = unix_dgram_poll, .ioctl = unix_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = unix_compat_ioctl, +#endif .listen = unix_listen, .shutdown = unix_shutdown, .setsockopt = sock_no_setsockopt,
@@ -2582,6 +2594,13 @@ static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)return err; } +#ifdef CONFIG_COMPAT +static int unix_compat_ioctl (struct socket *sock,unsigned int cmd,unsigned long arg) +{ +return unix_ioctl (sock, cmd, (unsigned long )compat_ptr (arg)); +} +#endif +static __poll_t unix_poll (struct file *file,struct socket *sock,poll_table *wait) {struct sock *sk = sock->sk;
Signature · 1 line
2.20.0
PATCH v5 12/18 compat_ioctl: unify copy-in of ppp filters
In reply to Arnd BergmannFrom: Al Viro <[email protected]>
Now that isdn4linux is gone, the is only one implementation of PPPIOCSPASS and PPPIOCSACTIVE in ppp_generic.c, so this is where the compat_ioctl support should be implemented.
The two commands are implemented in very similar ways, so introduce new helpers to allow sharing between the two and between native and compat mode.
--- drivers/net/ppp/ppp_generic.c | 169 ++++++++++++++++++++++------------ fs/compat_ioctl.c | 37 -------- 2 files changed, 108 insertions(+), 98 deletions(-)
drivers/net/ppp/ppp_generic.c +108 -61
@@ -554,29 +554,58 @@ static __poll_t ppp_poll(struct file *file, poll_table *wait) }#ifdef CONFIG_PPP_FILTER -static int get_filter (void __user *arg,struct sock_filter **p) +static struct bpf_prog *get_filter (struct sock_fprog *uprog) +{ +struct sock_fprog_kern fprog; +struct bpf_prog *res =NULL ; +int err; + +if (!uprog->len) +return NULL ; + +/* uprog->len is unsigned short, so no overflow here */ + fprog.len = uprog->len *sizeof (struct sock_filter ); + fprog.filter =memdup_user (uprog->filter, fprog.len); +if (IS_ERR (fprog.filter)) +return ERR_CAST (fprog.filter); + + err =bpf_prog_create (&res, &fprog); +kfree (fprog.filter); + +return err ?ERR_PTR (err) : res; +} + +static struct bpf_prog *ppp_get_filter (struct sock_fprog __user *p) {struct sock_fprog uprog; -struct sock_filter *code =NULL ; -int len; -if (copy_from_user (&uprog, arg,sizeof (uprog))) -return -EFAULT ; +if (copy_from_user (&uprog, p,sizeof (struct sock_fprog ))) +return ERR_PTR (-EFAULT ); +return get_filter (&uprog); +} -if (!uprog.len) { - *p =NULL ; -return 0 ; - } +#ifdef CONFIG_COMPAT +struct sock_fprog32 { +unsigned short len; +compat_caddr_t filter; +}; - len = uprog.len *sizeof (struct sock_filter ); - code =memdup_user (uprog.filter, len); -if (IS_ERR (code)) -return PTR_ERR (code); +#define PPPIOCSPASS32 _IOW('t', 71, struct sock_fprog32) +#define PPPIOCSACTIVE32 _IOW('t', 70, struct sock_fprog32) - *p = code; -return uprog.len; +static struct bpf_prog *compat_ppp_get_filter (struct sock_fprog32 __user *p) +{ +struct sock_fprog32 uprog32; +struct sock_fprog uprog; + +if (copy_from_user (&uprog32, p,sizeof (struct sock_fprog32 ))) +return ERR_PTR (-EFAULT ); + uprog.len = uprog32.len; + uprog.filter =compat_ptr (uprog32.filter); +return get_filter (&uprog); } -#endif /* CONFIG_PPP_FILTER */ +#endif +#endif static long ppp_ioctl (struct file *file,unsigned int cmd,unsigned long arg) {
@@ -753,55 +782,25 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)#ifdef CONFIG_PPP_FILTER case PPPIOCSPASS : - { -struct sock_filter *code; - - err =get_filter (argp, &code); -if (err >=0 ) { -struct bpf_prog *pass_filter =NULL ; -struct sock_fprog_kern fprog = { - .len = err, - .filter = code, - }; - - err =0 ; -if (fprog.filter) - err =bpf_prog_create (&pass_filter, &fprog); -if (!err) { -ppp_lock (ppp); -if (ppp->pass_filter) -bpf_prog_destroy (ppp->pass_filter); - ppp->pass_filter = pass_filter; -ppp_unlock (ppp); - } -kfree (code); - } -break ; - }case PPPIOCSACTIVE : { -struct sock_filter *code; +struct bpf_prog *filter =ppp_get_filter (argp); +struct bpf_prog **which; - err =get_filter (argp, &code); -if (err >=0 ) { -struct bpf_prog *active_filter =NULL ; -struct sock_fprog_kern fprog = { - .len = err, - .filter = code, - }; - - err =0 ; -if (fprog.filter) - err =bpf_prog_create (&active_filter, &fprog); -if (!err) { -ppp_lock (ppp); -if (ppp->active_filter) -bpf_prog_destroy (ppp->active_filter); - ppp->active_filter = active_filter; -ppp_unlock (ppp); - } -kfree (code); +if (IS_ERR (filter)) { + err =PTR_ERR (filter); +break ; } +if (cmd =PPPIOCSPASS ) + which = &ppp->pass_filter; +else + which = &ppp->active_filter; +ppp_lock (ppp); +if (*which) +bpf_prog_destroy (*which); + *which = filter; +ppp_unlock (ppp); + err =0 ;break ; }#endif /* CONFIG_PPP_FILTER */
@@ -827,6 +826,51 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)return err; } +#ifdef CONFIG_COMPAT +static long ppp_compat_ioctl (struct file *file,unsigned int cmd,unsigned long arg) +{ +struct ppp_file *pf; +int err = -ENOIOCTLCMD ; +void __user *argp = (void __user *)arg; + +mutex_lock (&ppp_mutex); + + pf = file->private_data; +if (pf && pf->kind =INTERFACE ) { +struct ppp *ppp =PF_TO_PPP (pf); +switch (cmd) { +#ifdef CONFIG_PPP_FILTER +case PPPIOCSPASS32 : +case PPPIOCSACTIVE32 : + { +struct bpf_prog *filter =compat_ppp_get_filter (argp); +struct bpf_prog **which; + +if (IS_ERR (filter)) { + err =PTR_ERR (filter); +break ; + } +if (cmd =PPPIOCSPASS32 ) + which = &ppp->pass_filter; +else + which = &ppp->active_filter; +ppp_lock (ppp); +if (*which) +bpf_prog_destroy (*which); + *which = filter; +ppp_unlock (ppp); + err =0 ; +break ; + } +#endif /* CONFIG_PPP_FILTER */ + } + } +mutex_unlock (&ppp_mutex); + +return err; +} +#endif +static int ppp_unattached_ioctl (struct net *net,struct ppp_file *pf,struct file *file,unsigned int cmd,unsigned long arg) {
@@ -895,6 +939,9 @@ static const struct file_operations ppp_device_fops = { .write = ppp_write, .poll = ppp_poll, .unlocked_ioctl = ppp_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = ppp_compat_ioctl, +#endif .open = ppp_open, .release = ppp_release, .llseek = noop_llseek,
fs/compat_ioctl.c +0 -37
@@ -99,40 +99,6 @@ static int sg_grt_trans(struct file *file, }#endif /* CONFIG_BLOCK */ -struct sock_fprog32 { -unsigned short len; -compat_caddr_t filter; -}; - -#define PPPIOCSPASS32 _IOW('t', 71, struct sock_fprog32) -#define PPPIOCSACTIVE32 _IOW('t', 70, struct sock_fprog32) - -static int ppp_sock_fprog_ioctl_trans (struct file *file, -unsigned int cmd,struct sock_fprog32 __user *u_fprog32) -{ -struct sock_fprog __user *u_fprog64 =compat_alloc_user_space (sizeof (struct sock_fprog )); -void __user *fptr64; -u32 fptr32; -u16 flen; - -if (get_user (flen, &u_fprog32->len) || -get_user (fptr32, &u_fprog32->filter)) -return -EFAULT ; - - fptr64 =compat_ptr (fptr32); - -if (put_user (flen, &u_fprog64->len) || -put_user (fptr64, &u_fprog64->filter)) -return -EFAULT ; - -if (cmd =PPPIOCSPASS32 ) - cmd =PPPIOCSPASS ; -else - cmd =PPPIOCSACTIVE ; - -return do_ioctl (file, cmd, (unsigned long ) u_fprog64); -} -struct ppp_option_data32 {compat_caddr_t ptr;u32 length;
@@ -285,9 +251,6 @@ static long do_ioctl_trans(unsigned int cmd,return ppp_gidle (file, cmd, argp);case PPPIOCSCOMPRESS32 :return ppp_scompress (file, cmd, argp); -case PPPIOCSPASS32 : -case PPPIOCSACTIVE32 : -return ppp_sock_fprog_ioctl_trans (file, cmd, argp);#ifdef CONFIG_BLOCK case SG_GET_REQUEST_TABLE :return sg_grt_trans (file, cmd, argp);
Signature · 1 line
2.20.0
PATCH v5 13/18 compat_ioctl: move PPPIOCSCOMPRESS to ppp_generic
In reply to Arnd BergmannFrom: Al Viro <[email protected]>
Rather than using a compat_alloc_user_space() buffer, moving this next to the native handler allows sharing most of the code, leaving only the user copy portion distinct.
--- drivers/net/ppp/ppp_generic.c | 53 +++++++++++++++++++++++++---------- fs/compat_ioctl.c | 32 --------------------- 2 files changed, 38 insertions(+), 47 deletions(-)
drivers/net/ppp/ppp_generic.c +38 -15
@@ -270,7 +270,7 @@ static void ppp_mp_insert(struct ppp *ppp, struct sk_buff *skb);static struct sk_buff *ppp_mp_reconstruct (struct ppp *ppp);static int ppp_mp_explode (struct ppp *ppp,struct sk_buff *skb);#endif /* CONFIG_PPP_MULTILINK */ -static int ppp_set_compress (struct ppp *ppp,unsigned long arg); +static int ppp_set_compress (struct ppp *ppp,struct ppp_option_data *data);static void ppp_ccp_peek (struct ppp *ppp,struct sk_buff *skb,int inbound);static void ppp_ccp_closed (struct ppp *ppp);static struct compressor *find_compressor (int type);
@@ -708,9 +708,14 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)break ;case PPPIOCSCOMPRESS : - err =ppp_set_compress (ppp, arg); + { +struct ppp_option_data data; +if (copy_from_user (&data, argp,sizeof (data))) + err = -EFAULT ; +else + err =ppp_set_compress (ppp, &data);break ; - + }case PPPIOCGUNIT :if (put_user (ppp->file.index, p))break ;
@@ -827,6 +832,13 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg) }#ifdef CONFIG_COMPAT +struct ppp_option_data32 { +compat_uptr_t ptr; +u32 length; +compat_int_t transmit; +}; +#define PPPIOCSCOMPRESS32 _IOW('t', 77, struct ppp_option_data32) +static long ppp_compat_ioctl (struct file *file,unsigned int cmd,unsigned long arg) {struct ppp_file *pf;
@@ -863,6 +875,21 @@ static long ppp_compat_ioctl(struct file *file, unsigned int cmd, unsigned long break; }#endif /* CONFIG_PPP_FILTER */ +case PPPIOCSCOMPRESS32 : + { +struct ppp_option_data32 data32; +if (copy_from_user (&data32, argp,sizeof (data32))) { + err = -EFAULT ; + }else { +struct ppp_option_data data = { + .ptr =compat_ptr (data32.ptr), + .length = data32.length, + .transmit = data32.transmit + }; + err =ppp_set_compress (ppp, &data); + } +break ; + } } }mutex_unlock (&ppp_mutex);
@@ -2781,24 +2808,20 @@ ppp_output_wakeup(struct ppp_channel *chan)/* Process the PPPIOCSCOMPRESS ioctl. */ static int -ppp_set_compress (struct ppp *ppp,unsigned long arg) +ppp_set_compress (struct ppp *ppp,struct ppp_option_data *data) { -int err; +int err = -EFAULT ;struct compressor *cp, *ocomp; -struct ppp_option_data data;void *state, *ostate;unsigned char ccp_option[CCP_MAX_OPTION_LENGTH ]; - err = -EFAULT ; -if (copy_from_user (&data, (void __user *) arg,sizeof (data))) - goto out; -if (data.length >CCP_MAX_OPTION_LENGTH ) +if (data->length >CCP_MAX_OPTION_LENGTH ) goto out; -if (copy_from_user (ccp_option, (void __user *) data.ptr, data.length)) +if (copy_from_user (ccp_option, data->ptr, data->length)) goto out; err = -EINVAL ; -if (data.length <2 || ccp_option[1 ] <2 || ccp_option[1 ] > data.length) +if (data->length <2 || ccp_option[1 ] <2 || ccp_option[1 ] > data->length) goto out; cp = try_then_request_module(
@@ -2808,8 +2831,8 @@ ppp_set_compress(struct ppp *ppp, unsigned long arg) goto out; err = -ENOBUFS ; -if (data.transmit) { - state = cp->comp_alloc (ccp_option, data.length); +if (data->transmit) { + state = cp->comp_alloc (ccp_option, data->length);if (state) {ppp_xmit_lock (ppp); ppp->xstate &= ~SC_COMP_RUN ;
@@ -2827,7 +2850,7 @@ ppp_set_compress(struct ppp *ppp, unsigned long arg)module_put (cp->owner); }else { - state = cp->decomp_alloc (ccp_option, data.length); + state = cp->decomp_alloc (ccp_option, data->length);if (state) {ppp_recv_lock (ppp); ppp->rstate &= ~SC_DECOMP_RUN ;
fs/compat_ioctl.c +0 -32
@@ -99,13 +99,6 @@ static int sg_grt_trans(struct file *file, }#endif /* CONFIG_BLOCK */ -struct ppp_option_data32 { -compat_caddr_t ptr; -u32 length; -compat_int_t transmit; -}; -#define PPPIOCSCOMPRESS32 _IOW('t', 77, struct ppp_option_data32) -struct ppp_idle32 {compat_time_t xmit_idle;compat_time_t recv_idle;
@@ -133,29 +126,6 @@ static int ppp_gidle(struct file *file, unsigned int cmd,return err; } -static int ppp_scompress (struct file *file,unsigned int cmd, -struct ppp_option_data32 __user *odata32) -{ -struct ppp_option_data __user *odata; -__u32 data; -void __user *datap; - - odata =compat_alloc_user_space (sizeof (*odata)); - -if (get_user (data, &odata32->ptr)) -return -EFAULT ; - - datap =compat_ptr (data); -if (put_user (datap, &odata->ptr)) -return -EFAULT ; - -if (copy_in_user (&odata->length, &odata32->length, -sizeof (__u32) +sizeof (int ))) -return -EFAULT ; - -return do_ioctl (file,PPPIOCSCOMPRESS , (unsigned long ) odata); -} -/* * simple reversible transform to make our table more evenly * distributed after sorting.
@@ -249,8 +219,6 @@ static long do_ioctl_trans(unsigned int cmd,switch (cmd) {case PPPIOCGIDLE32 :return ppp_gidle (file, cmd, argp); -case PPPIOCSCOMPRESS32 : -return ppp_scompress (file, cmd, argp);#ifdef CONFIG_BLOCK case SG_GET_REQUEST_TABLE :return sg_grt_trans (file, cmd, argp);
Signature · 1 line
2.20.0
PATCH v5 14/18 compat_ioctl: handle PPPIOCGIDLE for 64-bit time_t
In reply to Arnd BergmannThe ppp_idle structure is defined in terms of __kernel_time_t, which is defined as 'long' on all architectures, and this usage is not affected by the y2038 problem since it transports a time interval rather than an absolute time.
However, the ppp user space defines the same structure as time_t, which may be 64-bit wide on new libc versions even on 32-bit architectures.
It's easy enough to just handle both possible structure layouts on all architectures, to deal with the possibility that a user space ppp implementation comes with its own ppp_idle structure definition, as well as to document the fact that the driver is y2038-safe.
Doing this also avoids the need for a special compat mode translation, since 32-bit and 64-bit kernels now support the same interfaces. The old 32-bit structure is also available on native 64-bit architectures now, but this is harmless.
--- Documentation/networking/ppp_generic.txt | 2 ++ drivers/net/ppp/ppp_generic.c | 19 ++++++++++---- fs/compat_ioctl.c | 32 ++---------------------- include/uapi/linux/ppp-ioctl.h | 2 ++ include/uapi/linux/ppp_defs.h | 14 +++++++++++ 5 files changed, 34 insertions(+), 35 deletions(-)
Documentation/networking/ppp_generic.txt +2 -0
@@ -378,6 +378,8 @@ an interface unit are: CONFIG_PPP_FILTER option is enabled, the set of packets which reset the transmit and receive idle timers is restricted to those which pass the `active' packet filter. + Two versions of this command exist, to deal with user space + expecting times as either 32-bit or 64-bit time_t seconds. * PPPIOCSMAXCID sets the maximum connection-ID parameter (and thus the number of connection slots) for the TCP header compressor and
drivers/net/ppp/ppp_generic.c +14 -5
@@ -612,7 +612,8 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)struct ppp_file *pf;struct ppp *ppp;int err = -EFAULT , val, val2, i; -struct ppp_idle idle; +struct ppp_idle32 idle32; +struct ppp_idle64 idle64;struct npioctl npi;int unit, cflags;struct slcompress *vj;
@@ -735,10 +736,18 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg) err =0 ;break ; -case PPPIOCGIDLE : - idle.xmit_idle = (jiffies - ppp->last_xmit) /HZ ; - idle.recv_idle = (jiffies - ppp->last_recv) /HZ ; -if (copy_to_user (argp, &idle,sizeof (idle))) +case PPPIOCGIDLE32 : + idle32.xmit_idle = (jiffies - ppp->last_xmit) /HZ ; + idle32.recv_idle = (jiffies - ppp->last_recv) /HZ ; +if (copy_to_user (argp, &idle32,sizeof (idle32))) +break ; + err =0 ; +break ; + +case PPPIOCGIDLE64 : + idle64.xmit_idle = (jiffies - ppp->last_xmit) /HZ ; + idle64.recv_idle = (jiffies - ppp->last_recv) /HZ ; +if (copy_to_user (argp, &idle64,sizeof (idle64)))break ; err =0 ;break ;
fs/compat_ioctl.c +2 -30
@@ -99,33 +99,6 @@ static int sg_grt_trans(struct file *file, }#endif /* CONFIG_BLOCK */ -struct ppp_idle32 { -compat_time_t xmit_idle; -compat_time_t recv_idle; -}; -#define PPPIOCGIDLE32 _IOR('t', 63, struct ppp_idle32) - -static int ppp_gidle (struct file *file,unsigned int cmd, -struct ppp_idle32 __user *idle32) -{ -struct ppp_idle __user *idle; -__kernel_time_t xmit, recv; -int err; - - idle =compat_alloc_user_space (sizeof (*idle)); - - err =do_ioctl (file,PPPIOCGIDLE , (unsigned long ) idle); - -if (!err) { -if (get_user (xmit, &idle->xmit_idle) || -get_user (recv, &idle->recv_idle) || -put_user (xmit, &idle32->xmit_idle) || -put_user (recv, &idle32->recv_idle)) - err = -EFAULT ; - } -return err; -} -/* * simple reversible transform to make our table more evenly * distributed after sorting.
@@ -192,7 +165,8 @@ COMPATIBLE_IOCTL(PPPIOCGDEBUG) COMPATIBLE_IOCTL(PPPIOCSDEBUG) /* PPPIOCSPASS is translated */ /* PPPIOCSACTIVE is translated */ -/* PPPIOCGIDLE is translated */ +COMPATIBLE_IOCTL(PPPIOCGIDLE32) +COMPATIBLE_IOCTL(PPPIOCGIDLE64) COMPATIBLE_IOCTL(PPPIOCNEWUNIT) COMPATIBLE_IOCTL(PPPIOCATTACH) COMPATIBLE_IOCTL(PPPIOCDETACH)
@@ -217,8 +191,6 @@ static long do_ioctl_trans(unsigned int cmd,void __user *argp =compat_ptr (arg);switch (cmd) { -case PPPIOCGIDLE32 : -return ppp_gidle (file, cmd, argp);#ifdef CONFIG_BLOCK case SG_GET_REQUEST_TABLE :return sg_grt_trans (file, cmd, argp);
include/uapi/linux/ppp-ioctl.h +2 -0
@@ -104,6 +104,8 @@ struct pppol2tp_ioc_stats {#define PPPIOCGDEBUG _IOR('t', 65, int)/* Read debug level */ #define PPPIOCSDEBUG _IOW('t', 64, int)/* Set debug level */ #define PPPIOCGIDLE _IOR('t', 63, struct ppp_idle)/* get idle time */ +#define PPPIOCGIDLE32 _IOR('t', 63, struct ppp_idle32)/* 32-bit times */ +#define PPPIOCGIDLE64 _IOR('t', 63, struct ppp_idle64)/* 64-bit times */ #define PPPIOCNEWUNIT _IOWR('t', 62, int)/* create new ppp unit */ #define PPPIOCATTACH _IOW('t', 61, int)/* attach to ppp unit */ #define PPPIOCDETACH _IOW('t', 60, int)/* obsolete, do not use */
include/uapi/linux/ppp_defs.h +14 -0
@@ -142,10 +142,24 @@ struct ppp_comp_stats {/* * The following structure records the time in seconds since * the last NP packet was sent or received. +* +* Linux implements both 32-bit and 64-bit time_t versions +* for compatibility with user space that defines ppp_idle +* based on the libc time_t. */ struct ppp_idle {__kernel_time_t xmit_idle;/* time since last NP packet sent */ __kernel_time_t recv_idle;/* time since last NP packet received */ }; +struct ppp_idle32 { +__s32 xmit_idle;/* time since last NP packet sent */ +__s32 recv_idle;/* time since last NP packet received */ +}; + +struct ppp_idle64 { +__s64 xmit_idle;/* time since last NP packet sent */ +__s64 recv_idle;/* time since last NP packet received */ +}; +#endif /* _UAPI_PPP_DEFS_H_ */
Signature · 1 line
2.20.0
PATCH v5 15/18 compat_ioctl: ppp: move simple commands into ppp_generic.c
In reply to Arnd BergmannAll ppp commands that are not already handled in ppp_compat_ioctl() are compatible, so they can now handled by calling the native ppp_ioctl() directly.
--- drivers/net/ppp/ppp_generic.c | 4 ++++ fs/compat_ioctl.c | 32 -------------------------------- 2 files changed, 4 insertions(+), 32 deletions(-)
drivers/net/ppp/ppp_generic.c +4 -0
@@ -903,6 +903,10 @@ static long ppp_compat_ioctl(struct file *file, unsigned int cmd, unsigned long }mutex_unlock (&ppp_mutex); +/* all other commands have compatible arguments */ +if (err = -ENOIOCTLCMD ) + err =ppp_ioctl (file, cmd, (unsigned long )compat_ptr (arg)); +return err; }#endif
fs/compat_ioctl.c +0 -32
@@ -144,38 +144,6 @@ COMPATIBLE_IOCTL(SG_GET_REQUEST_TABLE) COMPATIBLE_IOCTL(SG_SET_KEEP_ORPHAN) COMPATIBLE_IOCTL(SG_GET_KEEP_ORPHAN)#endif -/* PPP stuff */ -COMPATIBLE_IOCTL(PPPIOCGFLAGS) -COMPATIBLE_IOCTL(PPPIOCSFLAGS) -COMPATIBLE_IOCTL(PPPIOCGASYNCMAP) -COMPATIBLE_IOCTL(PPPIOCSASYNCMAP) -COMPATIBLE_IOCTL(PPPIOCGUNIT) -COMPATIBLE_IOCTL(PPPIOCGRASYNCMAP) -COMPATIBLE_IOCTL(PPPIOCSRASYNCMAP) -COMPATIBLE_IOCTL(PPPIOCGMRU) -COMPATIBLE_IOCTL(PPPIOCSMRU) -COMPATIBLE_IOCTL(PPPIOCSMAXCID) -COMPATIBLE_IOCTL(PPPIOCGXASYNCMAP) -COMPATIBLE_IOCTL(PPPIOCSXASYNCMAP) -COMPATIBLE_IOCTL(PPPIOCXFERUNIT) -/* PPPIOCSCOMPRESS is translated */ -COMPATIBLE_IOCTL(PPPIOCGNPMODE) -COMPATIBLE_IOCTL(PPPIOCSNPMODE) -COMPATIBLE_IOCTL(PPPIOCGDEBUG) -COMPATIBLE_IOCTL(PPPIOCSDEBUG) -/* PPPIOCSPASS is translated */ -/* PPPIOCSACTIVE is translated */ -COMPATIBLE_IOCTL(PPPIOCGIDLE32) -COMPATIBLE_IOCTL(PPPIOCGIDLE64) -COMPATIBLE_IOCTL(PPPIOCNEWUNIT) -COMPATIBLE_IOCTL(PPPIOCATTACH) -COMPATIBLE_IOCTL(PPPIOCDETACH) -COMPATIBLE_IOCTL(PPPIOCSMRRU) -COMPATIBLE_IOCTL(PPPIOCCONNECT) -COMPATIBLE_IOCTL(PPPIOCDISCONN) -COMPATIBLE_IOCTL(PPPIOCATTCHAN) -COMPATIBLE_IOCTL(PPPIOCGCHAN) -COMPATIBLE_IOCTL(PPPIOCGL2TPSTATS) };/*
Signature · 1 line
2.20.0
PATCH v5 9/18 compat_ioctl: handle SIOCOUTQNSD
In reply to Arnd BergmannUnlike the normal SIOCOUTQ, SIOCOUTQNSD was never handled in compat mode. Add it to the common socket compat handler along with similar ones.
--- net/socket.c | 1 + 1 file changed, 1 insertion(+)
net/socket.c +1 -0
@@ -3452,6 +3452,7 @@ static int compat_sock_ioctl_trans(struct file *file, struct socket *sock,case SIOCSARP :case SIOCGARP :case SIOCDARP : +case SIOCOUTQNSD :case SIOCATMARK :return sock_do_ioctl (net, sock, cmd, arg); }
Signature · 1 line
2.20.0
PATCH v5 10/18 compat_ioctl: move SIOCOUTQ out of compat_ioctl.c
In reply to Arnd BergmannAll users of this call are in socket or tty code, so handling it there means we can avoid the table entry in fs/compat_ioctl.c.
--- drivers/tty/tty_io.c | 1 + fs/compat_ioctl.c | 2 -- net/socket.c | 2 ++ 3 files changed, 3 insertions(+), 2 deletions(-)
drivers/tty/tty_io.c +1 -0
@@ -2755,6 +2755,7 @@ static long tty_compat_ioctl(struct file *file, unsigned int cmd,int retval = -ENOIOCTLCMD ;switch (cmd) { +case TIOCOUTQ :case TIOCSTI :case TIOCGWINSZ :case TIOCSWINSZ :
fs/compat_ioctl.c +0 -2
@@ -198,8 +198,6 @@ static int ppp_scompress(struct file *file, unsigned int cmd,#define COMPATIBLE_IOCTL (cmd) XFORM((u32)cmd),static unsigned int ioctl_pointer[] = { -/* Little t */ -COMPATIBLE_IOCTL(TIOCOUTQ) #ifdef CONFIG_BLOCK/* Big S */ COMPATIBLE_IOCTL(SCSI_IOCTL_GET_IDLUN)
net/socket.c +2 -0
@@ -100,6 +100,7 @@#include <linux/if_tun.h> #include <linux/ipv6_route.h> #include <linux/route.h> +#include <linux/termios.h> #include <linux/sockios.h> #include <net/busy_poll.h> #include <linux/errqueue.h>
@@ -3452,6 +3453,7 @@ static int compat_sock_ioctl_trans(struct file *file, struct socket *sock,case SIOCSARP :case SIOCGARP :case SIOCDARP : +case SIOCOUTQ :case SIOCOUTQNSD :case SIOCATMARK :return sock_do_ioctl (net, sock, cmd, arg);
Signature · 1 line
2.20.0
PATCH v5 11/18 tty: handle compat PPP ioctls
In reply to Arnd BergmannMultiple tty devices are have tty devices that handle the PPPIOCGUNIT and PPPIOCGCHAN ioctls. To avoid adding a compat_ioctl handler to each of those, add it directly in tty_compat_ioctl so we can remove the calls from fs/compat_ioctl.c.
--- drivers/tty/tty_io.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/tty/tty_io.c +4 -0
@@ -87,6 +87,7 @@#include <linux/string.h> #include <linux/slab.h> #include <linux/poll.h> +#include <linux/ppp-ioctl.h> #include <linux/proc_fs.h> #include <linux/init.h> #include <linux/module.h>
@@ -2811,6 +2812,9 @@ static long tty_compat_ioctl(struct file *file, unsigned int cmd,#endif case TIOCGSOFTCAR :case TIOCSSOFTCAR : + +case PPPIOCGCHAN : +case PPPIOCGUNIT :return tty_ioctl (file, cmd, (unsigned long )compat_ptr (arg));case TIOCCONS :case TIOCEXCL :
Signature · 1 line
2.20.0
PATCH v5 17/18 pktcdvd: add compat_ioctl handler
In reply to Arnd Bergmannpkt_ioctl() implements the generic SCSI_IOCTL_SEND_COMMAND and some cdrom ioctls by forwarding to the underlying block device. For compat_ioctl handling, this always takes a roundtrip through fs/compat_ioctl.c that we should try to avoid, at least for the compatible commands.
CDROM_SEND_PACKET is an exception here, it requires special translation in compat_blkdev_driver_ioctl().
CDROM_LAST_WRITTEN has no compat handling at the moment.
--- drivers/block/pktcdvd.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
drivers/block/pktcdvd.c +25 -0
@@ -2664,6 +2664,28 @@ static int pkt_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,return ret; } +#ifdef CONFIG_COMPAT +static int pkt_compat_ioctl (struct block_device *bdev,fmode_t mode,unsigned int cmd,unsigned long arg) +{ +switch (cmd) { +/* compatible */ +case CDROMEJECT : +case CDROMMULTISESSION : +case CDROMREADTOCENTRY : +case SCSI_IOCTL_SEND_COMMAND : +return pkt_ioctl (bdev, mode, cmd, (unsigned long )compat_ptr (arg)); + + +/* FIXME: no handler so far */ +case CDROM_LAST_WRITTEN : +/* handled in compat_blkdev_driver_ioctl */ +case CDROM_SEND_PACKET : +default : +return -ENOIOCTLCMD ; + } +} +#endif +static unsigned int pkt_check_events (struct gendisk *disk,unsigned int clearing) {
@@ -2685,6 +2707,9 @@ static const struct block_device_operations pktcdvd_ops = { .open = pkt_open, .release = pkt_close, .ioctl = pkt_ioctl, +#ifdef CONFIG_COMPAT + .ioctl = pkt_compat_ioctl, +#endif .check_events = pkt_check_events, };
Signature · 1 line
2.20.0
PATCH v5 18/18 scsi: sd: enable compat ioctls for sed-opal
In reply to Arnd BergmannThe sed_ioctl() function is written to be compatible between 32-bit and 64-bit processes, however compat mode is only wired up for nvme, not for sd.
Add the missing call to sed_ioctl() in sd_compat_ioctl().
--- drivers/scsi/sd.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/scsi/sd.c +12 -2
@@ -1693,20 +1693,30 @@ static void sd_rescan(struct device *dev)static int sd_compat_ioctl (struct block_device *bdev,fmode_t mode,unsigned int cmd,unsigned long arg) { -struct scsi_device *sdev =scsi_disk (bdev->bd_disk)->device; +struct gendisk *disk = bdev->bd_disk; +struct scsi_disk *sdkp =scsi_disk (disk); +struct scsi_device *sdev = sdkp->device; +void __user *p =compat_ptr (arg);int error; + error =scsi_verify_blk_ioctl (bdev, cmd); +if (error <0 ) +return error; + error =scsi_ioctl_block_when_processing_errors (sdev, cmd, (mode &FMODE_NDELAY ) !=0 );if (error)return error; + +if (is_sed_ioctl (cmd)) +return sed_ioctl (sdkp->opal_dev, cmd, p);/* * Let the static ioctl translation table take care of it. */ if (!sdev->host->hostt->compat_ioctl)return -ENOIOCTLCMD ; -return sdev->host->hostt->compat_ioctl (sdev, cmd, (void __user *)arg); +return sdev->host->hostt->compat_ioctl (sdev, cmd, p); }#endif
Signature · 1 line
2.20.0
PATCH v5 16/18 compat_ioctl: move SG_GET_REQUEST_TABLE handling
In reply to Arnd BergmannSG_GET_REQUEST_TABLE is now the last ioctl command that needs a conversion handler. This is only used in a single file, so the implementation should be there.
I'm trying to simplify it in the process, to get rid of the compat_alloc_user_space() and extra copy, by adding a put_compat_request_table() function instead, which copies the data in the right format to user space.
--- drivers/scsi/sg.c | 40 ++++++++++++++++++++++++++++++----- fs/compat_ioctl.c | 54 +---------------------------------------------- 2 files changed, 36 insertions(+), 58 deletions(-)
drivers/scsi/sg.c +35 -5
@@ -889,6 +889,33 @@ sg_fill_request_table(Sg_fd *sfp, sg_req_info_t *rinfo) } } +#ifdef CONFIG_COMPAT +struct compat_sg_req_info {/* used by SG_GET_REQUEST_TABLE ioctl() */ +char req_state; +char orphan; +char sg_io_owned; +char problem; +int pack_id; +compat_uptr_t usr_ptr; +unsigned int duration; +int unused; +}; + +static int put_compat_request_table (struct compat_sg_req_info __user *o, +struct sg_req_info *rinfo) +{ +int i; +for (i =0 ; i <SG_MAX_QUEUE ; i++) { +if (copy_to_user (o + i, rinfo + i, offsetof(sg_req_info_t , usr_ptr)) || +put_user ((uintptr_t )rinfo[i].usr_ptr, &o[i].usr_ptr) || +put_user (rinfo[i].duration, &o[i].duration) || +put_user (rinfo[i].unused, &o[i].unused)) +return -EFAULT ; + } +return 0 ; +} +#endif +static long sg_ioctl (struct file *filp,unsigned int cmd_in,unsigned long arg) {
@@ -1069,9 +1096,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg) val = (sdp->device ?1 :0 );return put_user (val, ip);case SG_GET_REQUEST_TABLE : -if (!access_ok (p,SZ_SG_REQ_INFO *SG_MAX_QUEUE )) -return -EFAULT ; -else { + {sg_req_info_t *rinfo; rinfo = kcalloc(SG_MAX_QUEUE, SZ_SG_REQ_INFO,
@@ -1081,8 +1106,13 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)read_lock_irqsave (&sfp->rq_list_lock, iflags);sg_fill_request_table (sfp, rinfo);read_unlock_irqrestore (&sfp->rq_list_lock, iflags); - result =__copy_to_user (p, rinfo, -SZ_SG_REQ_INFO *SG_MAX_QUEUE ); +#ifdef CONFIG_COMPAT +if (in_compat_syscall ()) + result =put_compat_request_table (p, rinfo); + else +#endif + result =copy_to_user (p, rinfo, +SZ_SG_REQ_INFO *SG_MAX_QUEUE ); result = result ? -EFAULT :0 ;kfree (rinfo);return result;
fs/compat_ioctl.c +1 -53
73 lines not on this page · raw message
Signature · 1 line
2.20.0
Re: [PATCH v5 01/18] xfs: compat_ioctl: use compat_ptr()
In reply to Arnd BergmannQuoted 2 lines · Arnd Bergmann
For 31-bit s390 user space, we have to pass pointer arguments through
compat_ptr()in thecompat_ioctlhandler.
Seems fair enough, but...
Quoted 20 lines
Signed-off-by Arnd Bergmann <[email protected]>--- fs/xfs/xfs_ioctl32.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)fs/xfs/xfs_ioctl32.c +1
-1@@ -547,7 +547,7 @@ xfs_file_compat_ioctl(struct inode *inode =file_inode (filp);struct xfs_inode *ip =XFS_I (inode);struct xfs_mount *mp = ip->i_mount; -void __user *arg = (void __user *)p; +void __user *arg =compat_ptr (p);int error;trace_xfs_file_compat_ioctl (ip);
fs/xfs/xfs_ioctl32.c xfs_file_compat_ioctl( · line 579
Quoted 5 lines
fs/xfs/xfs_ioctl32.c +1
-1@@ -576,7 +576,7 @@ xfs_file_compat_ioctl(case XFS_IOC_SCRUB_METADATA :case XFS_IOC_BULKSTAT :case XFS_IOC_INUMBERS : -return xfs_file_ioctl (filp, cmd, p); +return xfs_file_ioctl (filp, cmd, (unsigned long )arg);
I don't really like having to sprinkle special casts through the code because of this.
Perhaps do something like:
static inline unsigned long compat_ptr_mask(unsigned long p)
{
return (unsigned long)compat_ptr(p);
}and then up front you can do:
void __user *arg; p = compat_ptr_mask(p); arg = (void __user *)p;
and then the rest of the code remains unchanged by now uses p correctly instead of having to change all the code to cast arg back to an unsigned long...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH v5 01/18] xfs: compat_ioctl: use compat_ptr()
Quoted 23 lines · Dave Chinner
Review
Quoted 4 lines
case
XFS_IOC_BULKSTAT:
caseXFS_IOC_INUMBERS:(quoted diff) +1
-1- return xfs_file_ioctl(filp, cmd, p); + return xfs_file_ioctl(filp, cmd, (unsigned long)arg);I don't really like having to sprinkle special casts through the code because of this.
Perhaps do something like:
static inline unsigned long
compat_ptr_mask(unsigned long p){ return (unsigned long)compat_ptr(p); }and then up front you can do:
void __user *arg; p = compat_ptr_mask(p); arg = (void __user *)p;
Quoted 4 lines
and then the rest of the code remains unchanged by now uses p correctly instead of having to change all the code to cast arg back to an unsigned long...
In part 1 of the series, I define this function as a global:
long compat_ptr_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
if (!file->f_op->unlocked_ioctl)
return -ENOIOCTLCMD;
return file->f_op->unlocked_ioctl(file, cmd, (unsignedlong)compat_ptr(arg));
}
How about using that to replace the individual casts:
- return xfs_file_ioctl(filp, cmd, (unsigned long)arg);
+ return compat_ptr_ioctl(filp, cmd, arg);
It adds another indirection, but it avoids all the casts and uses existing mechanism.
Arnd
Re: [PATCH v5 01/18] xfs: compat_ioctl: use compat_ptr()
In reply to Dave ChinnerQuoted 9 lines · Dave Chinner
fs/xfs/xfs_ioctl32.c xfs_file_compat_ioctl( · line 579
Quoted 6 lines
fs/xfs/xfs_ioctl32.c +1
-1@@ -576,7 +576,7 @@ xfs_file_compat_ioctl(case XFS_IOC_SCRUB_METADATA :case XFS_IOC_BULKSTAT :case XFS_IOC_INUMBERS : -return xfs_file_ioctl (filp, cmd, p); +return xfs_file_ioctl (filp, cmd, (unsigned long )arg);I don't really like having to sprinkle special casts through the code because of this.
True. But the proper fix is to not do the indirection through xfs_file_ioctl but instead to call xfs_ioc_scrub_metadata, xfs_ioc_bulkstat, etc directly which all take a void __user arguments already.
Re: [PATCH v5 01/18] xfs: compat_ioctl: use compat_ptr()
Quoted 12 lines · Christoph Hellwig
Quoted 9 lines · Dave Chinner
fs/xfs/xfs_ioctl32.c xfs_file_compat_ioctl( · line 579
Quoted 6 lines
fs/xfs/xfs_ioctl32.c +1
-1@@ -576,7 +576,7 @@ xfs_file_compat_ioctl(case XFS_IOC_SCRUB_METADATA :case XFS_IOC_BULKSTAT :case XFS_IOC_INUMBERS : -return xfs_file_ioctl (filp, cmd, p); +return xfs_file_ioctl (filp, cmd, (unsigned long )arg);I don't really like having to sprinkle special casts through the code because of this.
Quoted 4 lines
True. But the proper fix is to not do the indirection through
xfs_file_ioctlbut instead to callxfs_ioc_scrub_metadata,xfs_ioc_bulkstat, etc directly which all take a void__userarguments already.
I'm not sure that's better: This would end up duplicating all of xfs_file_ioctl(), which is already a fairly long function, compared to the current way of having a large set of commands all handled with a single line.
From looking at other subsystems, what I find to work best is to move the compat handler into the same file as the native code and then structure the files so that shared handlers get put into one place, something like
/* these are the ones that have the same ABI for 32-bit and 64-bit tasks */ static int xfs_compatible_file_ioctl(struct file *filp, unsigned cmd, void __user *p)
{
int ret = -ENOIOCTLCMD;
switch (cmd) {
case XFS_IOC_DIOINFO:
...
case ...
}
return ret;
}long
xfs_file_compat_ioctl(
struct file *filp,
unsigned cmd,
unsigned long p)
{
ret = xfs_compatible_file_ioctl(filp, cmd, compat_ptr(p));
if (ret != -ENOIOCTLCMD)
return ret;
/* all incompatible ones below */
switch (cmd) {
...
}
}Having them in one place makes it more obvious to readers how the native and compat handlers fit together, and makes it easier to keep the two in sync.
That would of course be a much larger change to how it's done today, and it's way out of scope of what I want to achieve in my (already too long) series.
Arnd
Re: [PATCH v5 01/18] xfs: compat_ioctl: use compat_ptr()
In many ways I'd actually much rather have a table driven approach. Let me try something..
Re: [PATCH v5 01/18] xfs: compat_ioctl: use compat_ptr()
Quoted 2 lines · Christoph Hellwig
In many ways I'd actually much rather have a table driven approach. Let me try something..
Ok, it seems like we don't even need a table containing native and compat as we can just fall back. The tables still seem nicer to read, though.
Let me know what you think of this:
http://git.infradead.org/users/hch/xfs.git/shortlog/refs/heads/xfs-ioctl-table
I also wonder if we should life the ioctl handler tables to the VFS..
Re: [PATCH v5 01/18] xfs: compat_ioctl: use compat_ptr()
Quoted 5 lines · Christoph Hellwig
Quoted 2 lines · Christoph Hellwig
In many ways I'd actually much rather have a table driven approach. Let me try something..
Quoted 7 lines
Ok, it seems like we don't even need a table containing native and compat as we can just fall back. The tables still seem nicer to read, though.
Let me know what you think of this:
http://git.infradead.org/users/hch/xfs.git/shortlog/refs/heads/xfs-ioctl-table
These all look like useful cleanups, but I'm a little worried about introducing merge conflicts with my own patches. I would want to have my series get merged as a complete branch since each patch that removes a bit of fs/compat_ioctl.c would clash with a patch removing the adjacent bits otherwise.
I still haven't heard from Al regarding what he thinks of my v5 series. If he wants me to send a pull request for it, I can of course add in your patches after they are fully reviewed.
Quoted 1 line
I also wonder if we should life the ioctl handler tables to the VFS.
The idea of these tables has come up a few times in the past, and there are a couple of subsystems that have something like it, e.g. drivers/media.
Usually you'd want to combine the table with a more generic way to do the copy_from_user()/copy_to_user() on the argument, but that in turn requires all commands to be defined correctly (a lot of drivers have some commands that specify the wrong direction or the wrong size, or one that predates the _IO() macro).
What I could imaging having in the long run is to have the ioctl table attached to the file_operations structure, and then define it in a way that handles at least the more common variations:
- copy_from_user to stack, pass a kernel pointer to handler
- a single entry for commands that are 32/64-bit compatible
- entries that are only used for native vs compat mode if they have incompatible arguments (this could also be handled by calling in_compat_syscall() in the handler itself).
- a flag to specify handlers that require the __user pointer instead of the implied copy.
Doing this right will certainly require several revisions of patch series and lots of discussions, and is unrelated to the removal of fs/compat_ioctl.c, so I'd much prefer to get this series merged before we start working on that.
Arnd
Re: [PATCH v5 03/18] gfs2: add compat_ioctl support
In reply to Arnd Bergmann----- Original Message -----
Quoted 10 lines
Out of the four ioctl commands supported on gfs2, only FITRIM works in compat mode.
Add a proper handler based on the ext4 implementation.
Fixes 6ddc5c3ddf25 ("gfs2: getlabel support")Signed-off-by Arnd Bergmann <[email protected]>--- fs/gfs2/file.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
Hi,
Regards,
Bob Peterson
Re: [PATCH v5 01/18] xfs: compat_ioctl: use compat_ptr()
In reply to Christoph HellwigQuoted 11 lines · Christoph Hellwig
Quoted 2 lines · Christoph Hellwig
In many ways I'd actually much rather have a table driven approach. Let me try something..
Ok, it seems like we don't even need a table containing native and compat as we can just fall back. The tables still seem nicer to read, though.
Let me know what you think of this:
http://git.infradead.org/users/hch/xfs.git/shortlog/refs/heads/xfs-ioctl-table
Lots to like in that handful of patches. :)
It can easily go before or after Arnd's patch, and the merge conflict either way would be minor, so I'm not really fussed either way this gets sorted out...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH v5 01/18] xfs: compat_ioctl: use compat_ptr()
Quoted 7 lines · Dave Chinner
Lots to like in that handful of patches. :)
It can easily go before or after Arnd's patch, and the merge conflict either way would be minor, so I'm not really fussed either way this gets sorted out...
The other thing we could do is to just pick the two important ones:
http://git.infradead.org/users/hch/xfs.git/shortlog/refs/heads/xfs-ioctl-table-5.3
and throw that into Arnds series, or even 5.3, and then defer the table thing until later.
Re: [PATCH v5 10/18] compat_ioctl: move SIOCOUTQ out of compat_ioctl.c
In reply to Arnd BergmannQuoted 9 lines · Arnd Bergmann
All users of this call are in socket or tty code, so handling it there means we can avoid the table entry in
fs/compat_ioctl.c.Signed-off-by Arnd Bergmann <[email protected]>--- drivers/tty/tty_io.c | 1 + fs/compat_ioctl.c | 2 -- net/socket.c | 2 ++ 3 files changed, 3 insertions(+), 2 deletions(-)a
Re: [PATCH v5 11/18] tty: handle compat PPP ioctls
In reply to Arnd BergmannQuoted 6 lines · Arnd Bergmann
Multiple tty devices are have tty devices that handle the PPPIOCGUNIT and PPPIOCGCHAN ioctls. To avoid adding a
compat_ioctlhandler to each of those, add it directly intty_compat_ioctlso we can remove the calls fromfs/compat_ioctl.c.Signed-off-by Arnd Bergmann <[email protected]>
Re: [PATCH v5 05/18] watchdog: cpwd: use generic compat_ptr_ioctl
In reply to Arnd BergmannQuoted 7 lines · Arnd Bergmann
The
cpwd_compat_ioctl()contains a bogus mutex that dates back to a leftover BKL instance.Simplify the implementation by using the new
compat_ptr_ioctl()helper function that will do the right thing for all calls here.
Quoted 5 lines
Note that WIOCSTART/WIOCSTOP don't take any arguments, so the
compat_ptr()conversion is not needed here, but it also doesn't hurt.Signed-off-by Arnd Bergmann <[email protected]>
Re: [PATCH v5 06/18] compat_ioctl: move WDIOC handling into wdt drivers
In reply to Arnd BergmannQuoted 8 lines · Arnd Bergmann
All watchdog drivers implement the same set of ioctl commands, and fortunately all of them are compatible between 32-bit and 64-bit architectures.
Modern drivers always go through
drivers/watchdog/wdt.cas an abstraction layer, but older ones implement their ownfile_operationson a character device for this.
Quoted 8 lines
Move the handling from
fs/compat_ioctl.cinto the individual drivers.Note that most of the legacy drivers will never be used on 64-bit hardware, because they are for an old 32-bit SoC implementation, but doing them all at once is safer than trying to guess which ones do or do not need the
compat_ioctlhandling.Signed-off-by Arnd Bergmann <[email protected]>
This patch doesn't seem to have a useful base (or at least git says so). It does not apply to mainline nor to my own watchdog-next branch. I assume you plan to apply the entire series together. Please not that there will be conflicts against watchdog-next when you do so.
Guenter
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v5 01/18] xfs: compat_ioctl: use compat_ptr()
In reply to Christoph HellwigQuoted 10 lines · Christoph Hellwig
Quoted 7 lines · Dave Chinner
Lots to like in that handful of patches. :)
It can easily go before or after Arnd's patch, and the merge conflict either way would be minor, so I'm not really fussed either way this gets sorted out...
Quoted 6 lines
The other thing we could do is to just pick the two important ones:
http://git.infradead.org/users/hch/xfs.git/shortlog/refs/heads/xfs-ioctl-table-5.3
and throw that into Arnds series, or even 5.3, and then defer the table thing until later.
If we can have your "xfs: fall back to native ioctls for unhandled compat ones" in 5.3, that would be ideal from my side, then I can just drop the corresponding patch from my series and have the rest merged for 5.4.
The compat_ptr addition is independent of my series, I just added it because I noticed it was missing, so we can merged that through the xfs tree along with your other changes, either for 5.3 or 5.4.
Arnd
Re: [PATCH v5 01/18] xfs: compat_ioctl: use compat_ptr()
Quoted 18 lines · Arnd Bergmann
Quoted 10 lines · Christoph Hellwig
Quoted 7 lines · Dave Chinner
Lots to like in that handful of patches. :)
It can easily go before or after Arnd's patch, and the merge conflict either way would be minor, so I'm not really fussed either way this gets sorted out...
Quoted 6 lines
The other thing we could do is to just pick the two important ones:
http://git.infradead.org/users/hch/xfs.git/shortlog/refs/heads/xfs-ioctl-table-5.3
and throw that into Arnds series, or even 5.3, and then defer the table thing until later.
Quoted 7 lines
If we can have your "xfs: fall back to native ioctls for unhandled compat ones" in 5.3, that would be ideal from my side, then I can just drop the corresponding patch from my series and have the rest merged for 5.4.
The
compat_ptraddition is independent of my series, I just added it because I noticed it was missing, so we can merged that through the xfs tree along with your other changes, either for 5.3 or 5.4.
Er... do the two patches in the -5.3 branch actually fix something that's broken? I sense s390 is missing a pointer sanitization check or something...?
--D
Quoted 1 line
Arnd
Re: [PATCH v5 01/18] xfs: compat_ioctl: use compat_ptr()
Quoted 24 lines · Darrick J. Wong
Quoted 22 lines · Arnd Bergmann
Quoted 10 lines · Christoph Hellwig
Quoted 7 lines · Dave Chinner
Lots to like in that handful of patches. :)
It can easily go before or after Arnd's patch, and the merge conflict either way would be minor, so I'm not really fussed either way this gets sorted out...
Quoted 6 lines
The other thing we could do is to just pick the two important ones:
http://git.infradead.org/users/hch/xfs.git/shortlog/refs/heads/xfs-ioctl-table-5.3
and throw that into Arnds series, or even 5.3, and then defer the table thing until later.
If we can have your "xfs: fall back to native ioctls for unhandled compat ones" in 5.3, that would be ideal from my side, then I can just drop the corresponding patch from my series and have the rest merged for 5.4.
Quoted 7 lines
Quoted 3 lines
The
compat_ptraddition is independent of my series, I just added it because I noticed it was missing, so we can merged that through the xfs tree along with your other changes, either for 5.3 or 5.4.Er... do the two patches in the -5.3 branch actually fix something that's broken? I sense s390 is missing a pointer sanitization check or something...?
s390 is indeed missing the pointer conversion, the other patch adds compat ioctl support for FS_IOC_GETFSLABEL and FS_IOC_SETFSLABEL, which were missing, and it ensures that FITRIM keeps working after I remove it from the list in fs/compat_ioctl.c
Arnd
Andreas Gruenbacher
maintainerRe: [PATCH v5 03/18] gfs2: add compat_ioctl support
In reply to Arnd BergmannArnd,
Quoted 29 lines · Arnd Bergmann
Out of the four ioctl commands supported on gfs2, only FITRIM works in compat mode.
Add a proper handler based on the ext4 implementation.
Fixes 6ddc5c3ddf25 ("gfs2: getlabel support")Signed-off-by Arnd Bergmann <[email protected]>--- fs/gfs2/file.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)fs/gfs2/file.c +2
-0@@ -6,6 +6,7 @@#include <linux/slab.h> #include <linux/spinlock.h> +#include <linux/compat.h> #include <linux/completion.h> #include <linux/buffer_head.h> #include <linux/pagemap.h> @@ -354,6 +355,25 @@ static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)return -ENOTTY ; } +#ifdef CONFIG_COMPAT
fs/gfs2/file.c static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) · line 368
Quoted 10 lines
fs/gfs2/file.c +10
-0+static long gfs2_compat_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) +{ +/* These are just misnamed, they actually get/put from/to user an int */ +switch (cmd) { +case FS_IOC32_GETFLAGS : + cmd =FS_IOC_GETFLAGS ; +break ; +case FS_IOC32_SETFLAGS : + cmd =FS_IOC_SETFLAGS ; +break ;
I'd like the code to be more explicit here:
case FITRIM:
case FS_IOC_GETFSLABEL:
break;
default:
return -ENOIOCTLCMD;Quoted 44 lines
fs/gfs2/file.c +12
-1+ } + +return gfs2_ioctl (filp, cmd, (unsigned long )compat_ptr (arg)); +} +#else +#define gfs2_compat_ioctl NULL +#endif +/** * gfs2_size_hint - Give a hint to the size of a write request * @filep: The struct file @@ -1294,6 +1314,7 @@ const struct file_operations gfs2_file_fops = { .write_iter = gfs2_file_write_iter, .iopoll = iomap_dio_iopoll, .unlocked_ioctl = gfs2_ioctl, + .compat_ioctl = gfs2_compat_ioctl, .mmap = gfs2_mmap, .open = gfs2_open, .release = gfs2_release,@@ -1309,6 +1330,7 @@ const struct file_operations gfs2_file_fops = {const struct file_operations gfs2_dir_fops = { .iterate_shared = gfs2_readdir, .unlocked_ioctl = gfs2_ioctl, + .compat_ioctl = gfs2_compat_ioctl, .open = gfs2_open, .release = gfs2_release, .fsync = gfs2_fsync,@@ -1325,6 +1347,7 @@ const struct file_operations gfs2_file_fops_nolock = { .write_iter = gfs2_file_write_iter, .iopoll = iomap_dio_iopoll, .unlocked_ioctl = gfs2_ioctl, + .compat_ioctl = gfs2_compat_ioctl, .mmap = gfs2_mmap, .open = gfs2_open, .release = gfs2_release,@@ -1338,6 +1361,7 @@ const struct file_operations gfs2_file_fops_nolock = {const struct file_operations gfs2_dir_fops_nolock = { .iterate_shared = gfs2_readdir, .unlocked_ioctl = gfs2_ioctl, + .compat_ioctl = gfs2_compat_ioctl, .open = gfs2_open, .release = gfs2_release, .fsync = gfs2_fsync, --
Quoted 2 lines
2.20.0
Should we feed this through the gfs2 tree?
Thanks,
Andreas
Re: [PATCH v5 03/18] gfs2: add compat_ioctl support
Quoted 11 lines · Andreas Gruenbacher
fs/gfs2/file.c static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) · line 368
Quoted 8 lines · Arnd Bergmann
fs/gfs2/file.c +8
-0+/* These are just misnamed, they actually get/put from/to user an int */ +switch (cmd) { +case FS_IOC32_GETFLAGS : + cmd =FS_IOC_GETFLAGS ; +break ; +case FS_IOC32_SETFLAGS : + cmd =FS_IOC_SETFLAGS ; +break ;
Quoted 7 lines
I'd like the code to be more explicit here:
case FITRIM: case FS_IOC_GETFSLABEL: break; default: return -ENOIOCTLCMD;
I've looked at it again: if we do this, the function actually becomes longer than
the native gfs2_ioctl(). Should we just make a full copy then?
static long gfs2_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
switch(cmd) {
case FS_IOC32_GETFLAGS:
return gfs2_get_flags(filp, (u32 __user *)arg);
case FS_IOC32_SETFLAGS:
return gfs2_set_flags(filp, (u32 __user *)arg);
case FITRIM:
return gfs2_fitrim(filp, (void __user *)arg);
case FS_IOC_GETFSLABEL:
return gfs2_getlabel(filp, (char __user *)arg);
}
return -ENOTTY;
}Quoted 1 line
Should we feed this through the gfs2 tree?
A later patch that removes the FITRIM handling from fs/compat_ioctl.c depends on it, so I'd like to keep everything together.
Arnd
Re: [PATCH v5 03/18] gfs2: add compat_ioctl support
Am So., 18. Aug. 2019 um 21:32 Uhr schrieb Arnd Bergmann <[email protected]>:
Quoted 13 lines · Andreas Gruenbacher
Quoted 12 lines · Arnd Bergmann
fs/gfs2/file.c static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) · line 368
Quoted 8 lines
fs/gfs2/file.c +8
-0+/* These are just misnamed, they actually get/put from/to user an int */ +switch (cmd) { +case FS_IOC32_GETFLAGS : + cmd =FS_IOC_GETFLAGS ; +break ; +case FS_IOC32_SETFLAGS : + cmd =FS_IOC_SETFLAGS ; +break ;I'd like the code to be more explicit here:
Quoted 8 lines
Quoted 5 lines
case FITRIM: case FS_IOC_GETFSLABEL: break; default: return -ENOIOCTLCMD;I've looked at it again: if we do this, the function actually becomes longer than the native
gfs2_ioctl(). Should we just make a full copy then?
I don't think the length of gfs2_compat_ioctl is really an issue as long as the function is that simple.
Quoted 16 lines
static long
gfs2_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg){ switch(cmd) { case FS_IOC32_GETFLAGS: return gfs2_get_flags(filp, (u32 __user *)arg); case FS_IOC32_SETFLAGS: return gfs2_set_flags(filp, (u32 __user *)arg); case FITRIM: return gfs2_fitrim(filp, (void __user *)arg); case FS_IOC_GETFSLABEL: return gfs2_getlabel(filp, (char __user *)arg); } return -ENOTTY; }
Don't we still need the compat_ptr conversion? That seems to be the main point of having a compat_ioctl operation.
Quoted 4 lines
Quoted 1 line
Should we feed this through the gfs2 tree?
A later patch that removes the FITRIM handling from
fs/compat_ioctl.cdepends on it, so I'd like to keep everything together.
Ok, fine for me.
Thanks,
Andreas
Re: [PATCH v5 03/18] gfs2: add compat_ioctl support
Quoted 20 lines · Andreas Gr?nbacher
Am So., 18. Aug. 2019 um 21:32 Uhr schrieb Arnd Bergmann <[email protected]>:
Quoted 19 lines · Andreas Gruenbacher
Quoted 17 lines · Arnd Bergmann
fs/gfs2/file.c static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) · line 368
Quoted 8 lines
fs/gfs2/file.c +8
-0+/* These are just misnamed, they actually get/put from/to user an int */ +switch (cmd) { +case FS_IOC32_GETFLAGS : + cmd =FS_IOC_GETFLAGS ; +break ; +case FS_IOC32_SETFLAGS : + cmd =FS_IOC_SETFLAGS ; +break ;I'd like the code to be more explicit here:
case FITRIM: case FS_IOC_GETFSLABEL: break; default: return -ENOIOCTLCMD;
Quoted 5 lines
Quoted 2 lines
I've looked at it again: if we do this, the function actually becomes longer than the native
gfs2_ioctl(). Should we just make a full copy then?I don't think the length of
gfs2_compat_ioctlis really an issue as long as the function is that simple.
True. The most important goal should just be to make it easy to add the correct handler the next time another command is added to the ioctl function.
Just let me know which version you want for that:
1. my original patch
2. the version from your reply
3. my version below with compat_ptr() added
4. ...
Quoted 14 lines
Quoted 14 lines
static long
gfs2_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg){ switch(cmd) { case FS_IOC32_GETFLAGS: return gfs2_get_flags(filp, (u32 __user *)arg); case FS_IOC32_SETFLAGS: return gfs2_set_flags(filp, (u32 __user *)arg); case FITRIM: return gfs2_fitrim(filp, (void __user *)arg); case FS_IOC_GETFSLABEL: return gfs2_getlabel(filp, (char __user *)arg); }
Quoted 5 lines
Quoted 2 lines
return -ENOTTY; }Don't we still need the
compat_ptrconversion? That seems to be the main point of having acompat_ioctloperation.
Right, of course. Fixed now in my tree.
Arnd
Andreas Gruenbacher
maintainerRe: [PATCH v5 03/18] gfs2: add compat_ioctl support
Quoted 28 lines · Arnd Bergmann
Quoted 20 lines · Andreas Gr?nbacher
Am So., 18. Aug. 2019 um 21:32 Uhr schrieb Arnd Bergmann <[email protected]>:
Quoted 19 lines · Andreas Gruenbacher
Quoted 17 lines · Arnd Bergmann
fs/gfs2/file.c static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) · line 368
Quoted 8 lines
fs/gfs2/file.c +8
-0+/* These are just misnamed, they actually get/put from/to user an int */ +switch (cmd) { +case FS_IOC32_GETFLAGS : + cmd =FS_IOC_GETFLAGS ; +break ; +case FS_IOC32_SETFLAGS : + cmd =FS_IOC_SETFLAGS ; +break ;I'd like the code to be more explicit here:
case FITRIM: case FS_IOC_GETFSLABEL: break; default: return -ENOIOCTLCMD;Quoted 5 lines
Quoted 2 lines
I've looked at it again: if we do this, the function actually becomes longer than the native
gfs2_ioctl(). Should we just make a full copy then?I don't think the length of
gfs2_compat_ioctlis really an issue as long as the function is that simple.
Quoted 8 lines
True. The most important goal should just be to make it easy to add the correct handler the next time another command is added to the ioctl function.
Just let me know which version you want for that:
1. my original patch
2. the version from your reply
That one, please.
Quoted 20 lines
3. my version below with
compat_ptr()added
4. ...Quoted 17 lines
Quoted 16 lines
static long
gfs2_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg){ switch(cmd) { case FS_IOC32_GETFLAGS: return gfs2_get_flags(filp, (u32 __user *)arg); case FS_IOC32_SETFLAGS: return gfs2_set_flags(filp, (u32 __user *)arg); case FITRIM: return gfs2_fitrim(filp, (void __user *)arg); case FS_IOC_GETFSLABEL: return gfs2_getlabel(filp, (char __user *)arg); } return -ENOTTY; }
Quoted 6 lines
Quoted 2 lines
Don't we still need the
compat_ptrconversion? That seems to be the main point of having acompat_ioctloperation.Right, of course. Fixed now in my tree.
Arnd
Thanks,
Andreas
Guenter Roeck
maintainerRe: [PATCH v5 05/18] watchdog: cpwd: use generic compat_ptr_ioctl
In reply to Arnd BergmannArnd,
Quoted 7 lines · Arnd Bergmann
The
cpwd_compat_ioctl()contains a bogus mutex that dates back to a leftover BKL instance.Simplify the implementation by using the new
compat_ptr_ioctl()helper function that will do the right thing for all calls here.
Quoted 6 lines
Note that WIOCSTART/WIOCSTOP don't take any arguments, so the
compat_ptr()conversion is not needed here, but it also doesn't hurt.Signed-off-by Arnd Bergmann <[email protected]>Reviewed-by Guenter Roeck <[email protected]>
This patch made it into the kernel, but the infrastructure didn't make it. Do we need to revert it ?
Guenter
Quoted 47 lines
--- drivers/watchdog/cpwd.c | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-)drivers/watchdog/cpwd.c +1
-24@@ -473,29 +473,6 @@ static long cpwd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)return 0 ; } -static long cpwd_compat_ioctl (struct file *file,unsigned int cmd, -unsigned long arg) -{ -int rval = -ENOIOCTLCMD ; - -switch (cmd) { -/* solaris ioctls are specific to this driver */ -case WIOCSTART : -case WIOCSTOP : -case WIOCGSTAT : -mutex_lock (&cpwd_mutex); - rval =cpwd_ioctl (file, cmd, arg); -mutex_unlock (&cpwd_mutex); -break ; - -/* everything else is handled by the generic compat layer */ -default : -break ; - } - -return rval; -} -static ssize_t cpwd_write (struct file *file,const char __user *buf,size_t count,loff_t *ppos) {@@ -520,7 +497,7 @@ static ssize_t cpwd_read(struct file *file, char __user *buffer,static const struct file_operations cpwd_fops = { .owner =THIS_MODULE , .unlocked_ioctl = cpwd_ioctl, - .compat_ioctl = cpwd_compat_ioctl, + .compat_ioctl = compat_ptr_ioctl, .open = cpwd_open, .write = cpwd_write, .read = cpwd_read,
Re: [PATCH v5 05/18] watchdog: cpwd: use generic compat_ptr_ioctl
Quoted 13 lines · Guenter Roeck
Quoted 11 lines · Arnd Bergmann
The
cpwd_compat_ioctl()contains a bogus mutex that dates back to a leftover BKL instance.Simplify the implementation by using the new
compat_ptr_ioctl()helper function that will do the right thing for all calls here.Note that WIOCSTART/WIOCSTOP don't take any arguments, so the
compat_ptr()conversion is not needed here, but it also doesn't hurt.
Quoted 5 lines
Quoted 2 lines
Signed-off-by Arnd Bergmann <[email protected]>Reviewed-by Guenter Roeck <[email protected]>This patch made it into the kernel, but the infrastructure didn't make it. Do we need to revert it ?
Sorry I had not realized that this patch got queued in the watchdog tree and relied on the other patches. I ended up not sending the series after a runtime regression in another driver, combined with the series not having spent much time in linux-next before the merge window.
I've sent a fixup patch now that will make it do the right thing regardless of my series, please apply that for v5.4.
Arnd