linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: "James E.J. Bottomley" <jejb@linux.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Arnd Bergmann <arnd@arndb.de>, Jens Axboe <axboe@kernel.dk>,
	John Garry <john.garry@huawei.com>,
	Brian King <brking@us.ibm.com>,
	Intel SCU Linux support <intel-linux-scu@intel.com>,
	Artur Paszkiewicz <artur.paszkiewicz@intel.com>,
	Jack Wang <jinpu.wang@cloud.ionos.com>,
	Kees Cook <keescook@chromium.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	James Bottomley <James.Bottomley@HansenPartnership.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Hannes Reinecke <hare@suse.de>,
	Xiang Chen <chenxiang66@hisilicon.com>,
	Luo Jiaxing <luojiaxing@huawei.com>,
	zhengbin <zhengbin13@huawei.com>,
	Xiaofei Tan <tanxiaofei@huawei.com>,
	Bart Van Assche <bvanassche@acm.org>,
	Bradley Grove <bgrove@attotech.com>,
	Ming Lei <ming.lei@redhat.com>,
	Logan Gunthorpe <logang@deltatee.com>,
	Jeff Moyer <jmoyer@redhat.com>,
	Richard Fontana <rfontana@redhat.com>,
	Deepak Ukey <deepak.ukey@microchip.com>,
	Viswas G <Viswas.G@microchip.com>, peter chang <dpf@google.com>,
	Colin Ian King <colin.king@canonical.com>,
	Saurav Girepunje <saurav.girepunje@gmail.com>,
	Vikram Auradkar <auradkar@google.com>,
	Denis Efremov <efremov@linux.com>, Jiri Slaby <jslaby@suse.cz>,
	Jilayne Lovejoy <opensource@jilayne.com>,
	linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-scsi@vger.kernel.org
Subject: [PATCH v3 17/22] compat_ioctl: scsi: handle HDIO commands from drivers
Date: Thu,  2 Jan 2020 15:55:35 +0100	[thread overview]
Message-ID: <20200102145552.1853992-18-arnd@arndb.de> (raw)
In-Reply-To: <20200102145552.1853992-1-arnd@arndb.de>

The ata_sas_scsi_ioctl() function implements a number of HDIO_* commands
for SCSI devices, it is used by all libata drivers as well as a few
drivers that support SAS attached SATA drives.

The only command that is not safe for compat ioctls here is
HDIO_GET_32BIT. Change the implementation to check for in_compat_syscall()
in order to do both cases correctly, and change all callers to use it
as both native and compat callback pointers, including the indirect
callers through sas_ioctl and ata_scsi_ioctl.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/ata/libata-scsi.c              | 9 +++++++++
 drivers/scsi/aic94xx/aic94xx_init.c    | 3 +++
 drivers/scsi/hisi_sas/hisi_sas_v1_hw.c | 3 +++
 drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 3 +++
 drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 3 +++
 drivers/scsi/ipr.c                     | 3 +++
 drivers/scsi/isci/init.c               | 3 +++
 drivers/scsi/mvsas/mv_init.c           | 3 +++
 drivers/scsi/pm8001/pm8001_init.c      | 3 +++
 include/linux/libata.h                 | 6 ++++++
 10 files changed, 39 insertions(+)

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 58e09ffe8b9c..eb2eb599e602 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -17,6 +17,7 @@
  *  - http://www.t13.org/
  */
 
+#include <linux/compat.h>
 #include <linux/slab.h>
 #include <linux/kernel.h>
 #include <linux/blkdev.h>
@@ -761,6 +762,10 @@ static int ata_ioc32(struct ata_port *ap)
 	return 0;
 }
 
