Commit e10cc1df authored by Paul Fulghum's avatar Paul Fulghum Committed by Linus Torvalds

tty: add compat_ioctl

Add compat_ioctl method for tty code to allow processing of 32 bit ioctl
calls on 64 bit systems by tty core, tty drivers, and line disciplines.

Based on patch by Arnd Bergmann:
http://www.uwsg.iu.edu/hypermail/linux/kernel/0511.0/1732.html

[akpm@linux-foundation.org: make things static]
Signed-off-by: default avatarPaul Fulghum <paulkf@microgate.com>
Acked-by: default avatarArnd Bergmann <arnd@arndb.de>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 108f39a1
...@@ -1544,21 +1544,18 @@ static unsigned int normal_poll(struct tty_struct * tty, struct file * file, pol ...@@ -1544,21 +1544,18 @@ static unsigned int normal_poll(struct tty_struct * tty, struct file * file, pol
} }
struct tty_ldisc tty_ldisc_N_TTY = { struct tty_ldisc tty_ldisc_N_TTY = {
TTY_LDISC_MAGIC, /* magic */ .magic = TTY_LDISC_MAGIC,
"n_tty", /* name */ .name = "n_tty",
0, /* num */ .open = n_tty_open,
0, /* flags */ .close = n_tty_close,
n_tty_open, /* open */ .flush_buffer = n_tty_flush_buffer,
n_tty_close, /* close */ .chars_in_buffer = n_tty_chars_in_buffer,
n_tty_flush_buffer, /* flush_buffer */ .read = read_chan,
n_tty_chars_in_buffer, /* chars_in_buffer */ .write = write_chan,
read_chan, /* read */ .ioctl = n_tty_ioctl,
write_chan, /* write */ .set_termios = n_tty_set_termios,
n_tty_ioctl, /* ioctl */ .poll = normal_poll,
n_tty_set_termios, /* set_termios */ .receive_buf = n_tty_receive_buf,
normal_poll, /* poll */ .write_wakeup = n_tty_write_wakeup
NULL, /* hangup */
n_tty_receive_buf, /* receive_buf */
n_tty_write_wakeup /* write_wakeup */
}; };
...@@ -151,6 +151,12 @@ static int tty_open(struct inode *, struct file *); ...@@ -151,6 +151,12 @@ static int tty_open(struct inode *, struct file *);
static int tty_release(struct inode *, struct file *); static int tty_release(struct inode *, struct file *);
int tty_ioctl(struct inode * inode, struct file * file, int tty_ioctl(struct inode * inode, struct file * file,
unsigned int cmd, unsigned long arg); unsigned int cmd, unsigned long arg);
#ifdef CONFIG_COMPAT
static long tty_compat_ioctl(struct file * file, unsigned int cmd,
unsigned long arg);
#else
#define tty_compat_ioctl NULL
#endif
static int tty_fasync(int fd, struct file * filp, int on); static int tty_fasync(int fd, struct file * filp, int on);
static void release_tty(struct tty_struct *tty, int idx); static void release_tty(struct tty_struct *tty, int idx);
static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty); static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
...@@ -1143,8 +1149,8 @@ static unsigned int hung_up_tty_poll(struct file * filp, poll_table * wait) ...@@ -1143,8 +1149,8 @@ static unsigned int hung_up_tty_poll(struct file * filp, poll_table * wait)
return POLLIN | POLLOUT | POLLERR | POLLHUP | POLLRDNORM | POLLWRNORM; return POLLIN | POLLOUT | POLLERR | POLLHUP | POLLRDNORM | POLLWRNORM;
} }
static int hung_up_tty_ioctl(struct inode * inode, struct file * file, static long hung_up_tty_ioctl(struct file * file,
unsigned int cmd, unsigned long arg) unsigned int cmd, unsigned long arg)
{ {
return cmd == TIOCSPGRP ? -ENOTTY : -EIO; return cmd == TIOCSPGRP ? -ENOTTY : -EIO;
} }
...@@ -1155,6 +1161,7 @@ static const struct file_operations tty_fops = { ...@@ -1155,6 +1161,7 @@ static const struct file_operations tty_fops = {
.write = tty_write, .write = tty_write,
.poll = tty_poll, .poll = tty_poll,
.ioctl = tty_ioctl, .ioctl = tty_ioctl,
.compat_ioctl = tty_compat_ioctl,
.open = tty_open, .open = tty_open,
.release = tty_release, .release = tty_release,
.fasync = tty_fasync, .fasync = tty_fasync,
...@@ -1167,6 +1174,7 @@ static const struct file_operations ptmx_fops = { ...@@ -1167,6 +1174,7 @@ static const struct file_operations ptmx_fops = {
.write = tty_write, .write = tty_write,
.poll = tty_poll, .poll = tty_poll,
.ioctl = tty_ioctl, .ioctl = tty_ioctl,
.compat_ioctl = tty_compat_ioctl,
.open = ptmx_open, .open = ptmx_open,
.release = tty_release, .release = tty_release,
.fasync = tty_fasync, .fasync = tty_fasync,
...@@ -1179,6 +1187,7 @@ static const struct file_operations console_fops = { ...@@ -1179,6 +1187,7 @@ static const struct file_operations console_fops = {
.write = redirected_tty_write, .write = redirected_tty_write,
.poll = tty_poll, .poll = tty_poll,
.ioctl = tty_ioctl, .ioctl = tty_ioctl,
.compat_ioctl = tty_compat_ioctl,
.open = tty_open, .open = tty_open,
.release = tty_release, .release = tty_release,
.fasync = tty_fasync, .fasync = tty_fasync,
...@@ -1189,7 +1198,8 @@ static const struct file_operations hung_up_tty_fops = { ...@@ -1189,7 +1198,8 @@ static const struct file_operations hung_up_tty_fops = {
.read = hung_up_tty_read, .read = hung_up_tty_read,
.write = hung_up_tty_write, .write = hung_up_tty_write,
.poll = hung_up_tty_poll, .poll = hung_up_tty_poll,
.ioctl = hung_up_tty_ioctl, .unlocked_ioctl = hung_up_tty_ioctl,
.compat_ioctl = hung_up_tty_ioctl,
.release = tty_release, .release = tty_release,
}; };
...@@ -3357,6 +3367,32 @@ int tty_ioctl(struct inode * inode, struct file * file, ...@@ -3357,6 +3367,32 @@ int tty_ioctl(struct inode * inode, struct file * file,
return retval; return retval;
} }
#ifdef CONFIG_COMPAT
static long tty_compat_ioctl(struct file * file, unsigned int cmd,
unsigned long arg)
{
struct inode *inode = file->f_dentry->d_inode;
struct tty_struct *tty = file->private_data;
struct tty_ldisc *ld;
int retval = -ENOIOCTLCMD;
if (tty_paranoia_check(tty, inode, "tty_ioctl"))
return -EINVAL;
if (tty->driver->compat_ioctl) {
retval = (tty->driver->compat_ioctl)(tty, file, cmd, arg);
if (retval != -ENOIOCTLCMD)
return retval;
}
ld = tty_ldisc_ref_wait(tty);
if (ld->compat_ioctl)
retval = ld->compat_ioctl(tty, file, cmd, arg);
tty_ldisc_deref(ld);
return retval;
}
#endif
/* /*
* This implements the "Secure Attention Key" --- the idea is to * This implements the "Secure Attention Key" --- the idea is to
...@@ -3689,6 +3725,7 @@ void tty_set_operations(struct tty_driver *driver, ...@@ -3689,6 +3725,7 @@ void tty_set_operations(struct tty_driver *driver,
driver->write_room = op->write_room; driver->write_room = op->write_room;
driver->chars_in_buffer = op->chars_in_buffer; driver->chars_in_buffer = op->chars_in_buffer;
driver->ioctl = op->ioctl; driver->ioctl = op->ioctl;
driver->compat_ioctl = op->compat_ioctl;
driver->set_termios = op->set_termios; driver->set_termios = op->set_termios;
driver->throttle = op->throttle; driver->throttle = op->throttle;
driver->unthrottle = op->unthrottle; driver->unthrottle = op->unthrottle;
......
...@@ -52,6 +52,11 @@ ...@@ -52,6 +52,11 @@
* This routine allows the tty driver to implement * This routine allows the tty driver to implement
* device-specific ioctl's. If the ioctl number passed in cmd * device-specific ioctl's. If the ioctl number passed in cmd
* is not recognized by the driver, it should return ENOIOCTLCMD. * is not recognized by the driver, it should return ENOIOCTLCMD.
*
* long (*compat_ioctl)(struct tty_struct *tty, struct file * file,
* unsigned int cmd, unsigned long arg);
*
* implement ioctl processing for 32 bit process on 64 bit system
* *
* void (*set_termios)(struct tty_struct *tty, struct ktermios * old); * void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
* *
...@@ -132,6 +137,8 @@ struct tty_operations { ...@@ -132,6 +137,8 @@ struct tty_operations {
int (*chars_in_buffer)(struct tty_struct *tty); int (*chars_in_buffer)(struct tty_struct *tty);
int (*ioctl)(struct tty_struct *tty, struct file * file, int (*ioctl)(struct tty_struct *tty, struct file * file,
unsigned int cmd, unsigned long arg); unsigned int cmd, unsigned long arg);
long (*compat_ioctl)(struct tty_struct *tty, struct file * file,
unsigned int cmd, unsigned long arg);
void (*set_termios)(struct tty_struct *tty, struct ktermios * old); void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
void (*throttle)(struct tty_struct * tty); void (*throttle)(struct tty_struct * tty);
void (*unthrottle)(struct tty_struct * tty); void (*unthrottle)(struct tty_struct * tty);
...@@ -193,6 +200,8 @@ struct tty_driver { ...@@ -193,6 +200,8 @@ struct tty_driver {
int (*chars_in_buffer)(struct tty_struct *tty); int (*chars_in_buffer)(struct tty_struct *tty);
int (*ioctl)(struct tty_struct *tty, struct file * file, int (*ioctl)(struct tty_struct *tty, struct file * file,
unsigned int cmd, unsigned long arg); unsigned int cmd, unsigned long arg);
long (*compat_ioctl)(struct tty_struct *tty, struct file * file,
unsigned int cmd, unsigned long arg);
void (*set_termios)(struct tty_struct *tty, struct ktermios * old); void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
void (*throttle)(struct tty_struct * tty); void (*throttle)(struct tty_struct * tty);
void (*unthrottle)(struct tty_struct * tty); void (*unthrottle)(struct tty_struct * tty);
......
...@@ -59,6 +59,11 @@ ...@@ -59,6 +59,11 @@
* low-level driver can "grab" an ioctl request before the line * low-level driver can "grab" an ioctl request before the line
* discpline has a chance to see it. * discpline has a chance to see it.
* *
* long (*compat_ioctl)(struct tty_struct * tty, struct file * file,
* unsigned int cmd, unsigned long arg);
*
* Process ioctl calls from 32-bit process on 64-bit system
*
* void (*set_termios)(struct tty_struct *tty, struct ktermios * old); * void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
* *
* This function notifies the line discpline that a change has * This function notifies the line discpline that a change has
...@@ -118,6 +123,8 @@ struct tty_ldisc { ...@@ -118,6 +123,8 @@ struct tty_ldisc {
const unsigned char * buf, size_t nr); const unsigned char * buf, size_t nr);
int (*ioctl)(struct tty_struct * tty, struct file * file, int (*ioctl)(struct tty_struct * tty, struct file * file,
unsigned int cmd, unsigned long arg); unsigned int cmd, unsigned long arg);
long (*compat_ioctl)(struct tty_struct * tty, struct file * file,
unsigned int cmd, unsigned long arg);
void (*set_termios)(struct tty_struct *tty, struct ktermios * old); void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
unsigned int (*poll)(struct tty_struct *, struct file *, unsigned int (*poll)(struct tty_struct *, struct file *,
struct poll_table_struct *); struct poll_table_struct *);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment