Skip to content

Commit 0da5221

Browse files
committed
Merge tag 'compat-ioctl-5.5' of git://git.kernel.org:/pub/scm/linux/kernel/git/arnd/playground
Pull removal of most of fs/compat_ioctl.c from Arnd Bergmann: "As part of the cleanup of some remaining y2038 issues, I came to fs/compat_ioctl.c, which still has a couple of commands that need support for time64_t. In completely unrelated work, I spent time on cleaning up parts of this file in the past, moving things out into drivers instead. After Al Viro reviewed an earlier version of this series and did a lot more of that cleanup, I decided to try to completely eliminate the rest of it and move it all into drivers. This series incorporates some of Al's work and many patches of my own, but in the end stops short of actually removing the last part, which is the scsi ioctl handlers. I have patches for those as well, but they need more testing or possibly a rewrite" * tag 'compat-ioctl-5.5' of git://git.kernel.org:/pub/scm/linux/kernel/git/arnd/playground: (42 commits) scsi: sd: enable compat ioctls for sed-opal pktcdvd: add compat_ioctl handler compat_ioctl: move SG_GET_REQUEST_TABLE handling compat_ioctl: ppp: move simple commands into ppp_generic.c compat_ioctl: handle PPPIOCGIDLE for 64-bit time_t compat_ioctl: move PPPIOCSCOMPRESS to ppp_generic compat_ioctl: unify copy-in of ppp filters tty: handle compat PPP ioctls compat_ioctl: move SIOCOUTQ out of compat_ioctl.c compat_ioctl: handle SIOCOUTQNSD af_unix: add compat_ioctl support compat_ioctl: reimplement SG_IO handling compat_ioctl: move WDIOC handling into wdt drivers fs: compat_ioctl: move FITRIM emulation into file systems gfs2: add compat_ioctl support compat_ioctl: remove unused convert_in_user macro compat_ioctl: remove last RAID handling code compat_ioctl: remove /dev/raw ioctl translation compat_ioctl: remove PCI ioctl translation compat_ioctl: remove joystick ioctl translation ...
2 parents ad0b314 + 142b2ac commit 0da5221

File tree

156 files changed

+954
-1394
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+954
-1394
lines changed

