2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1992 obz under the linux copyright
|
|
|
|
*
|
|
|
|
* Dynamic diacritical handling - aeb@cwi.nl - Dec 1993
|
|
|
|
* Dynamic keymap and string allocation - aeb@cwi.nl - May 1994
|
|
|
|
* Restrict VT switching via ioctl() - grif@cs.ucr.edu - Dec 1995
|
|
|
|
* Some code moved for less code duplication - Andi Kleen - Mar 1997
|
|
|
|
* Check put/get_user, cleanups - acme@conectiva.com.br - Jun 2001
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/kernel.h>
|
2009-08-06 13:09:28 +00:00
|
|
|
#include <linux/compat.h>
|
2009-09-19 20:13:25 +00:00
|
|
|
#include <linux/module.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/kd.h>
|
|
|
|
#include <linux/vt.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/major.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/console.h>
|
2007-10-17 06:27:04 +00:00
|
|
|
#include <linux/consolemap.h>
|
2005-05-01 15:59:14 +00:00
|
|
|
#include <linux/signal.h>
|
2012-11-19 05:27:41 +00:00
|
|
|
#include <linux/suspend.h>
|
2005-06-29 03:44:49 +00:00
|
|
|
#include <linux/timex.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
|
|
|
|
#include <linux/kbd_kern.h>
|
|
|
|
#include <linux/vt_kern.h>
|
|
|
|
#include <linux/kbd_diacr.h>
|
|
|
|
#include <linux/selection.h>
|
|
|
|
|
2007-03-16 21:38:24 +00:00
|
|
|
char vt_dont_switch;
|
2005-04-16 22:20:36 +00:00
|
|
|
extern struct tty_driver *console_driver;
|
|
|
|
|
|
|
|
#define VT_IS_IN_USE(i) (console_driver->ttys[i] && console_driver->ttys[i]->count)
|
|
|
|
#define VT_BUSY(i) (VT_IS_IN_USE(i) || i == fg_console || vc_cons[i].d == sel_cons)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Console (vt and kd) routines, as defined by USL SVR4 manual, and by
|
|
|
|
* experimentation and study of X386 SYSV handling.
|
|
|
|
*
|
|
|
|
* One point of difference: SYSV vt's are /dev/vtX, which X >= 0, and
|
|
|
|
* /dev/console is a separate ttyp. Under Linux, /dev/tty0 is /dev/console,
|
|
|
|
* and the vc start at /dev/ttyX, X >= 1. We maintain that here, so we will
|
|
|
|
* always treat our set of vt as numbered 1..MAX_NR_CONSOLES (corresponding to
|
|
|
|
* ttys 0..MAX_NR_CONSOLES-1). Explicitly naming VT 0 is illegal, but using
|
|
|
|
* /dev/tty0 (fg_console) as a target is legal, since an implicit aliasing
|
|
|
|
* to the current console is done by the main ioctl code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_X86
|
|
|
|
#include <linux/syscalls.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void complete_change_console(struct vc_data *vc);
|
|
|
|
|
2009-09-19 20:13:24 +00:00
|
|
|
/*
|
|
|
|
* User space VT_EVENT handlers
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct vt_event_wait {
|
|
|
|
struct list_head list;
|
|
|
|
struct vt_event event;
|
|
|
|
int done;
|
|
|
|
};
|
|
|
|
|
|
|
|
static LIST_HEAD(vt_events);
|
|
|
|
static DEFINE_SPINLOCK(vt_event_lock);
|
|
|
|
static DECLARE_WAIT_QUEUE_HEAD(vt_event_waitqueue);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vt_event_post
|
|
|
|
* @event: the event that occurred
|
|
|
|
* @old: old console
|
|
|
|
* @new: new console
|
|
|
|
*
|
|
|
|
* Post an VT event to interested VT handlers
|
|
|
|
*/
|
|
|
|
|
|
|
|
void vt_event_post(unsigned int event, unsigned int old, unsigned int new)
|
|
|
|
{
|
|
|
|
struct list_head *pos, *head;
|
|
|
|
unsigned long flags;
|
|
|
|
int wake = 0;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&vt_event_lock, flags);
|
|
|
|
head = &vt_events;
|
|
|
|
|
|
|
|
list_for_each(pos, head) {
|
|
|
|
struct vt_event_wait *ve = list_entry(pos,
|
|
|
|
struct vt_event_wait, list);
|
|
|
|
if (!(ve->event.event & event))
|
|
|
|
continue;
|
|
|
|
ve->event.event = event;
|
|
|
|
/* kernel view is consoles 0..n-1, user space view is
|
|
|
|
console 1..n with 0 meaning current, so we must bias */
|
2009-11-19 13:30:36 +00:00
|
|
|
ve->event.oldev = old + 1;
|
|
|
|
ve->event.newev = new + 1;
|
2009-09-19 20:13:24 +00:00
|
|
|
wake = 1;
|
|
|
|
ve->done = 1;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&vt_event_lock, flags);
|
|
|
|
if (wake)
|
|
|
|
wake_up_interruptible(&vt_event_waitqueue);
|
|
|
|
}
|
|
|
|
|
2012-05-21 08:08:42 +00:00
|
|
|
static void __vt_event_queue(struct vt_event_wait *vw)
|
2009-09-19 20:13:24 +00:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
/* Prepare the event */
|
|
|
|
INIT_LIST_HEAD(&vw->list);
|
|
|
|
vw->done = 0;
|
|
|
|
/* Queue our event */
|
|
|
|
spin_lock_irqsave(&vt_event_lock, flags);
|
|
|
|
list_add(&vw->list, &vt_events);
|
|
|
|
spin_unlock_irqrestore(&vt_event_lock, flags);
|
2012-05-21 08:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __vt_event_wait(struct vt_event_wait *vw)
|
|
|
|
{
|
2009-09-19 20:13:24 +00:00
|
|
|
/* Wait for it to pass */
|
2012-03-02 14:59:49 +00:00
|
|
|
wait_event_interruptible(vt_event_waitqueue, vw->done);
|
2012-05-21 08:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __vt_event_dequeue(struct vt_event_wait *vw)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
2009-09-19 20:13:24 +00:00
|
|
|
/* Dequeue it */
|
|
|
|
spin_lock_irqsave(&vt_event_lock, flags);
|
|
|
|
list_del(&vw->list);
|
|
|
|
spin_unlock_irqrestore(&vt_event_lock, flags);
|
|
|
|
}
|
|
|
|
|
2012-05-21 08:08:42 +00:00
|
|
|
/**
|
|
|
|
* vt_event_wait - wait for an event
|
|
|
|
* @vw: our event
|
|
|
|
*
|
|
|
|
* Waits for an event to occur which completes our vt_event_wait
|
|
|
|
* structure. On return the structure has wv->done set to 1 for success
|
|
|
|
* or 0 if some event such as a signal ended the wait.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void vt_event_wait(struct vt_event_wait *vw)
|
|
|
|
{
|
|
|
|
__vt_event_queue(vw);
|
|
|
|
__vt_event_wait(vw);
|
|
|
|
__vt_event_dequeue(vw);
|
|
|
|
}
|
|
|
|
|
2009-09-19 20:13:24 +00:00
|
|
|
/**
|
|
|
|
* vt_event_wait_ioctl - event ioctl handler
|
|
|
|
* @arg: argument to ioctl
|
|
|
|
*
|
|
|
|
* Implement the VT_WAITEVENT ioctl using the VT event interface
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int vt_event_wait_ioctl(struct vt_event __user *event)
|
|
|
|
{
|
|
|
|
struct vt_event_wait vw;
|
|
|
|
|
|
|
|
if (copy_from_user(&vw.event, event, sizeof(struct vt_event)))
|
|
|
|
return -EFAULT;
|
|
|
|
/* Highest supported event for now */
|
|
|
|
if (vw.event.event & ~VT_MAX_EVENT)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
vt_event_wait(&vw);
|
|
|
|
/* If it occurred report it */
|
|
|
|
if (vw.done) {
|
|
|
|
if (copy_to_user(event, &vw.event, sizeof(struct vt_event)))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -EINTR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vt_waitactive - active console wait
|
|
|
|
* @event: event code
|
|
|
|
* @n: new console
|
|
|
|
*
|
|
|
|
* Helper for event waits. Used to implement the legacy
|
|
|
|
* event waiting ioctls in terms of events
|
|
|
|
*/
|
|
|
|
|
|
|
|
int vt_waitactive(int n)
|
|
|
|
{
|
|
|
|
struct vt_event_wait vw;
|
|
|
|
do {
|
|
|
|
vw.event.event = VT_EVENT_SWITCH;
|
2012-05-21 08:08:42 +00:00
|
|
|
__vt_event_queue(&vw);
|
|
|
|
if (n == fg_console + 1) {
|
|
|
|
__vt_event_dequeue(&vw);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
__vt_event_wait(&vw);
|
|
|
|
__vt_event_dequeue(&vw);
|
2009-09-19 20:13:24 +00:00
|
|
|
if (vw.done == 0)
|
|
|
|
return -EINTR;
|
2009-11-19 13:30:36 +00:00
|
|
|
} while (vw.event.newev != n);
|
2009-09-19 20:13:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* these are the valid i/o ports we're allowed to change. they map all the
|
|
|
|
* video ports
|
|
|
|
*/
|
|
|
|
#define GPFIRST 0x3b4
|
|
|
|
#define GPLAST 0x3df
|
|
|
|
#define GPNUM (GPLAST - GPFIRST + 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
do_fontx_ioctl(int cmd, struct consolefontdesc __user *user_cfd, int perm, struct console_font_op *op)
|
|
|
|
{
|
|
|
|
struct consolefontdesc cfdarg;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (copy_from_user(&cfdarg, user_cfd, sizeof(struct consolefontdesc)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case PIO_FONTX:
|
|
|
|
if (!perm)
|
|
|
|
return -EPERM;
|
|
|
|
op->op = KD_FONT_OP_SET;
|
|
|
|
op->flags = KD_FONT_FLAG_OLD;
|
|
|
|
op->width = 8;
|
|
|
|
op->height = cfdarg.charheight;
|
|
|
|
op->charcount = cfdarg.charcount;
|
|
|
|
op->data = cfdarg.chardata;
|
|
|
|
return con_font_op(vc_cons[fg_console].d, op);
|
|
|
|
case GIO_FONTX: {
|
|
|
|
op->op = KD_FONT_OP_GET;
|
|
|
|
op->flags = KD_FONT_FLAG_OLD;
|
|
|
|
op->width = 8;
|
|
|
|
op->height = cfdarg.charheight;
|
|
|
|
op->charcount = cfdarg.charcount;
|
|
|
|
op->data = cfdarg.chardata;
|
|
|
|
i = con_font_op(vc_cons[fg_console].d, op);
|
|
|
|
if (i)
|
|
|
|
return i;
|
|
|
|
cfdarg.charheight = op->height;
|
|
|
|
cfdarg.charcount = op->charcount;
|
|
|
|
if (copy_to_user(user_cfd, &cfdarg, sizeof(struct consolefontdesc)))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
do_unimap_ioctl(int cmd, struct unimapdesc __user *user_ud, int perm, struct vc_data *vc)
|
|
|
|
{
|
|
|
|
struct unimapdesc tmp;
|
|
|
|
|
|
|
|
if (copy_from_user(&tmp, user_ud, sizeof tmp))
|
|
|
|
return -EFAULT;
|
|
|
|
if (tmp.entries)
|
|
|
|
if (!access_ok(VERIFY_WRITE, tmp.entries,
|
|
|
|
tmp.entry_ct*sizeof(struct unipair)))
|
|
|
|
return -EFAULT;
|
|
|
|
switch (cmd) {
|
|
|
|
case PIO_UNIMAP:
|
|
|
|
if (!perm)
|
|
|
|
return -EPERM;
|
|
|
|
return con_set_unimap(vc, tmp.entry_ct, tmp.entries);
|
|
|
|
case GIO_UNIMAP:
|
|
|
|
if (!perm && fg_console != vc->vc_num)
|
|
|
|
return -EPERM;
|
|
|
|
return con_get_unimap(vc, tmp.entry_ct, &(user_ud->entry_ct), tmp.entries);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-19 20:13:24 +00:00
|
|
|
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* We handle the console-specific ioctl's here. We allow the
|
|
|
|
* capability to modify any console, not just the fg_console.
|
|
|
|
*/
|
2011-02-14 16:27:22 +00:00
|
|
|
int vt_ioctl(struct tty_struct *tty,
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
2009-01-02 13:47:26 +00:00
|
|
|
struct vc_data *vc = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct console_font_op op; /* used in multiple places here */
|
|
|
|
unsigned int console;
|
|
|
|
unsigned char ucval;
|
2010-10-27 22:33:00 +00:00
|
|
|
unsigned int uival;
|
2005-04-16 22:20:36 +00:00
|
|
|
void __user *up = (void __user *)arg;
|
|
|
|
int i, perm;
|
2008-04-30 07:53:26 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
console = vc->vc_num;
|
|
|
|
|
2008-04-30 07:53:26 +00:00
|
|
|
|
|
|
|
if (!vc_cons_allocated(console)) { /* impossible? */
|
|
|
|
ret = -ENOIOCTLCMD;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* To have permissions to do most of the vt ioctls, we either have
|
|
|
|
* to be the owner of the tty, or have CAP_SYS_TTY_CONFIG.
|
|
|
|
*/
|
|
|
|
perm = 0;
|
|
|
|
if (current->signal->tty == tty || capable(CAP_SYS_TTY_CONFIG))
|
|
|
|
perm = 1;
|
|
|
|
|
|
|
|
switch (cmd) {
|
2008-10-13 09:36:40 +00:00
|
|
|
case TIOCLINUX:
|
2009-06-22 17:42:18 +00:00
|
|
|
ret = tioclinux(tty, arg);
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
case KIOCSOUND:
|
|
|
|
if (!perm)
|
2012-03-02 14:59:20 +00:00
|
|
|
return -EPERM;
|
2010-08-29 03:35:17 +00:00
|
|
|
/*
|
|
|
|
* The use of PIT_TICK_RATE is historic, it used to be
|
|
|
|
* the platform-dependent CLOCK_TICK_RATE between 2.6.12
|
|
|
|
* and 2.6.36, which was a minor but unfortunate ABI
|
2012-03-02 14:59:20 +00:00
|
|
|
* change. kd_mksound is locked by the input layer.
|
2010-08-29 03:35:17 +00:00
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
if (arg)
|
2010-08-29 03:35:17 +00:00
|
|
|
arg = PIT_TICK_RATE / arg;
|
2005-04-16 22:20:36 +00:00
|
|
|
kd_mksound(arg, 0);
|
2008-04-30 07:53:26 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
case KDMKTONE:
|
|
|
|
if (!perm)
|
2012-03-02 14:59:20 +00:00
|
|
|
return -EPERM;
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned int ticks, count;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generate the tone for the appropriate number of ticks.
|
|
|
|
* If the time is zero, turn off sound ourselves.
|
|
|
|
*/
|
|
|
|
ticks = HZ * ((arg >> 16) & 0xffff) / 1000;
|
|
|
|
count = ticks ? (arg & 0xffff) : 0;
|
|
|
|
if (count)
|
2010-08-29 03:35:17 +00:00
|
|
|
count = PIT_TICK_RATE / count;
|
2005-04-16 22:20:36 +00:00
|
|
|
kd_mksound(count, ticks);
|
2008-04-30 07:53:26 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case KDGKBTYPE:
|
|
|
|
/*
|
2012-03-02 14:59:20 +00:00
|
|
|
* this is naïve.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
ucval = KB_101;
|
2012-02-28 14:49:23 +00:00
|
|
|
ret = put_user(ucval, (char __user *)arg);
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* These cannot be implemented on any machine that implements
|
|
|
|
* ioperm() in user level (such as Alpha PCs) or not at all.
|
|
|
|
*
|
|
|
|
* XXX: you should never use these, just call ioperm directly..
|
|
|
|
*/
|
|
|
|
#ifdef CONFIG_X86
|
|
|
|
case KDADDIO:
|
|
|
|
case KDDELIO:
|
|
|
|
/*
|
|
|
|
* KDADDIO and KDDELIO may be able to add ports beyond what
|
|
|
|
* we reject here, but to be safe...
|
2012-03-02 14:59:20 +00:00
|
|
|
*
|
|
|
|
* These are locked internally via sys_ioperm
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2008-04-30 07:53:26 +00:00
|
|
|
if (arg < GPFIRST || arg > GPLAST) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ret = sys_ioperm(arg, 1, (cmd == KDADDIO)) ? -ENXIO : 0;
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
case KDENABIO:
|
|
|
|
case KDDISABIO:
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = sys_ioperm(GPFIRST, GPNUM,
|
2005-04-16 22:20:36 +00:00
|
|
|
(cmd == KDENABIO)) ? -ENXIO : 0;
|
2008-04-30 07:53:26 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Linux m68k/i386 interface for setting the keyboard delay/repeat rate */
|
|
|
|
|
|
|
|
case KDKBDREP:
|
|
|
|
{
|
|
|
|
struct kbd_repeat kbrep;
|
|
|
|
|
|
|
|
if (!capable(CAP_SYS_TTY_CONFIG))
|
2012-03-02 14:59:20 +00:00
|
|
|
return -EPERM;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-30 07:53:26 +00:00
|
|
|
if (copy_from_user(&kbrep, up, sizeof(struct kbd_repeat))) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ret = kbd_rate(&kbrep);
|
|
|
|
if (ret)
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (copy_to_user(up, &kbrep, sizeof(struct kbd_repeat)))
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = -EFAULT;
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case KDSETMODE:
|
|
|
|
/*
|
|
|
|
* currently, setting the mode from KD_TEXT to KD_GRAPHICS
|
|
|
|
* doesn't do a whole lot. i'm not sure if it should do any
|
|
|
|
* restoration of modes or what...
|
|
|
|
*
|
|
|
|
* XXX It should at least call into the driver, fbdev's definitely
|
|
|
|
* need to restore their engine state. --BenH
|
|
|
|
*/
|
|
|
|
if (!perm)
|
2012-03-02 14:59:20 +00:00
|
|
|
return -EPERM;
|
2005-04-16 22:20:36 +00:00
|
|
|
switch (arg) {
|
|
|
|
case KD_GRAPHICS:
|
|
|
|
break;
|
|
|
|
case KD_TEXT0:
|
|
|
|
case KD_TEXT1:
|
|
|
|
arg = KD_TEXT;
|
|
|
|
case KD_TEXT:
|
|
|
|
break;
|
|
|
|
default:
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2012-03-02 14:59:20 +00:00
|
|
|
/* FIXME: this needs the console lock extending */
|
2005-04-16 22:20:36 +00:00
|
|
|
if (vc->vc_mode == (unsigned char) arg)
|
2008-04-30 07:53:26 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
vc->vc_mode = (unsigned char) arg;
|
|
|
|
if (console != fg_console)
|
2008-04-30 07:53:26 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* explicitly blank/unblank the screen if switching modes
|
|
|
|
*/
|
2011-01-25 23:07:35 +00:00
|
|
|
console_lock();
|
2005-04-16 22:20:36 +00:00
|
|
|
if (arg == KD_TEXT)
|
|
|
|
do_unblank_screen(1);
|
|
|
|
else
|
|
|
|
do_blank_screen(1);
|
2011-01-25 23:07:35 +00:00
|
|
|
console_unlock();
|
2008-04-30 07:53:26 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
case KDGETMODE:
|
2010-10-27 22:33:00 +00:00
|
|
|
uival = vc->vc_mode;
|
2005-04-16 22:20:36 +00:00
|
|
|
goto setint;
|
|
|
|
|
|
|
|
case KDMAPDISP:
|
|
|
|
case KDUNMAPDISP:
|
|
|
|
/*
|
|
|
|
* these work like a combination of mmap and KDENABIO.
|
|
|
|
* this could be easily finished.
|
|
|
|
*/
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
case KDSKBMODE:
|
|
|
|
if (!perm)
|
2012-03-02 14:59:20 +00:00
|
|
|
return -EPERM;
|
2012-02-28 14:49:23 +00:00
|
|
|
ret = vt_do_kdskbmode(console, arg);
|
|
|
|
if (ret == 0)
|
|
|
|
tty_ldisc_flush(tty);
|
2008-04-30 07:53:26 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
case KDGKBMODE:
|
2012-02-28 14:49:23 +00:00
|
|
|
uival = vt_do_kdgkbmode(console);
|
|
|
|
ret = put_user(uival, (int __user *)arg);
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* this could be folded into KDSKBMODE, but for compatibility
|
|
|
|
reasons it is not so easy to fold KDGKBMETA into KDGKBMODE */
|
|
|
|
case KDSKBMETA:
|
2012-02-28 14:49:23 +00:00
|
|
|
ret = vt_do_kdskbmeta(console, arg);
|
2008-04-30 07:53:26 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
case KDGKBMETA:
|
2012-02-28 14:49:23 +00:00
|
|
|
/* FIXME: should review whether this is worth locking */
|
|
|
|
uival = vt_do_kdgkbmeta(console);
|
2005-04-16 22:20:36 +00:00
|
|
|
setint:
|
2010-10-27 22:33:00 +00:00
|
|
|
ret = put_user(uival, (int __user *)arg);
|
2008-04-30 07:53:26 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
case KDGETKEYCODE:
|
|
|
|
case KDSETKEYCODE:
|
|
|
|
if(!capable(CAP_SYS_TTY_CONFIG))
|
2008-04-30 07:53:26 +00:00
|
|
|
perm = 0;
|
2012-02-28 14:49:23 +00:00
|
|
|
ret = vt_do_kbkeycode_ioctl(cmd, up, perm);
|
2008-04-30 07:53:26 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
case KDGKBENT:
|
|
|
|
case KDSKBENT:
|
2012-02-28 14:49:23 +00:00
|
|
|
ret = vt_do_kdsk_ioctl(cmd, up, perm, console);
|
2008-04-30 07:53:26 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
case KDGKBSENT:
|
|
|
|
case KDSKBSENT:
|
2012-02-28 14:49:23 +00:00
|
|
|
ret = vt_do_kdgkb_ioctl(cmd, up, perm);
|
2008-04-30 07:53:26 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-02-24 12:47:11 +00:00
|
|
|
/* Diacritical processing. Handled in keyboard.c as it has
|
|
|
|
to operate on the keyboard locks and structures */
|
2005-04-16 22:20:36 +00:00
|
|
|
case KDGKBDIACR:
|
2007-10-17 06:27:04 +00:00
|
|
|
case KDGKBDIACRUC:
|
2005-04-16 22:20:36 +00:00
|
|
|
case KDSKBDIACR:
|
2007-10-17 06:27:04 +00:00
|
|
|
case KDSKBDIACRUC:
|
2012-02-24 12:47:11 +00:00
|
|
|
ret = vt_do_diacrit(cmd, up, perm);
|
2008-04-30 07:53:26 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* the ioctls below read/set the flags usually shown in the leds */
|
|
|
|
/* don't use them - they will go away without warning */
|
|
|
|
case KDGKBLED:
|
|
|
|
case KDSKBLED:
|
|
|
|
case KDGETLED:
|
|
|
|
case KDSETLED:
|
2012-02-28 14:49:23 +00:00
|
|
|
ret = vt_do_kdskled(console, cmd, arg, perm);
|
2008-04-30 07:53:26 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A process can indicate its willingness to accept signals
|
|
|
|
* generated by pressing an appropriate key combination.
|
|
|
|
* Thus, one can have a daemon that e.g. spawns a new console
|
|
|
|
* upon a keypress and then changes to it.
|
|
|
|
* See also the kbrequest field of inittab(5).
|
|
|
|
*/
|
|
|
|
case KDSIGACCEPT:
|
|
|
|
{
|
|
|
|
if (!perm || !capable(CAP_KILL))
|
2012-03-02 14:59:20 +00:00
|
|
|
return -EPERM;
|
2005-05-01 15:59:14 +00:00
|
|
|
if (!valid_signal(arg) || arg < 1 || arg == SIGKILL)
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = -EINVAL;
|
|
|
|
else {
|
|
|
|
spin_lock_irq(&vt_spawn_con.lock);
|
|
|
|
put_pid(vt_spawn_con.pid);
|
|
|
|
vt_spawn_con.pid = get_pid(task_pid(current));
|
|
|
|
vt_spawn_con.sig = arg;
|
|
|
|
spin_unlock_irq(&vt_spawn_con.lock);
|
|
|
|
}
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case VT_SETMODE:
|
|
|
|
{
|
|
|
|
struct vt_mode tmp;
|
|
|
|
|
|
|
|
if (!perm)
|
2012-03-02 14:59:20 +00:00
|
|
|
return -EPERM;
|
2008-04-30 07:53:26 +00:00
|
|
|
if (copy_from_user(&tmp, up, sizeof(struct vt_mode))) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
2010-03-16 00:14:15 +00:00
|
|
|
if (tmp.mode != VT_AUTO && tmp.mode != VT_PROCESS) {
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2011-01-25 23:07:35 +00:00
|
|
|
console_lock();
|
2005-04-16 22:20:36 +00:00
|
|
|
vc->vt_mode = tmp;
|
|
|
|
/* the frsig is ignored, so we set it to 0 */
|
|
|
|
vc->vt_mode.frsig = 0;
|
2007-02-10 09:44:34 +00:00
|
|
|
put_pid(vc->vt_pid);
|
|
|
|
vc->vt_pid = get_pid(task_pid(current));
|
2005-04-16 22:20:36 +00:00
|
|
|
/* no switch is required -- saw@shade.msu.ru */
|
|
|
|
vc->vt_newvt = -1;
|
2011-01-25 23:07:35 +00:00
|
|
|
console_unlock();
|
2008-04-30 07:53:26 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case VT_GETMODE:
|
|
|
|
{
|
|
|
|
struct vt_mode tmp;
|
|
|
|
int rc;
|
|
|
|
|
2011-01-25 23:07:35 +00:00
|
|
|
console_lock();
|
2005-04-16 22:20:36 +00:00
|
|
|
memcpy(&tmp, &vc->vt_mode, sizeof(struct vt_mode));
|
2011-01-25 23:07:35 +00:00
|
|
|
console_unlock();
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
rc = copy_to_user(up, &tmp, sizeof(struct vt_mode));
|
2008-04-30 07:53:26 +00:00
|
|
|
if (rc)
|
|
|
|
ret = -EFAULT;
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns global vt state. Note that VT 0 is always open, since
|
|
|
|
* it's an alias for the current VT, and people can't use it here.
|
|
|
|
* We cannot return state for more than 16 VTs, since v_state is short.
|
|
|
|
*/
|
|
|
|
case VT_GETSTATE:
|
|
|
|
{
|
|
|
|
struct vt_stat __user *vtstat = up;
|
|
|
|
unsigned short state, mask;
|
|
|
|
|
2012-03-02 14:59:20 +00:00
|
|
|
/* Review: FIXME: Console lock ? */
|
2005-04-16 22:20:36 +00:00
|
|
|
if (put_user(fg_console + 1, &vtstat->v_active))
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = -EFAULT;
|
|
|
|
else {
|
|
|
|
state = 1; /* /dev/tty0 is always open */
|
|
|
|
for (i = 0, mask = 2; i < MAX_NR_CONSOLES && mask;
|
|
|
|
++i, mask <<= 1)
|
|
|
|
if (VT_IS_IN_USE(i))
|
|
|
|
state |= mask;
|
|
|
|
ret = put_user(state, &vtstat->v_state);
|
|
|
|
}
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns the first available (non-opened) console.
|
|
|
|
*/
|
|
|
|
case VT_OPENQRY:
|
2012-03-02 14:59:20 +00:00
|
|
|
/* FIXME: locking ? - but then this is a stupid API */
|
2005-04-16 22:20:36 +00:00
|
|
|
for (i = 0; i < MAX_NR_CONSOLES; ++i)
|
|
|
|
if (! VT_IS_IN_USE(i))
|
|
|
|
break;
|
2010-10-27 22:33:00 +00:00
|
|
|
uival = i < MAX_NR_CONSOLES ? (i+1) : -1;
|
2005-04-16 22:20:36 +00:00
|
|
|
goto setint;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ioctl(fd, VT_ACTIVATE, num) will cause us to switch to vt # num,
|
|
|
|
* with num >= 1 (switches to vt 0, our console, are not allowed, just
|
|
|
|
* to preserve sanity).
|
|
|
|
*/
|
|
|
|
case VT_ACTIVATE:
|
|
|
|
if (!perm)
|
2012-03-02 14:59:20 +00:00
|
|
|
return -EPERM;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (arg == 0 || arg > MAX_NR_CONSOLES)
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = -ENXIO;
|
|
|
|
else {
|
|
|
|
arg--;
|
2011-01-25 23:07:35 +00:00
|
|
|
console_lock();
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = vc_allocate(arg);
|
2011-01-25 23:07:35 +00:00
|
|
|
console_unlock();
|
2008-04-30 07:53:26 +00:00
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
set_console(arg);
|
|
|
|
}
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-09-19 20:13:26 +00:00
|
|
|
case VT_SETACTIVATE:
|
|
|
|
{
|
|
|
|
struct vt_setactivate vsa;
|
|
|
|
|
|
|
|
if (!perm)
|
2012-03-02 14:59:20 +00:00
|
|
|
return -EPERM;
|
2009-09-19 20:13:26 +00:00
|
|
|
|
|
|
|
if (copy_from_user(&vsa, (struct vt_setactivate __user *)arg,
|
2009-10-01 22:43:59 +00:00
|
|
|
sizeof(struct vt_setactivate))) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-09-19 20:13:26 +00:00
|
|
|
if (vsa.console == 0 || vsa.console > MAX_NR_CONSOLES)
|
|
|
|
ret = -ENXIO;
|
|
|
|
else {
|
|
|
|
vsa.console--;
|
2011-01-25 23:07:35 +00:00
|
|
|
console_lock();
|
2009-09-19 20:13:26 +00:00
|
|
|
ret = vc_allocate(vsa.console);
|
|
|
|
if (ret == 0) {
|
|
|
|
struct vc_data *nvc;
|
|
|
|
/* This is safe providing we don't drop the
|
|
|
|
console sem between vc_allocate and
|
|
|
|
finishing referencing nvc */
|
|
|
|
nvc = vc_cons[vsa.console].d;
|
|
|
|
nvc->vt_mode = vsa.mode;
|
|
|
|
nvc->vt_mode.frsig = 0;
|
|
|
|
put_pid(nvc->vt_pid);
|
|
|
|
nvc->vt_pid = get_pid(task_pid(current));
|
|
|
|
}
|
2011-01-25 23:07:35 +00:00
|
|
|
console_unlock();
|
2009-09-19 20:13:26 +00:00
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
/* Commence switch and lock */
|
2012-03-02 14:59:20 +00:00
|
|
|
/* Review set_console locks */
|
2011-02-11 14:39:28 +00:00
|
|
|
set_console(vsa.console);
|
2009-09-19 20:13:26 +00:00
|
|
|
}
|
2011-02-11 14:39:28 +00:00
|
|
|
break;
|
2009-09-19 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* wait until the specified VT has been activated
|
|
|
|
*/
|
|
|
|
case VT_WAITACTIVE:
|
|
|
|
if (!perm)
|
2012-03-02 14:59:20 +00:00
|
|
|
return -EPERM;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (arg == 0 || arg > MAX_NR_CONSOLES)
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = -ENXIO;
|
2012-03-02 14:59:49 +00:00
|
|
|
else
|
2009-09-19 20:13:24 +00:00
|
|
|
ret = vt_waitactive(arg);
|
2008-04-30 07:53:26 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If a vt is under process control, the kernel will not switch to it
|
|
|
|
* immediately, but postpone the operation until the process calls this
|
|
|
|
* ioctl, allowing the switch to complete.
|
|
|
|
*
|
|
|
|
* According to the X sources this is the behavior:
|
|
|
|
* 0: pending switch-from not OK
|
|
|
|
* 1: pending switch-from OK
|
|
|
|
* 2: completed switch-to OK
|
|
|
|
*/
|
|
|
|
case VT_RELDISP:
|
|
|
|
if (!perm)
|
2012-03-02 14:59:20 +00:00
|
|
|
return -EPERM;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-03-02 14:59:20 +00:00
|
|
|
console_lock();
|
2008-04-30 07:53:26 +00:00
|
|
|
if (vc->vt_mode.mode != VT_PROCESS) {
|
2012-03-02 14:59:20 +00:00
|
|
|
console_unlock();
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Switching-from response
|
|
|
|
*/
|
|
|
|
if (vc->vt_newvt >= 0) {
|
|
|
|
if (arg == 0)
|
|
|
|
/*
|
|
|
|
* Switch disallowed, so forget we were trying
|
|
|
|
* to do it.
|
|
|
|
*/
|
|
|
|
vc->vt_newvt = -1;
|
|
|
|
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* The current vt has been released, so
|
|
|
|
* complete the switch.
|
|
|
|
*/
|
|
|
|
int newvt;
|
|
|
|
newvt = vc->vt_newvt;
|
|
|
|
vc->vt_newvt = -1;
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = vc_allocate(newvt);
|
|
|
|
if (ret) {
|
2011-01-25 23:07:35 +00:00
|
|
|
console_unlock();
|
2008-04-30 07:53:26 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* When we actually do the console switch,
|
|
|
|
* make sure we are atomic with respect to
|
|
|
|
* other console switches..
|
|
|
|
*/
|
|
|
|
complete_change_console(vc_cons[newvt].d);
|
|
|
|
}
|
2008-04-30 07:53:26 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Switched-to response
|
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* If it's just an ACK, ignore it
|
|
|
|
*/
|
2008-04-30 07:53:26 +00:00
|
|
|
if (arg != VT_ACKACQ)
|
|
|
|
ret = -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2011-01-25 23:07:35 +00:00
|
|
|
console_unlock();
|
2008-04-30 07:53:26 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Disallocate memory associated to VT (but leave VT1)
|
|
|
|
*/
|
|
|
|
case VT_DISALLOCATE:
|
2008-04-30 07:53:26 +00:00
|
|
|
if (arg > MAX_NR_CONSOLES) {
|
|
|
|
ret = -ENXIO;
|
|
|
|
break;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
if (arg == 0) {
|
2006-09-29 09:00:03 +00:00
|
|
|
/* deallocate all unused consoles, but leave 0 */
|
2011-01-25 23:07:35 +00:00
|
|
|
console_lock();
|
2005-04-16 22:20:36 +00:00
|
|
|
for (i=1; i<MAX_NR_CONSOLES; i++)
|
|
|
|
if (! VT_BUSY(i))
|
2006-09-29 09:00:03 +00:00
|
|
|
vc_deallocate(i);
|
2011-01-25 23:07:35 +00:00
|
|
|
console_unlock();
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
2006-09-29 09:00:03 +00:00
|
|
|
/* deallocate a single console, if possible */
|
2005-04-16 22:20:36 +00:00
|
|
|
arg--;
|
|
|
|
if (VT_BUSY(arg))
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = -EBUSY;
|
|
|
|
else if (arg) { /* leave 0 */
|
2011-01-25 23:07:35 +00:00
|
|
|
console_lock();
|
2006-09-29 09:00:03 +00:00
|
|
|
vc_deallocate(arg);
|
2011-01-25 23:07:35 +00:00
|
|
|
console_unlock();
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-30 07:53:26 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
case VT_RESIZE:
|
|
|
|
{
|
|
|
|
struct vt_sizes __user *vtsizes = up;
|
vt/vgacon: Check if screen resize request comes from userspace
Various console drivers are able to resize the screen via the con_resize()
hook. This hook is also visible in userspace via the TIOCWINSZ, VT_RESIZE and
VT_RESIZEX ioctl's. One particular utility, SVGATextMode, expects that
con_resize() of the VGA console will always return success even if the
resulting screen is not compatible with the hardware. However, this
particular behavior of the VGA console, as reported in Kernel Bugzilla Bug
7513, can cause undefined behavior if the user starts with a console size
larger than 80x25.
To work around this problem, add an extra parameter to con_resize(). This
parameter is ignored by drivers except for vgacon. If this parameter is
non-zero, then the resize request came from a VT_RESIZE or VT_RESIZEX ioctl
and vgacon will always return success. If this parameter is zero, vgacon will
return -EINVAL if the requested size is not compatible with the hardware. The
latter is the more correct behavior.
With this change, SVGATextMode should still work correctly while in-kernel and
stty resize calls can expect correct behavior from vgacon.
Signed-off-by: Antonino Daplas <adaplas@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-10-16 08:29:35 +00:00
|
|
|
struct vc_data *vc;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
ushort ll,cc;
|
|
|
|
if (!perm)
|
2012-03-02 14:59:20 +00:00
|
|
|
return -EPERM;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (get_user(ll, &vtsizes->v_rows) ||
|
|
|
|
get_user(cc, &vtsizes->v_cols))
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = -EFAULT;
|
|
|
|
else {
|
2011-01-25 23:07:35 +00:00
|
|
|
console_lock();
|
2008-04-30 07:53:26 +00:00
|
|
|
for (i = 0; i < MAX_NR_CONSOLES; i++) {
|
|
|
|
vc = vc_cons[i].d;
|
vt/vgacon: Check if screen resize request comes from userspace
Various console drivers are able to resize the screen via the con_resize()
hook. This hook is also visible in userspace via the TIOCWINSZ, VT_RESIZE and
VT_RESIZEX ioctl's. One particular utility, SVGATextMode, expects that
con_resize() of the VGA console will always return success even if the
resulting screen is not compatible with the hardware. However, this
particular behavior of the VGA console, as reported in Kernel Bugzilla Bug
7513, can cause undefined behavior if the user starts with a console size
larger than 80x25.
To work around this problem, add an extra parameter to con_resize(). This
parameter is ignored by drivers except for vgacon. If this parameter is
non-zero, then the resize request came from a VT_RESIZE or VT_RESIZEX ioctl
and vgacon will always return success. If this parameter is zero, vgacon will
return -EINVAL if the requested size is not compatible with the hardware. The
latter is the more correct behavior.
With this change, SVGATextMode should still work correctly while in-kernel and
stty resize calls can expect correct behavior from vgacon.
Signed-off-by: Antonino Daplas <adaplas@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-10-16 08:29:35 +00:00
|
|
|
|
2008-04-30 07:53:26 +00:00
|
|
|
if (vc) {
|
|
|
|
vc->vc_resize_user = 1;
|
2012-03-02 14:59:20 +00:00
|
|
|
/* FIXME: review v tty lock */
|
2008-08-15 09:39:38 +00:00
|
|
|
vc_resize(vc_cons[i].d, cc, ll);
|
2008-04-30 07:53:26 +00:00
|
|
|
}
|
vt/vgacon: Check if screen resize request comes from userspace
Various console drivers are able to resize the screen via the con_resize()
hook. This hook is also visible in userspace via the TIOCWINSZ, VT_RESIZE and
VT_RESIZEX ioctl's. One particular utility, SVGATextMode, expects that
con_resize() of the VGA console will always return success even if the
resulting screen is not compatible with the hardware. However, this
particular behavior of the VGA console, as reported in Kernel Bugzilla Bug
7513, can cause undefined behavior if the user starts with a console size
larger than 80x25.
To work around this problem, add an extra parameter to con_resize(). This
parameter is ignored by drivers except for vgacon. If this parameter is
non-zero, then the resize request came from a VT_RESIZE or VT_RESIZEX ioctl
and vgacon will always return success. If this parameter is zero, vgacon will
return -EINVAL if the requested size is not compatible with the hardware. The
latter is the more correct behavior.
With this change, SVGATextMode should still work correctly while in-kernel and
stty resize calls can expect correct behavior from vgacon.
Signed-off-by: Antonino Daplas <adaplas@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-10-16 08:29:35 +00:00
|
|
|
}
|
2011-01-25 23:07:35 +00:00
|
|
|
console_unlock();
|
vt/vgacon: Check if screen resize request comes from userspace
Various console drivers are able to resize the screen via the con_resize()
hook. This hook is also visible in userspace via the TIOCWINSZ, VT_RESIZE and
VT_RESIZEX ioctl's. One particular utility, SVGATextMode, expects that
con_resize() of the VGA console will always return success even if the
resulting screen is not compatible with the hardware. However, this
particular behavior of the VGA console, as reported in Kernel Bugzilla Bug
7513, can cause undefined behavior if the user starts with a console size
larger than 80x25.
To work around this problem, add an extra parameter to con_resize(). This
parameter is ignored by drivers except for vgacon. If this parameter is
non-zero, then the resize request came from a VT_RESIZE or VT_RESIZEX ioctl
and vgacon will always return success. If this parameter is zero, vgacon will
return -EINVAL if the requested size is not compatible with the hardware. The
latter is the more correct behavior.
With this change, SVGATextMode should still work correctly while in-kernel and
stty resize calls can expect correct behavior from vgacon.
Signed-off-by: Antonino Daplas <adaplas@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-10-16 08:29:35 +00:00
|
|
|
}
|
2008-04-30 07:53:26 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case VT_RESIZEX:
|
|
|
|
{
|
|
|
|
struct vt_consize __user *vtconsize = up;
|
|
|
|
ushort ll,cc,vlin,clin,vcol,ccol;
|
|
|
|
if (!perm)
|
2012-03-02 14:59:20 +00:00
|
|
|
return -EPERM;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!access_ok(VERIFY_READ, vtconsize,
|
2008-04-30 07:53:26 +00:00
|
|
|
sizeof(struct vt_consize))) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* FIXME: Should check the copies properly */
|
2005-04-16 22:20:36 +00:00
|
|
|
__get_user(ll, &vtconsize->v_rows);
|
|
|
|
__get_user(cc, &vtconsize->v_cols);
|
|
|
|
__get_user(vlin, &vtconsize->v_vlin);
|
|
|
|
__get_user(clin, &vtconsize->v_clin);
|
|
|
|
__get_user(vcol, &vtconsize->v_vcol);
|
|
|
|
__get_user(ccol, &vtconsize->v_ccol);
|
|
|
|
vlin = vlin ? vlin : vc->vc_scan_lines;
|
|
|
|
if (clin) {
|
|
|
|
if (ll) {
|
2008-04-30 07:53:26 +00:00
|
|
|
if (ll != vlin/clin) {
|
|
|
|
/* Parameters don't add up */
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
} else
|
|
|
|
ll = vlin/clin;
|
|
|
|
}
|
|
|
|
if (vcol && ccol) {
|
|
|
|
if (cc) {
|
2008-04-30 07:53:26 +00:00
|
|
|
if (cc != vcol/ccol) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
} else
|
|
|
|
cc = vcol/ccol;
|
|
|
|
}
|
|
|
|
|
2008-04-30 07:53:26 +00:00
|
|
|
if (clin > 32) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_NR_CONSOLES; i++) {
|
|
|
|
if (!vc_cons[i].d)
|
|
|
|
continue;
|
2011-01-25 23:07:35 +00:00
|
|
|
console_lock();
|
2005-04-16 22:20:36 +00:00
|
|
|
if (vlin)
|
|
|
|
vc_cons[i].d->vc_scan_lines = vlin;
|
|
|
|
if (clin)
|
|
|
|
vc_cons[i].d->vc_font.height = clin;
|
vt/vgacon: Check if screen resize request comes from userspace
Various console drivers are able to resize the screen via the con_resize()
hook. This hook is also visible in userspace via the TIOCWINSZ, VT_RESIZE and
VT_RESIZEX ioctl's. One particular utility, SVGATextMode, expects that
con_resize() of the VGA console will always return success even if the
resulting screen is not compatible with the hardware. However, this
particular behavior of the VGA console, as reported in Kernel Bugzilla Bug
7513, can cause undefined behavior if the user starts with a console size
larger than 80x25.
To work around this problem, add an extra parameter to con_resize(). This
parameter is ignored by drivers except for vgacon. If this parameter is
non-zero, then the resize request came from a VT_RESIZE or VT_RESIZEX ioctl
and vgacon will always return success. If this parameter is zero, vgacon will
return -EINVAL if the requested size is not compatible with the hardware. The
latter is the more correct behavior.
With this change, SVGATextMode should still work correctly while in-kernel and
stty resize calls can expect correct behavior from vgacon.
Signed-off-by: Antonino Daplas <adaplas@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-10-16 08:29:35 +00:00
|
|
|
vc_cons[i].d->vc_resize_user = 1;
|
2005-04-16 22:20:36 +00:00
|
|
|
vc_resize(vc_cons[i].d, cc, ll);
|
2011-01-25 23:07:35 +00:00
|
|
|
console_unlock();
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-04-30 07:53:26 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case PIO_FONT: {
|
|
|
|
if (!perm)
|
2012-03-02 14:59:20 +00:00
|
|
|
return -EPERM;
|
2005-04-16 22:20:36 +00:00
|
|
|
op.op = KD_FONT_OP_SET;
|
|
|
|
op.flags = KD_FONT_FLAG_OLD | KD_FONT_FLAG_DONT_RECALC; /* Compatibility */
|
|
|
|
op.width = 8;
|
|
|
|
op.height = 0;
|
|
|
|
op.charcount = 256;
|
|
|
|
op.data = up;
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = con_font_op(vc_cons[fg_console].d, &op);
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case GIO_FONT: {
|
|
|
|
op.op = KD_FONT_OP_GET;
|
|
|
|
op.flags = KD_FONT_FLAG_OLD;
|
|
|
|
op.width = 8;
|
|
|
|
op.height = 32;
|
|
|
|
op.charcount = 256;
|
|
|
|
op.data = up;
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = con_font_op(vc_cons[fg_console].d, &op);
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case PIO_CMAP:
|
|
|
|
if (!perm)
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = -EPERM;
|
|
|
|
else
|
|
|
|
ret = con_set_cmap(up);
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
case GIO_CMAP:
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = con_get_cmap(up);
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
case PIO_FONTX:
|
|
|
|
case GIO_FONTX:
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = do_fontx_ioctl(cmd, up, perm, &op);
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
case PIO_FONTRESET:
|
|
|
|
{
|
|
|
|
if (!perm)
|
2012-03-02 14:59:20 +00:00
|
|
|
return -EPERM;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#ifdef BROKEN_GRAPHICS_PROGRAMS
|
|
|
|
/* With BROKEN_GRAPHICS_PROGRAMS defined, the default
|
|
|
|
font is not saved. */
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = -ENOSYS;
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
#else
|
|
|
|
{
|
|
|
|
op.op = KD_FONT_OP_SET_DEFAULT;
|
|
|
|
op.data = NULL;
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = con_font_op(vc_cons[fg_console].d, &op);
|
|
|
|
if (ret)
|
|
|
|
break;
|
2012-04-24 10:06:06 +00:00
|
|
|
console_lock();
|
2005-04-16 22:20:36 +00:00
|
|
|
con_set_default_unimap(vc_cons[fg_console].d);
|
2012-04-24 10:06:06 +00:00
|
|
|
console_unlock();
|
2008-04-30 07:53:26 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
case KDFONTOP: {
|
2008-04-30 07:53:26 +00:00
|
|
|
if (copy_from_user(&op, up, sizeof(op))) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!perm && op.op != KD_FONT_OP_GET)
|
2012-03-02 14:59:20 +00:00
|
|
|
return -EPERM;
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = con_font_op(vc, &op);
|
|
|
|
if (ret)
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (copy_to_user(up, &op, sizeof(op)))
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = -EFAULT;
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case PIO_SCRNMAP:
|
|
|
|
if (!perm)
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = -EPERM;
|
2012-04-24 10:06:06 +00:00
|
|
|
else
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = con_set_trans_old(up);
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
case GIO_SCRNMAP:
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = con_get_trans_old(up);
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
case PIO_UNISCRNMAP:
|
|
|
|
if (!perm)
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = -EPERM;
|
2012-04-24 10:06:06 +00:00
|
|
|
else
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = con_set_trans_new(up);
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
case GIO_UNISCRNMAP:
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = con_get_trans_new(up);
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
case PIO_UNIMAPCLR:
|
|
|
|
{ struct unimapinit ui;
|
|
|
|
if (!perm)
|
2012-03-02 14:59:20 +00:00
|
|
|
return -EPERM;
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = copy_from_user(&ui, up, sizeof(struct unimapinit));
|
2010-06-04 10:20:46 +00:00
|
|
|
if (ret)
|
|
|
|
ret = -EFAULT;
|
2012-04-24 10:06:06 +00:00
|
|
|
else
|
2008-04-30 07:53:26 +00:00
|
|
|
con_clear_unimap(vc, &ui);
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case PIO_UNIMAP:
|
|
|
|
case GIO_UNIMAP:
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = do_unimap_ioctl(cmd, up, perm, vc);
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
case VT_LOCKSWITCH:
|
|
|
|
if (!capable(CAP_SYS_TTY_CONFIG))
|
2012-03-02 14:59:20 +00:00
|
|
|
return -EPERM;
|
2005-04-16 22:20:36 +00:00
|
|
|
vt_dont_switch = 1;
|
2008-04-30 07:53:26 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
case VT_UNLOCKSWITCH:
|
|
|
|
if (!capable(CAP_SYS_TTY_CONFIG))
|
2012-03-02 14:59:20 +00:00
|
|
|
return -EPERM;
|
2005-04-16 22:20:36 +00:00
|
|
|
vt_dont_switch = 0;
|
2008-04-30 07:53:26 +00:00
|
|
|
break;
|
2006-08-27 08:23:39 +00:00
|
|
|
case VT_GETHIFONTMASK:
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = put_user(vc->vc_hi_font_mask,
|
|
|
|
(unsigned short __user *)arg);
|
|
|
|
break;
|
2009-09-19 20:13:24 +00:00
|
|
|
case VT_WAITEVENT:
|
|
|
|
ret = vt_event_wait_ioctl((struct vt_event __user *)arg);
|
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
default:
|
2008-04-30 07:53:26 +00:00
|
|
|
ret = -ENOIOCTLCMD;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-04-30 07:53:26 +00:00
|
|
|
out:
|
|
|
|
return ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void reset_vc(struct vc_data *vc)
|
|
|
|
{
|
|
|
|
vc->vc_mode = KD_TEXT;
|
2012-02-28 14:49:23 +00:00
|
|
|
vt_reset_unicode(vc->vc_num);
|
2005-04-16 22:20:36 +00:00
|
|
|
vc->vt_mode.mode = VT_AUTO;
|
|
|
|
vc->vt_mode.waitv = 0;
|
|
|
|
vc->vt_mode.relsig = 0;
|
|
|
|
vc->vt_mode.acqsig = 0;
|
|
|
|
vc->vt_mode.frsig = 0;
|
2007-02-10 09:44:34 +00:00
|
|
|
put_pid(vc->vt_pid);
|
|
|
|
vc->vt_pid = NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
vc->vt_newvt = -1;
|
|
|
|
if (!in_interrupt()) /* Via keyboard.c:SAK() - akpm */
|
|
|
|
reset_palette(vc);
|
|
|
|
}
|
|
|
|
|
2007-02-10 09:44:34 +00:00
|
|
|
void vc_SAK(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct vc *vc_con =
|
|
|
|
container_of(work, struct vc, SAK_work);
|
|
|
|
struct vc_data *vc;
|
|
|
|
struct tty_struct *tty;
|
|
|
|
|
2011-01-25 23:07:35 +00:00
|
|
|
console_lock();
|
2007-02-10 09:44:34 +00:00
|
|
|
vc = vc_con->d;
|
|
|
|
if (vc) {
|
2012-02-28 14:49:23 +00:00
|
|
|
/* FIXME: review tty ref counting */
|
2010-06-01 20:52:56 +00:00
|
|
|
tty = vc->port.tty;
|
2007-02-10 09:44:34 +00:00
|
|
|
/*
|
|
|
|
* SAK should also work in all raw modes and reset
|
|
|
|
* them properly.
|
|
|
|
*/
|
|
|
|
if (tty)
|
|
|
|
__do_SAK(tty);
|
|
|
|
reset_vc(vc);
|
|
|
|
}
|
2011-01-25 23:07:35 +00:00
|
|
|
console_unlock();
|
2007-02-10 09:44:34 +00:00
|
|
|
}
|
|
|
|
|
2009-08-06 13:09:28 +00:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
|
|
|
|
struct compat_consolefontdesc {
|
|
|
|
unsigned short charcount; /* characters in font (256 or 512) */
|
|
|
|
unsigned short charheight; /* scan lines per character (1-32) */
|
|
|
|
compat_caddr_t chardata; /* font data in expanded form */
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
compat_fontx_ioctl(int cmd, struct compat_consolefontdesc __user *user_cfd,
|
|
|
|
int perm, struct console_font_op *op)
|
|
|
|
{
|
|
|
|
struct compat_consolefontdesc cfdarg;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (copy_from_user(&cfdarg, user_cfd, sizeof(struct compat_consolefontdesc)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case PIO_FONTX:
|
|
|
|
if (!perm)
|
|
|
|
return -EPERM;
|
|
|
|
op->op = KD_FONT_OP_SET;
|
|
|
|
op->flags = KD_FONT_FLAG_OLD;
|
|
|
|
op->width = 8;
|
|
|
|
op->height = cfdarg.charheight;
|
|
|
|
op->charcount = cfdarg.charcount;
|
|
|
|
op->data = compat_ptr(cfdarg.chardata);
|
|
|
|
return con_font_op(vc_cons[fg_console].d, op);
|
|
|
|
case GIO_FONTX:
|
|
|
|
op->op = KD_FONT_OP_GET;
|
|
|
|
op->flags = KD_FONT_FLAG_OLD;
|
|
|
|
op->width = 8;
|
|
|
|
op->height = cfdarg.charheight;
|
|
|
|
op->charcount = cfdarg.charcount;
|
|
|
|
op->data = compat_ptr(cfdarg.chardata);
|
|
|
|
i = con_font_op(vc_cons[fg_console].d, op);
|
|
|
|
if (i)
|
|
|
|
return i;
|
|
|
|
cfdarg.charheight = op->height;
|
|
|
|
cfdarg.charcount = op->charcount;
|
|
|
|
if (copy_to_user(user_cfd, &cfdarg, sizeof(struct compat_consolefontdesc)))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct compat_console_font_op {
|
|
|
|
compat_uint_t op; /* operation code KD_FONT_OP_* */
|
|
|
|
compat_uint_t flags; /* KD_FONT_FLAG_* */
|
|
|
|
compat_uint_t width, height; /* font size */
|
|
|
|
compat_uint_t charcount;
|
|
|
|
compat_caddr_t data; /* font data with height fixed to 32 */
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
compat_kdfontop_ioctl(struct compat_console_font_op __user *fontop,
|
|
|
|
int perm, struct console_font_op *op, struct vc_data *vc)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (copy_from_user(op, fontop, sizeof(struct compat_console_font_op)))
|
|
|
|
return -EFAULT;
|
|
|
|
if (!perm && op->op != KD_FONT_OP_GET)
|
|
|
|
return -EPERM;
|
|
|
|
op->data = compat_ptr(((struct compat_console_font_op *)op)->data);
|
|
|
|
i = con_font_op(vc, op);
|
|
|
|
if (i)
|
|
|
|
return i;
|
|
|
|
((struct compat_console_font_op *)op)->data = (unsigned long)op->data;
|
|
|
|
if (copy_to_user(fontop, op, sizeof(struct compat_console_font_op)))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct compat_unimapdesc {
|
|
|
|
unsigned short entry_ct;
|
|
|
|
compat_caddr_t entries;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
compat_unimap_ioctl(unsigned int cmd, struct compat_unimapdesc __user *user_ud,
|
|
|
|
int perm, struct vc_data *vc)
|
|
|
|
{
|
|
|
|
struct compat_unimapdesc tmp;
|
|
|
|
struct unipair __user *tmp_entries;
|
|
|
|
|
|
|
|
if (copy_from_user(&tmp, user_ud, sizeof tmp))
|
|
|
|
return -EFAULT;
|
|
|
|
tmp_entries = compat_ptr(tmp.entries);
|
|
|
|
if (tmp_entries)
|
|
|
|
if (!access_ok(VERIFY_WRITE, tmp_entries,
|
|
|
|
tmp.entry_ct*sizeof(struct unipair)))
|
|
|
|
return -EFAULT;
|
|
|
|
switch (cmd) {
|
|
|
|
case PIO_UNIMAP:
|
|
|
|
if (!perm)
|
|
|
|
return -EPERM;
|
|
|
|
return con_set_unimap(vc, tmp.entry_ct, tmp_entries);
|
|
|
|
case GIO_UNIMAP:
|
|
|
|
if (!perm && fg_console != vc->vc_num)
|
|
|
|
return -EPERM;
|
|
|
|
return con_get_unimap(vc, tmp.entry_ct, &(user_ud->entry_ct), tmp_entries);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-14 16:27:22 +00:00
|
|
|
long vt_compat_ioctl(struct tty_struct *tty,
|
2009-08-06 13:09:28 +00:00
|
|
|
unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
struct vc_data *vc = tty->driver_data;
|
|
|
|
struct console_font_op op; /* used in multiple places here */
|
|
|
|
unsigned int console;
|
|
|
|
void __user *up = (void __user *)arg;
|
|
|
|
int perm;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
console = vc->vc_num;
|
|
|
|
|
|
|
|
if (!vc_cons_allocated(console)) { /* impossible? */
|
|
|
|
ret = -ENOIOCTLCMD;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* To have permissions to do most of the vt ioctls, we either have
|
|
|
|
* to be the owner of the tty, or have CAP_SYS_TTY_CONFIG.
|
|
|
|
*/
|
|
|
|
perm = 0;
|
|
|
|
if (current->signal->tty == tty || capable(CAP_SYS_TTY_CONFIG))
|
|
|
|
perm = 1;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
/*
|
|
|
|
* these need special handlers for incompatible data structures
|
|
|
|
*/
|
|
|
|
case PIO_FONTX:
|
|
|
|
case GIO_FONTX:
|
|
|
|
ret = compat_fontx_ioctl(cmd, up, perm, &op);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KDFONTOP:
|
|
|
|
ret = compat_kdfontop_ioctl(up, perm, &op, vc);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PIO_UNIMAP:
|
|
|
|
case GIO_UNIMAP:
|
2009-09-28 18:10:02 +00:00
|
|
|
ret = compat_unimap_ioctl(cmd, up, perm, vc);
|
2009-08-06 13:09:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* all these treat 'arg' as an integer
|
|
|
|
*/
|
|
|
|
case KIOCSOUND:
|
|
|
|
case KDMKTONE:
|
|
|
|
#ifdef CONFIG_X86
|
|
|
|
case KDADDIO:
|
|
|
|
case KDDELIO:
|
|
|
|
#endif
|
|
|
|
case KDSETMODE:
|
|
|
|
case KDMAPDISP:
|
|
|
|
case KDUNMAPDISP:
|
|
|
|
case KDSKBMODE:
|
|
|
|
case KDSKBMETA:
|
|
|
|
case KDSKBLED:
|
|
|
|
case KDSETLED:
|
|
|
|
case KDSIGACCEPT:
|
|
|
|
case VT_ACTIVATE:
|
|
|
|
case VT_WAITACTIVE:
|
|
|
|
case VT_RELDISP:
|
|
|
|
case VT_DISALLOCATE:
|
|
|
|
case VT_RESIZE:
|
|
|
|
case VT_RESIZEX:
|
|
|
|
goto fallback;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* the rest has a compatible data structure behind arg,
|
|
|
|
* but we have to convert it to a proper 64 bit pointer.
|
|
|
|
*/
|
|
|
|
default:
|
|
|
|
arg = (unsigned long)compat_ptr(arg);
|
|
|
|
goto fallback;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
fallback:
|
2011-02-14 16:27:22 +00:00
|
|
|
return vt_ioctl(tty, cmd, arg);
|
2009-08-06 13:09:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* CONFIG_COMPAT */
|
|
|
|
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2009-09-19 20:13:26 +00:00
|
|
|
* Performs the back end of a vt switch. Called under the console
|
|
|
|
* semaphore.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
static void complete_change_console(struct vc_data *vc)
|
|
|
|
{
|
|
|
|
unsigned char old_vc_mode;
|
2009-09-19 20:13:24 +00:00
|
|
|
int old = fg_console;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
last_console = fg_console;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we're switching, we could be going from KD_GRAPHICS to
|
|
|
|
* KD_TEXT mode or vice versa, which means we need to blank or
|
|
|
|
* unblank the screen later.
|
|
|
|
*/
|
|
|
|
old_vc_mode = vc_cons[fg_console].d->vc_mode;
|
|
|
|
switch_screen(vc);
|
|
|
|
|
|
|
|
/*
|
2006-12-13 08:34:05 +00:00
|
|
|
* This can't appear below a successful kill_pid(). If it did,
|
2005-04-16 22:20:36 +00:00
|
|
|
* then the *blank_screen operation could occur while X, having
|
|
|
|
* received acqsig, is waking up on another processor. This
|
|
|
|
* condition can lead to overlapping accesses to the VGA range
|
|
|
|
* and the framebuffer (causing system lockups).
|
|
|
|
*
|
|
|
|
* To account for this we duplicate this code below only if the
|
|
|
|
* controlling process is gone and we've called reset_vc.
|
|
|
|
*/
|
|
|
|
if (old_vc_mode != vc->vc_mode) {
|
|
|
|
if (vc->vc_mode == KD_TEXT)
|
|
|
|
do_unblank_screen(1);
|
|
|
|
else
|
|
|
|
do_blank_screen(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this new console is under process control, send it a signal
|
|
|
|
* telling it that it has acquired. Also check if it has died and
|
|
|
|
* clean up (similar to logic employed in change_console())
|
|
|
|
*/
|
2010-03-16 00:14:15 +00:00
|
|
|
if (vc->vt_mode.mode == VT_PROCESS) {
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2006-12-13 08:34:05 +00:00
|
|
|
* Send the signal as privileged - kill_pid() will
|
2005-04-16 22:20:36 +00:00
|
|
|
* tell us if the process has gone or something else
|
|
|
|
* is awry
|
|
|
|
*/
|
2006-10-02 09:17:14 +00:00
|
|
|
if (kill_pid(vc->vt_pid, vc->vt_mode.acqsig, 1) != 0) {
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* The controlling process has died, so we revert back to
|
|
|
|
* normal operation. In this case, we'll also change back
|
|
|
|
* to KD_TEXT mode. I'm not sure if this is strictly correct
|
|
|
|
* but it saves the agony when the X server dies and the screen
|
|
|
|
* remains blanked due to KD_GRAPHICS! It would be nice to do
|
|
|
|
* this outside of VT_PROCESS but there is no single process
|
|
|
|
* to account for and tracking tty count may be undesirable.
|
|
|
|
*/
|
|
|
|
reset_vc(vc);
|
|
|
|
|
|
|
|
if (old_vc_mode != vc->vc_mode) {
|
|
|
|
if (vc->vc_mode == KD_TEXT)
|
|
|
|
do_unblank_screen(1);
|
|
|
|
else
|
|
|
|
do_blank_screen(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wake anyone waiting for their VT to activate
|
|
|
|
*/
|
2009-09-19 20:13:24 +00:00
|
|
|
vt_event_post(VT_EVENT_SWITCH, old, vc->vc_num);
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Performs the front-end of a vt switch
|
|
|
|
*/
|
|
|
|
void change_console(struct vc_data *new_vc)
|
|
|
|
{
|
|
|
|
struct vc_data *vc;
|
|
|
|
|
|
|
|
if (!new_vc || new_vc->vc_num == fg_console || vt_dont_switch)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this vt is in process mode, then we need to handshake with
|
|
|
|
* that process before switching. Essentially, we store where that
|
|
|
|
* vt wants to switch to and wait for it to tell us when it's done
|
|
|
|
* (via VT_RELDISP ioctl).
|
|
|
|
*
|
|
|
|
* We also check to see if the controlling process still exists.
|
|
|
|
* If it doesn't, we reset this vt to auto mode and continue.
|
|
|
|
* This is a cheap way to track process control. The worst thing
|
|
|
|
* that can happen is: we send a signal to a process, it dies, and
|
|
|
|
* the switch gets "lost" waiting for a response; hopefully, the
|
|
|
|
* user will try again, we'll detect the process is gone (unless
|
|
|
|
* the user waits just the right amount of time :-) and revert the
|
|
|
|
* vt to auto control.
|
|
|
|
*/
|
|
|
|
vc = vc_cons[fg_console].d;
|
2010-03-16 00:14:15 +00:00
|
|
|
if (vc->vt_mode.mode == VT_PROCESS) {
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2006-12-13 08:34:05 +00:00
|
|
|
* Send the signal as privileged - kill_pid() will
|
2005-04-16 22:20:36 +00:00
|
|
|
* tell us if the process has gone or something else
|
2007-09-29 16:47:51 +00:00
|
|
|
* is awry.
|
|
|
|
*
|
|
|
|
* We need to set vt_newvt *before* sending the signal or we
|
|
|
|
* have a race.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2007-09-29 16:47:51 +00:00
|
|
|
vc->vt_newvt = new_vc->vc_num;
|
2006-10-02 09:17:14 +00:00
|
|
|
if (kill_pid(vc->vt_pid, vc->vt_mode.relsig, 1) == 0) {
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2010-03-16 00:14:15 +00:00
|
|
|
* It worked. Mark the vt to switch to and
|
|
|
|
* return. The process needs to send us a
|
|
|
|
* VT_RELDISP ioctl to complete the switch.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2010-03-16 00:14:15 +00:00
|
|
|
return;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-03-16 00:14:15 +00:00
|
|
|
* The controlling process has died, so we revert back to
|
|
|
|
* normal operation. In this case, we'll also change back
|
|
|
|
* to KD_TEXT mode. I'm not sure if this is strictly correct
|
|
|
|
* but it saves the agony when the X server dies and the screen
|
|
|
|
* remains blanked due to KD_GRAPHICS! It would be nice to do
|
|
|
|
* this outside of VT_PROCESS but there is no single process
|
|
|
|
* to account for and tracking tty count may be undesirable.
|
|
|
|
*/
|
|
|
|
reset_vc(vc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fall through to normal (VT_AUTO) handling of the switch...
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ignore all switches in KD_GRAPHICS+VT_AUTO mode
|
|
|
|
*/
|
|
|
|
if (vc->vc_mode == KD_GRAPHICS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
complete_change_console(new_vc);
|
|
|
|
}
|
2009-09-19 20:13:25 +00:00
|
|
|
|
|
|
|
/* Perform a kernel triggered VT switch for suspend/resume */
|
|
|
|
|
|
|
|
static int disable_vt_switch;
|
|
|
|
|
|
|
|
int vt_move_to_console(unsigned int vt, int alloc)
|
|
|
|
{
|
|
|
|
int prev;
|
|
|
|
|
2011-01-25 23:07:35 +00:00
|
|
|
console_lock();
|
2009-09-19 20:13:25 +00:00
|
|
|
/* Graphics mode - up to X */
|
|
|
|
if (disable_vt_switch) {
|
2011-01-25 23:07:35 +00:00
|
|
|
console_unlock();
|
2009-09-19 20:13:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
prev = fg_console;
|
|
|
|
|
|
|
|
if (alloc && vc_allocate(vt)) {
|
|
|
|
/* we can't have a free VC for now. Too bad,
|
|
|
|
* we don't want to mess the screen for now. */
|
2011-01-25 23:07:35 +00:00
|
|
|
console_unlock();
|
2009-09-19 20:13:25 +00:00
|
|
|
return -ENOSPC;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (set_console(vt)) {
|
|
|
|
/*
|
|
|
|
* We're unable to switch to the SUSPEND_CONSOLE.
|
|
|
|
* Let the calling function know so it can decide
|
|
|
|
* what to do.
|
|
|
|
*/
|
2011-01-25 23:07:35 +00:00
|
|
|
console_unlock();
|
2009-09-19 20:13:25 +00:00
|
|
|
return -EIO;
|
|
|
|
}
|
2011-01-25 23:07:35 +00:00
|
|
|
console_unlock();
|
2009-08-11 21:20:41 +00:00
|
|
|
if (vt_waitactive(vt + 1)) {
|
2009-09-19 20:13:25 +00:00
|
|
|
pr_debug("Suspend: Can't switch VCs.");
|
|
|
|
return -EINTR;
|
|
|
|
}
|
|
|
|
return prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Normally during a suspend, we allocate a new console and switch to it.
|
|
|
|
* When we resume, we switch back to the original console. This switch
|
|
|
|
* can be slow, so on systems where the framebuffer can handle restoration
|
|
|
|
* of video registers anyways, there's little point in doing the console
|
|
|
|
* switch. This function allows you to disable it by passing it '0'.
|
|
|
|
*/
|
|
|
|
void pm_set_vt_switch(int do_switch)
|
|
|
|
{
|
2011-01-25 23:07:35 +00:00
|
|
|
console_lock();
|
2009-09-19 20:13:25 +00:00
|
|
|
disable_vt_switch = !do_switch;
|
2011-01-25 23:07:35 +00:00
|
|
|
console_unlock();
|
2009-09-19 20:13:25 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(pm_set_vt_switch);
|