Skip to content

Commit 0770542

Browse files
arndbmartinkpetersen
authored andcommitted
scsi: aacraid: Improve compat_ioctl handlers
The use of compat_alloc_user_space() can be easily replaced by handling compat arguments in the regular handler, and this will make it work for big-endian kernels as well, which at the moment get an invalid indirect pointer argument. Calling aac_ioctl() instead of aac_compat_do_ioctl() means the compat and native code paths behave the same way again, which they stopped when the adapter health check was added only in the native function. Link: https://lore.kernel.org/r/20201030164450.1253641-1-arnd@kernel.org Fixes: 572ee53 ("scsi: aacraid: check adapter health") Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 2030745 commit 0770542

2 files changed

Lines changed: 22 additions & 61 deletions

File tree

‎drivers/scsi/aacraid/commctrl.c‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <linux/completion.h>
2626
#include <linux/dma-mapping.h>
2727
#include <linux/blkdev.h>
28+
#include <linux/compat.h>
2829
#include <linux/delay.h> /* ssleep prototype */
2930
#include <linux/kthread.h>
3031
#include <linux/uaccess.h>
@@ -226,6 +227,12 @@ static int open_getadapter_fib(struct aac_dev * dev, void __user *arg)
226227
return status;
227228
}
228229

230+
struct compat_fib_ioctl {
231+
u32 fibctx;
232+
s32 wait;
233+
compat_uptr_t fib;
234+
};
235+
229236
/**
230237
* next_getadapter_fib - get the next fib
231238
* @dev: adapter to use
@@ -243,8 +250,19 @@ static int next_getadapter_fib(struct aac_dev * dev, void __user *arg)
243250
struct list_head * entry;
244251
unsigned long flags;
245252

246-
if(copy_from_user((void *)&f, arg, sizeof(struct fib_ioctl)))
247-
return -EFAULT;
253+
if (in_compat_syscall()) {
254+
struct compat_fib_ioctl cf;
255+
256+
if (copy_from_user(&cf, arg, sizeof(struct compat_fib_ioctl)))
257+
return -EFAULT;
258+
259+
f.fibctx = cf.fibctx;
260+
f.wait = cf.wait;
261+
f.fib = compat_ptr(cf.fib);
262+
} else {
263+
if (copy_from_user(&f, arg, sizeof(struct fib_ioctl)))
264+
return -EFAULT;
265+
}
248266
/*
249267
* Verify that the HANDLE passed in was a valid AdapterFibContext
250268
*

‎drivers/scsi/aacraid/linit.c‎

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,63 +1182,6 @@ static long aac_cfg_ioctl(struct file *file,
11821182
return aac_do_ioctl(aac, cmd, (void __user *)arg);
11831183
}
11841184

1185-
#ifdef CONFIG_COMPAT
1186-
static long aac_compat_do_ioctl(struct aac_dev *dev, unsigned cmd, unsigned long arg)
1187-
{
1188-
long ret;
1189-
switch (cmd) {
1190-
case FSACTL_MINIPORT_REV_CHECK:
1191-
case FSACTL_SENDFIB:
1192-
case FSACTL_OPEN_GET_ADAPTER_FIB:
1193-
case FSACTL_CLOSE_GET_ADAPTER_FIB:
1194-
case FSACTL_SEND_RAW_SRB:
1195-
case FSACTL_GET_PCI_INFO:
1196-
case FSACTL_QUERY_DISK:
1197-
case FSACTL_DELETE_DISK:
1198-
case FSACTL_FORCE_DELETE_DISK:
1199-
case FSACTL_GET_CONTAINERS:
1200-
case FSACTL_SEND_LARGE_FIB:
1201-
ret = aac_do_ioctl(dev, cmd, (void __user *)arg);
1202-
break;
1203-
1204-
case FSACTL_GET_NEXT_ADAPTER_FIB: {
1205-
struct fib_ioctl __user *f;
1206-
1207-
f = compat_alloc_user_space(sizeof(*f));
1208-
ret = 0;
1209-
if (clear_user(f, sizeof(*f)))
1210-
ret = -EFAULT;
1211-
if (copy_in_user(f, (void __user *)arg, sizeof(struct fib_ioctl) - sizeof(u32)))
1212-
ret = -EFAULT;
1213-
if (!ret)
1214-
ret = aac_do_ioctl(dev, cmd, f);
1215-
break;
1216-
}
1217-
1218-
default:
1219-
ret = -ENOIOCTLCMD;
1220-
break;
1221-
}
1222-
return ret;
1223-
}
1224-
1225-
static int aac_compat_ioctl(struct scsi_device *sdev, unsigned int cmd,
1226-
void __user *arg)
1227-
{
1228-
struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
1229-
if (!capable(CAP_SYS_RAWIO))
1230-
return -EPERM;
1231-
return aac_compat_do_ioctl(dev, cmd, (unsigned long)arg);
1232-
}
1233-
1234-
static long aac_compat_cfg_ioctl(struct file *file, unsigned cmd, unsigned long arg)
1235-
{
1236-
if (!capable(CAP_SYS_RAWIO))
1237-
return -EPERM;
1238-
return aac_compat_do_ioctl(file->private_data, cmd, arg);
1239-
}
1240-
#endif
1241-
12421185
static ssize_t aac_show_model(struct device *device,
12431186
struct device_attribute *attr, char *buf)
12441187
{
@@ -1523,7 +1466,7 @@ static const struct file_operations aac_cfg_fops = {
15231466
.owner = THIS_MODULE,
15241467
.unlocked_ioctl = aac_cfg_ioctl,
15251468
#ifdef CONFIG_COMPAT
1526-
.compat_ioctl = aac_compat_cfg_ioctl,
1469+
.compat_ioctl = aac_cfg_ioctl,
15271470
#endif
15281471
.open = aac_cfg_open,
15291472
.llseek = noop_llseek,
@@ -1536,7 +1479,7 @@ static struct scsi_host_template aac_driver_template = {
15361479
.info = aac_info,
15371480
.ioctl = aac_ioctl,
15381481
#ifdef CONFIG_COMPAT
1539-
.compat_ioctl = aac_compat_ioctl,
1482+
.compat_ioctl = aac_ioctl,
15401483
#endif
15411484
.queuecommand = aac_queuecommand,
15421485
.bios_param = aac_biosparm,

0 commit comments

Comments
 (0)