Documentation/networking/ppp_generic.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ an interface unit are:
378378
CONFIG_PPP_FILTER option is enabled, the set of packets which reset
379379
the transmit and receive idle timers is restricted to those which
380380
pass the `active' packet filter.
381+
Two versions of this command exist, to deal with user space
382+
expecting times as either 32-bit or 64-bit time_t seconds.
381383

382384
* PPPIOCSMAXCID sets the maximum connection-ID parameter (and thus the
383385
number of connection slots) for the TCP header compressor and

arch/powerpc/platforms/52xx/mpc52xx_gpt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ static const struct file_operations mpc52xx_wdt_fops = {
650650
.llseek = no_llseek,
651651
.write = mpc52xx_wdt_write,
652652
.unlocked_ioctl = mpc52xx_wdt_ioctl,
653+
.compat_ioctl = compat_ptr_ioctl,
653654
.open = mpc52xx_wdt_open,
654655
.release = mpc52xx_wdt_release,
655656
};

arch/um/drivers/harddog_kern.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ static const struct file_operations harddog_fops = {
165165
.owner = THIS_MODULE,
166166
.write = harddog_write,
167167
.unlocked_ioctl = harddog_ioctl,
168+
.compat_ioctl = compat_ptr_ioctl,
168169
.open = harddog_open,
169170
.release = harddog_release,
170171
.llseek = no_llseek,

arch/um/drivers/hostaudio_kern.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ static const struct file_operations hostaudio_fops = {
298298
.write = hostaudio_write,
299299
.poll = hostaudio_poll,
300300
.unlocked_ioctl = hostaudio_ioctl,
301+
.compat_ioctl = compat_ptr_ioctl,
301302
.mmap = NULL,
302303
.open = hostaudio_open,
303304
.release = hostaudio_release,

block/scsi_ioctl.c

Lines changed: 128 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/*
33
* Copyright (C) 2001 Jens Axboe <[email protected]>
44
*/
5+
#include <linux/compat.h>
56
#include <linux/kernel.h>
67
#include <linux/errno.h>
78
#include <linux/string.h>
@@ -327,7 +328,14 @@ static int sg_io(struct request_queue *q, struct gendisk *bd_disk,
327328
struct iov_iter i;
328329
struct iovec *iov = NULL;
329330

330-
ret = import_iovec(rq_data_dir(rq),
331+
#ifdef CONFIG_COMPAT
332+
if (in_compat_syscall())
333+
ret = compat_import_iovec(rq_data_dir(rq),
334+
hdr->dxferp, hdr->iovec_count,
335+
0, &iov, &i);
336+
else
337+
#endif
338+
ret = import_iovec(rq_data_dir(rq),
331339
hdr->dxferp, hdr->iovec_count,
332340
0, &iov, &i);
333341
if (ret < 0)
@@ -542,6 +550,122 @@ static inline int blk_send_start_stop(struct request_queue *q,
542550
return __blk_send_generic(q, bd_disk, GPCMD_START_STOP_UNIT, data);
543551
}
544552

553+
#ifdef CONFIG_COMPAT
554+
struct compat_sg_io_hdr {
555+
compat_int_t interface_id; /* [i] 'S' for SCSI generic (required) */
556+
compat_int_t dxfer_direction; /* [i] data transfer direction */
557+
unsigned char cmd_len; /* [i] SCSI command length ( <= 16 bytes) */
558+
unsigned char mx_sb_len; /* [i] max length to write to sbp */
559+
unsigned short iovec_count; /* [i] 0 implies no scatter gather */
560+
compat_uint_t dxfer_len; /* [i] byte count of data transfer */
561+
compat_uint_t dxferp; /* [i], [*io] points to data transfer memory
562+
or scatter gather list */
563+
compat_uptr_t cmdp; /* [i], [*i] points to command to perform */
564+
compat_uptr_t sbp; /* [i], [*o] points to sense_buffer memory */
565+
compat_uint_t timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */
566+
compat_uint_t flags; /* [i] 0 -> default, see SG_FLAG... */
567+
compat_int_t pack_id; /* [i->o] unused internally (normally) */
568+
compat_uptr_t usr_ptr; /* [i->o] unused internally */
569+
unsigned char status; /* [o] scsi status */
570+
unsigned char masked_status; /* [o] shifted, masked scsi status */
571+
unsigned char msg_status; /* [o] messaging level data (optional) */
572+
unsigned char sb_len_wr; /* [o] byte count actually written to sbp */
573+
unsigned short host_status; /* [o] errors from host adapter */
574+
unsigned short driver_status; /* [o] errors from software driver */
575+
compat_int_t resid; /* [o] dxfer_len - actual_transferred */
576+
compat_uint_t duration; /* [o] time taken by cmd (unit: millisec) */
577+
compat_uint_t info; /* [o] auxiliary information */
578+
};
579+
#endif
580+
581+
int put_sg_io_hdr(const struct sg_io_hdr *hdr, void __user *argp)
582+
{
583+
#ifdef CONFIG_COMPAT
584+
if (in_compat_syscall()) {
585+
struct compat_sg_io_hdr hdr32 = {
586+
.interface_id = hdr->interface_id,
587+
.dxfer_direction = hdr->dxfer_direction,
588+
.cmd_len = hdr->cmd_len,
589+
.mx_sb_len = hdr->mx_sb_len,
590+
.iovec_count = hdr->iovec_count,
591+
.dxfer_len = hdr->dxfer_len,
592+
.dxferp = (uintptr_t)hdr->dxferp,
593+
.cmdp = (uintptr_t)hdr->cmdp,
594+
.sbp = (uintptr_t)hdr->sbp,
595+
.timeout = hdr->timeout,
596+
.flags = hdr->flags,
597+
.pack_id = hdr->pack_id,
598+
.usr_ptr = (uintptr_t)hdr->usr_ptr,
599+
.status = hdr->status,
600+
.masked_status = hdr->masked_status,
601+
.msg_status = hdr->msg_status,
602+
.sb_len_wr = hdr->sb_len_wr,
603+
.host_status = hdr->host_status,
604+
.driver_status = hdr->driver_status,
605+
.resid = hdr->resid,
606+
.duration = hdr->duration,
607+
.info = hdr->info,
608+
};
609+
610+
if (copy_to_user(argp, &hdr32, sizeof(hdr32)))
611+
return -EFAULT;
612+
613+
return 0;
614+
}
615+
#endif
616+
617+
if (copy_to_user(argp, hdr, sizeof(*hdr)))
618+
return -EFAULT;
619+
620+
return 0;
621+
}
622+
EXPORT_SYMBOL(put_sg_io_hdr);
623+
624+
int get_sg_io_hdr(struct sg_io_hdr *hdr, const void __user *argp)
625+
{
626+
#ifdef CONFIG_COMPAT
627+
struct compat_sg_io_hdr hdr32;
628+
629+
if (in_compat_syscall()) {
630+
if (copy_from_user(&hdr32, argp, sizeof(hdr32)))
631+
return -EFAULT;
632+
633+
*hdr = (struct sg_io_hdr) {
634+
.interface_id = hdr32.interface_id,
635+
.dxfer_direction = hdr32.dxfer_direction,
636+
.cmd_len = hdr32.cmd_len,
637+
.mx_sb_len = hdr32.mx_sb_len,
638+
.iovec_count = hdr32.iovec_count,
639+
.dxfer_len = hdr32.dxfer_len,
640+
.dxferp = compat_ptr(hdr32.dxferp),
641+
.cmdp = compat_ptr(hdr32.cmdp),
642+
.sbp = compat_ptr(hdr32.sbp),
643+
.timeout = hdr32.timeout,
644+
.flags = hdr32.flags,
645+
.pack_id = hdr32.pack_id,
646+
.usr_ptr = compat_ptr(hdr32.usr_ptr),
647+
.status = hdr32.status,
648+
.masked_status = hdr32.masked_status,
649+
.msg_status = hdr32.msg_status,
650+
.sb_len_wr = hdr32.sb_len_wr,
651+
.host_status = hdr32.host_status,
652+
.driver_status = hdr32.driver_status,
653+
.resid = hdr32.resid,
654+
.duration = hdr32.duration,
655+
.info = hdr32.info,
656+
};
657+
658+
return 0;
659+
}
660+
#endif
661+
662+
if (copy_from_user(hdr, argp, sizeof(*hdr)))
663+
return -EFAULT;
664+
665+
return 0;
666+
}
667+
EXPORT_SYMBOL(get_sg_io_hdr);
668+
545669
int scsi_cmd_ioctl(struct request_queue *q, struct gendisk *bd_disk, fmode_t mode,
546670
unsigned int cmd, void __user *arg)
547671
{
@@ -581,14 +705,14 @@ int scsi_cmd_ioctl(struct request_queue *q, struct gendisk *bd_disk, fmode_t mod
581705
case SG_IO: {
582706
struct sg_io_hdr hdr;
583707

584-
err = -EFAULT;
585-
if (copy_from_user(&hdr, arg, sizeof(hdr)))
708+
err = get_sg_io_hdr(&hdr, arg);
709+
if (err)
586710
break;
587711
err = sg_io(q, bd_disk, &hdr, mode);
588712
if (err == -EFAULT)
589713
break;
590714

591-
if (copy_to_user(arg, &hdr, sizeof(hdr)))
715+
if (put_sg_io_hdr(&hdr, arg))
592716
err = -EFAULT;
593717
break;
594718
}

drivers/android/binder.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6054,7 +6054,7 @@ const struct file_operations binder_fops = {
60546054
.owner = THIS_MODULE,
60556055
.poll = binder_poll,
60566056
.unlocked_ioctl = binder_ioctl,
6057-
.compat_ioctl = binder_ioctl,
6057+
.compat_ioctl = compat_ptr_ioctl,
60586058
.mmap = binder_mmap,
60596059
.open = binder_open,
60606060
.flush = binder_flush,

drivers/block/pktcdvd.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2663,6 +2663,28 @@ static int pkt_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
26632663
return ret;
26642664
}
26652665

2666+
#ifdef CONFIG_COMPAT
2667+
static int pkt_compat_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg)
2668+
{
2669+
switch (cmd) {
2670+
/* compatible */
2671+
case CDROMEJECT:
2672+
case CDROMMULTISESSION:
2673+
case CDROMREADTOCENTRY:
2674+
case SCSI_IOCTL_SEND_COMMAND:
2675+
return pkt_ioctl(bdev, mode, cmd, (unsigned long)compat_ptr(arg));
2676+
2677+
2678+
/* FIXME: no handler so far */
2679+
case CDROM_LAST_WRITTEN:
2680+
/* handled in compat_blkdev_driver_ioctl */
2681+
case CDROM_SEND_PACKET:
2682+
default:
2683+
return -ENOIOCTLCMD;
2684+
}
2685+
}
2686+
#endif
2687+
26662688
static unsigned int pkt_check_events(struct gendisk *disk,
26672689
unsigned int clearing)
26682690
{
@@ -2684,6 +2706,9 @@ static const struct block_device_operations pktcdvd_ops = {
26842706
.open = pkt_open,
26852707
.release = pkt_close,
26862708
.ioctl = pkt_ioctl,
2709+
#ifdef CONFIG_COMPAT
2710+
.ioctl = pkt_compat_ioctl,
2711+
#endif
26872712
.check_events = pkt_check_events,
26882713
};
26892714

drivers/char/ipmi/ipmi_watchdog.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,7 @@ static const struct file_operations ipmi_wdog_fops = {
893893
.poll = ipmi_poll,
894894
.write = ipmi_write,
895895
.unlocked_ioctl = ipmi_unlocked_ioctl,
896+
.compat_ioctl = compat_ptr_ioctl,
896897
.open = ipmi_open,
897898
.release = ipmi_close,
898899
.fasync = ipmi_fasync,

drivers/char/ppdev.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -678,14 +678,6 @@ static long pp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
678678
return ret;
679679
}
680680

681-
#ifdef CONFIG_COMPAT
682-
static long pp_compat_ioctl(struct file *file, unsigned int cmd,
683-
unsigned long arg)
684-
{
685-
return pp_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
686-
}
687-
#endif
688-
689681
static int pp_open(struct inode *inode, struct file *file)
690682
{
691683
unsigned int minor = iminor(inode);
@@ -794,9 +786,7 @@ static const struct file_operations pp_fops = {
794786
.write = pp_write,
795787
.poll = pp_poll,
796788
.unlocked_ioctl = pp_ioctl,
797-
#ifdef CONFIG_COMPAT
798-
.compat_ioctl = pp_compat_ioctl,
799-
#endif
789+
.compat_ioctl = compat_ptr_ioctl,
800790
.open = pp_open,
801791
.release = pp_release,
802792
};

drivers/char/random.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,6 +2166,7 @@ const struct file_operations random_fops = {
21662166
.write = random_write,
21672167
.poll = random_poll,
21682168
.unlocked_ioctl = random_ioctl,
2169+
.compat_ioctl = compat_ptr_ioctl,
21692170
.fasync = random_fasync,
21702171
.llseek = noop_llseek,
21712172
};

0 commit comments

Comments
 (0)