+/*
+ * This handles both native and compat commands, so anything added
+ * here must have a compatible argument, or check in_compat_syscall()
+ */
 int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *scsidev,
 		     unsigned int cmd, void __user *arg)
 {
@@ -773,6 +778,10 @@ int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *scsidev,
 		spin_lock_irqsave(ap->lock, flags);
 		val = ata_ioc32(ap);
 		spin_unlock_irqrestore(ap->lock, flags);
+#ifdef CONFIG_COMPAT
+		if (in_compat_syscall())
+			return put_user(val, (compat_ulong_t __user *)arg);
+#endif
 		return put_user(val, (unsigned long __user *)arg);
 
 	case HDIO_SET_32BIT:
diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
index f5781e31f57c..d022407e5645 100644
--- a/drivers/scsi/aic94xx/aic94xx_init.c
+++ b/drivers/scsi/aic94xx/aic94xx_init.c
@@ -54,6 +54,9 @@ static struct scsi_host_template aic94xx_sht = {
 	.eh_target_reset_handler	= sas_eh_target_reset_handler,
 	.target_destroy		= sas_target_destroy,
 	.ioctl			= sas_ioctl,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl		= sas_ioctl,
+#endif
 	.track_queue_depth	= 1,
 };
 
diff --git a/drivers/scsi/hisi_sas/hisi_sas_v1_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v1_hw.c
index 3af53cc42bd6..fa25766502a2 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_v1_hw.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_v1_hw.c
@@ -1772,6 +1772,9 @@ static struct scsi_host_template sht_v1_hw = {
 	.eh_target_reset_handler = sas_eh_target_reset_handler,
 	.target_destroy		= sas_target_destroy,
 	.ioctl			= sas_ioctl,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl		= sas_ioctl,
+#endif
 	.shost_attrs		= host_attrs_v1_hw,
 	.host_reset             = hisi_sas_host_reset,
 };
diff --git a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c
index 61b1e2693b08..545eaff5f3ee 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c
@@ -3551,6 +3551,9 @@ static struct scsi_host_template sht_v2_hw = {
 	.eh_target_reset_handler = sas_eh_target_reset_handler,
 	.target_destroy		= sas_target_destroy,
 	.ioctl			= sas_ioctl,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl		= sas_ioctl,
+#endif
 	.shost_attrs		= host_attrs_v2_hw,
 	.host_reset		= hisi_sas_host_reset,
 };
diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
index bf5d5f138437..fa05e612d85a 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c
@@ -3075,6 +3075,9 @@ static struct scsi_host_template sht_v3_hw = {
 	.eh_target_reset_handler = sas_eh_target_reset_handler,
 	.target_destroy		= sas_target_destroy,
 	.ioctl			= sas_ioctl,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl		= sas_ioctl,
+#endif
 	.shost_attrs		= host_attrs_v3_hw,
 	.tag_alloc_policy	= BLK_TAG_ALLOC_RR,
 	.host_reset             = hisi_sas_host_reset,
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index 079c04bc448a..ae45cbe98ae2 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -6727,6 +6727,9 @@ static struct scsi_host_template driver_template = {
 	.name = "IPR",
 	.info = ipr_ioa_info,
 	.ioctl = ipr_ioctl,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl = ipr_ioctl,
+#endif
 	.queuecommand = ipr_queuecommand,
 	.eh_abort_handler = ipr_eh_abort,
 	.eh_device_reset_handler = ipr_eh_dev_reset,
diff --git a/drivers/scsi/isci/init.c b/drivers/scsi/isci/init.c
index 1727d0c71b12..b48aac8dfcb8 100644
--- a/drivers/scsi/isci/init.c
+++ b/drivers/scsi/isci/init.c
@@ -168,6 +168,9 @@ static struct scsi_host_template isci_sht = {
 	.eh_target_reset_handler        = sas_eh_target_reset_handler,
 	.target_destroy			= sas_target_destroy,
 	.ioctl				= sas_ioctl,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl			= sas_ioctl,
+#endif
 	.shost_attrs			= isci_host_attrs,
 	.track_queue_depth		= 1,
 };
diff --git a/drivers/scsi/mvsas/mv_init.c b/drivers/scsi/mvsas/mv_init.c
index da719b0694dc..7af9173c4925 100644
--- a/drivers/scsi/mvsas/mv_init.c
+++ b/drivers/scsi/mvsas/mv_init.c
@@ -47,6 +47,9 @@ static struct scsi_host_template mvs_sht = {
 	.eh_target_reset_handler = sas_eh_target_reset_handler,
 	.target_destroy		= sas_target_destroy,
 	.ioctl			= sas_ioctl,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl		= sas_ioctl,
+#endif
 	.shost_attrs		= mvst_host_attrs,
 	.track_queue_depth	= 1,
 };
diff --git a/drivers/scsi/pm8001/pm8001_init.c b/drivers/scsi/pm8001/pm8001_init.c
index ff618ad80ebd..3c6076e4c6d2 100644
--- a/drivers/scsi/pm8001/pm8001_init.c
+++ b/drivers/scsi/pm8001/pm8001_init.c
@@ -101,6 +101,9 @@ static struct scsi_host_template pm8001_sht = {
 	.eh_target_reset_handler = sas_eh_target_reset_handler,
 	.target_destroy		= sas_target_destroy,
 	.ioctl			= sas_ioctl,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl		= sas_ioctl,
+#endif
 	.shost_attrs		= pm8001_host_attrs,
 	.track_queue_depth	= 1,
 };
diff --git a/include/linux/libata.h b/include/linux/libata.h
index 2dbde119721d..a36bdcb8d9e9 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -1109,6 +1109,11 @@ extern void ata_host_init(struct ata_host *, struct device *, struct ata_port_op
 extern int ata_scsi_detect(struct scsi_host_template *sht);
 extern int ata_scsi_ioctl(struct scsi_device *dev, unsigned int cmd,
 			  void __user *arg);
+#ifdef CONFIG_COMPAT
+#define ATA_SCSI_COMPAT_IOCTL .compat_ioctl = ata_scsi_ioctl,
+#else
+#define ATA_SCSI_COMPAT_IOCTL /* empty */
+#endif
 extern int ata_scsi_queuecmd(struct Scsi_Host *h, struct scsi_cmnd *cmd);
 extern int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *dev,
 			    unsigned int cmd, void __user *arg);
@@ -1341,6 +1346,7 @@ extern struct device_attribute *ata_common_sdev_attrs[];
 	.module			= THIS_MODULE,			\
 	.name			= drv_name,			\
 	.ioctl			= ata_scsi_ioctl,		\
+	ATA_SCSI_COMPAT_IOCTL					\
 	.queuecommand		= ata_scsi_queuecmd,		\
 	.can_queue		= ATA_DEF_QUEUE,		\
 	.tag_alloc_policy	= BLK_TAG_ALLOC_RR,		\
-- 
2.20.0


  parent reply	other threads:[~2020-01-02 15:05 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-02 14:55 [GIT PULL v3 00/27] block, scsi: final compat_ioctl cleanup Arnd Bergmann
2020-01-02 14:55 ` [PATCH v3 01/22] compat: ARM64: always include asm-generic/compat.h Arnd Bergmann
2020-01-02 14:55 ` [PATCH v3 02/22] compat: provide compat_ptr() on all architectures Arnd Bergmann
2020-01-06 17:40   ` Will Deacon
2020-01-06 17:59   ` H. Peter Anvin
2020-01-07  2:05   ` Michael Ellerman
2020-01-07  8:08     ` Arnd Bergmann
2020-01-07  8:19       ` H. Peter Anvin
2020-01-07  8:40         ` Arnd Bergmann
2020-01-07 17:51   ` Heiko Carstens
2020-01-02 14:55 ` [PATCH v3 03/22] compat: scsi: sg: fix v3 compat read/write interface Arnd Bergmann
2020-01-02 14:55 ` [PATCH v3 04/22] compat_ioctl: block: add blkdev_compat_ptr_ioctl Arnd Bergmann
2020-01-02 14:55 ` [PATCH v3 05/22] compat_ioctl: ubd, aoe: use blkdev_compat_ptr_ioctl Arnd Bergmann
2020-01-02 14:55 ` [PATCH v3 06/22] compat_ioctl: move CDROM_SEND_PACKET handling into scsi Arnd Bergmann
2020-01-02 14:55 ` [PATCH v3 07/22] compat_ioctl: move CDROMREADADIO to cdrom.c Arnd Bergmann
2020-01-02 14:55 ` [PATCH v3 08/22] compat_ioctl: cdrom: handle CDROM_LAST_WRITTEN Arnd Bergmann
2020-01-02 14:55 ` [PATCH v3 09/22] compat_ioctl: block: handle cdrom compat ioctl in non-cdrom drivers Arnd Bergmann
2020-01-02 14:55 ` [PATCH v3 10/22] compat_ioctl: add scsi_compat_ioctl Arnd Bergmann
2020-01-02 14:55 ` [PATCH v3 11/22] compat_ioctl: bsg: add handler Arnd Bergmann
2020-01-02 14:55 ` [PATCH v3 12/22] compat_ioctl: ide: floppy: " Arnd Bergmann
2020-01-02 14:55 ` [PATCH v3 13/22] compat_ioctl: scsi: move ioctl handling into drivers Arnd Bergmann
2020-01-02 16:33   ` Stefan Hajnoczi
2020-02-12 21:14   ` Johannes Hirte
2020-02-12 21:49     ` Arnd Bergmann
2020-02-13  6:53       ` Johannes Hirte
2020-01-02 14:55 ` [PATCH v3 14/22] compat_ioctl: move sys_compat_ioctl() to ioctl.c Arnd Bergmann
2020-01-02 14:55 ` [PATCH v3 15/22] compat_ioctl: simplify the implementation Arnd Bergmann
2020-01-02 14:55 ` [PATCH v3 16/22] compat_ioctl: move cdrom commands into cdrom.c Arnd Bergmann
2020-01-02 14:55 ` Arnd Bergmann [this message]
2020-01-02 14:55 ` [PATCH v3 18/22] compat_ioctl: move HDIO ioctl handling into drivers/ide Arnd Bergmann
2020-01-02 14:55 ` [PATCH v3 19/22] compat_ioctl: block: move blkdev_compat_ioctl() into ioctl.c Arnd Bergmann
2020-01-02 14:55 ` [PATCH v3 20/22] compat_ioctl: block: simplify compat_blkpg_ioctl() Arnd Bergmann
2020-01-02 14:55 ` [PATCH v3 21/22] compat_ioctl: simplify up block/ioctl.c Arnd Bergmann
2020-01-02 14:55 ` [PATCH v3 22/22] Documentation: document ioctl interfaces better Arnd Bergmann
2020-01-02 20:22 ` [GIT PULL v3 00/27] block, scsi: final compat_ioctl cleanup Arnd Bergmann
2020-01-03  0:22 ` Ben Hutchings
2020-01-03  8:56   ` Arnd Bergmann
2020-01-03  3:02 ` Martin K. Petersen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200102145552.1853992-18-arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=Viswas.G@microchip.com \
    --cc=artur.paszkiewicz@intel.com \
    --cc=auradkar@google.com \
    --cc=axboe@kernel.dk \
    --cc=bgrove@attotech.com \
    --cc=brking@us.ibm.com \
    --cc=bvanassche@acm.org \
    --cc=chenxiang66@hisilicon.com \
    --cc=colin.king@canonical.com \
    --cc=deepak.ukey@microchip.com \
    --cc=dpf@google.com \
    --cc=efremov@linux.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hare@suse.de \
    --cc=intel-linux-scu@intel.com \
    --cc=jejb@linux.ibm.com \
    --cc=jinpu.wang@cloud.ionos.com \
    --cc=jmoyer@redhat.com \
    --cc=john.garry@huawei.com \
    --cc=jslaby@suse.cz \
    --cc=keescook@chromium.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=logang@deltatee.com \
    --cc=luojiaxing@huawei.com \
    --cc=martin.petersen@oracle.com \
    --cc=mika.westerberg@linux.intel.com \
    --cc=ming.lei@redhat.com \
    --cc=opensource@jilayne.com \
    --cc=rfontana@redhat.com \
    --cc=saurav.girepunje@gmail.com \
    --cc=tanxiaofei@huawei.com \
    --cc=tglx@linutronix.de \
    --cc=zhengbin13@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).