aboutsummaryrefslogtreecommitdiffstats
path: root/fs/compat_ioctl.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-01-05 18:40:12 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2012-01-05 18:40:12 -0500
commit07d106d0a33d6063d2061305903deb02489eba20 (patch)
tree6f257f877a9c2e653ca0515253e930fa6606239a /fs/compat_ioctl.c
parent805a6af8dba5dfdd35ec35dc52ec0122400b2610 (diff)
vfs: fix up ENOIOCTLCMD error handling
We're doing some odd things there, which already messes up various users (see the net/socket.c code that this removes), and it was going to add yet more crud to the block layer because of the incorrect error code translation. ENOIOCTLCMD is not an error return that should be returned to user mode from the "ioctl()" system call, but it should *not* be translated as EINVAL ("Invalid argument"). It should be translated as ENOTTY ("Inappropriate ioctl for device"). That EINVAL confusion has apparently so permeated some code that the block layer actually checks for it, which is sad. We continue to do so for now, but add a big comment about how wrong that is, and we should remove it entirely eventually. In the meantime, this tries to keep the changes localized to just the EINVAL -> ENOTTY fix, and removing code that makes it harder to do the right thing. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/compat_ioctl.c')
-rw-r--r--fs/compat_ioctl.c38
1 files changed, 2 insertions, 36 deletions
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index 51352de88ef1..a10e428b32b4 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -1506,35 +1506,6 @@ static long do_ioctl_trans(int fd, unsigned int cmd,
1506 return -ENOIOCTLCMD; 1506 return -ENOIOCTLCMD;
1507} 1507}
1508 1508
1509static void compat_ioctl_error(struct file *filp, unsigned int fd,
1510 unsigned int cmd, unsigned long arg)
1511{
1512 char buf[10];
1513 char *fn = "?";
1514 char *path;
1515
1516 /* find the name of the device. */
1517 path = (char *)__get_free_page(GFP_KERNEL);
1518 if (path) {
1519 fn = d_path(&filp->f_path, path, PAGE_SIZE);
1520 if (IS_ERR(fn))
1521 fn = "?";
1522 }
1523
1524 sprintf(buf,"'%c'", (cmd>>_IOC_TYPESHIFT) & _IOC_TYPEMASK);
1525 if (!isprint(buf[1]))
1526 sprintf(buf, "%02x", buf[1]);
1527 compat_printk("ioctl32(%s:%d): Unknown cmd fd(%d) "
1528 "cmd(%08x){t:%s;sz:%u} arg(%08x) on %s\n",
1529 current->comm, current->pid,
1530 (int)fd, (unsigned int)cmd, buf,
1531 (cmd >> _IOC_SIZESHIFT) & _IOC_SIZEMASK,
1532 (unsigned int)arg, fn);
1533
1534 if (path)
1535 free_page((unsigned long)path);
1536}
1537
1538static int compat_ioctl_check_table(unsigned int xcmd) 1509static int compat_ioctl_check_table(unsigned int xcmd)
1539{ 1510{
1540 int i; 1511 int i;
@@ -1621,13 +1592,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
1621 goto found_handler; 1592 goto found_handler;
1622 1593
1623 error = do_ioctl_trans(fd, cmd, arg, filp); 1594 error = do_ioctl_trans(fd, cmd, arg, filp);
1624 if (error == -ENOIOCTLCMD) { 1595 if (error == -ENOIOCTLCMD)
1625 static int count; 1596 error = -ENOTTY;
1626
1627 if (++count <= 50)
1628 compat_ioctl_error(filp, fd, cmd, arg);
1629 error = -EINVAL;
1630 }
1631 1597
1632 goto out_fput; 1598 goto out_fput;
1633 1599