aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/vt.c3
-rw-r--r--drivers/char/vt_ioctl.c203
2 files changed, 206 insertions, 0 deletions
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index 33214d92ca4c..5dfbfa7d7606 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -2910,6 +2910,9 @@ static const struct tty_operations con_ops = {
2910 .flush_chars = con_flush_chars, 2910 .flush_chars = con_flush_chars,
2911 .chars_in_buffer = con_chars_in_buffer, 2911 .chars_in_buffer = con_chars_in_buffer,
2912 .ioctl = vt_ioctl, 2912 .ioctl = vt_ioctl,
2913#ifdef CONFIG_COMPAT
2914 .compat_ioctl = vt_compat_ioctl,
2915#endif
2913 .stop = con_stop, 2916 .stop = con_stop,
2914 .start = con_start, 2917 .start = con_start,
2915 .throttle = con_throttle, 2918 .throttle = con_throttle,
diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c
index 0fceb8f4d6f2..30b5d128037c 100644
--- a/drivers/char/vt_ioctl.c
+++ b/drivers/char/vt_ioctl.c
@@ -16,6 +16,7 @@
16#include <linux/tty.h> 16#include <linux/tty.h>
17#include <linux/timer.h> 17#include <linux/timer.h>
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/compat.h>
19#include <linux/module.h> 20#include <linux/module.h>
20#include <linux/kd.h> 21#include <linux/kd.h>
21#include <linux/vt.h> 22#include <linux/vt.h>
@@ -1376,6 +1377,208 @@ void vc_SAK(struct work_struct *work)
1376 release_console_sem(); 1377 release_console_sem();
1377} 1378}
1378 1379
1380#ifdef CONFIG_COMPAT
1381
1382struct compat_consolefontdesc {
1383 unsigned short charcount; /* characters in font (256 or 512) */
1384 unsigned short charheight; /* scan lines per character (1-32) */
1385 compat_caddr_t chardata; /* font data in expanded form */
1386};
1387
1388static inline int
1389compat_fontx_ioctl(int cmd, struct compat_consolefontdesc __user *user_cfd,
1390 int perm, struct console_font_op *op)
1391{
1392 struct compat_consolefontdesc cfdarg;
1393 int i;
1394
1395 if (copy_from_user(&cfdarg, user_cfd, sizeof(struct compat_consolefontdesc)))
1396 return -EFAULT;
1397
1398 switch (cmd) {
1399 case PIO_FONTX:
1400 if (!perm)
1401 return -EPERM;
1402 op->op = KD_FONT_OP_SET;
1403 op->flags = KD_FONT_FLAG_OLD;
1404 op->width = 8;
1405 op->height = cfdarg.charheight;
1406 op->charcount = cfdarg.charcount;
1407 op->data = compat_ptr(cfdarg.chardata);
1408 return con_font_op(vc_cons[fg_console].d, op);
1409 case GIO_FONTX:
1410 op->op = KD_FONT_OP_GET;
1411 op->flags = KD_FONT_FLAG_OLD;
1412 op->width = 8;
1413 op->height = cfdarg.charheight;
1414 op->charcount = cfdarg.charcount;
1415 op->data = compat_ptr(cfdarg.chardata);
1416 i = con_font_op(vc_cons[fg_console].d, op);
1417 if (i)
1418 return i;
1419 cfdarg.charheight = op->height;
1420 cfdarg.charcount = op->charcount;
1421 if (copy_to_user(user_cfd, &cfdarg, sizeof(struct compat_consolefontdesc)))
1422 return -EFAULT;
1423 return 0;
1424 }
1425 return -EINVAL;
1426}
1427
1428struct compat_console_font_op {
1429 compat_uint_t op; /* operation code KD_FONT_OP_* */
1430 compat_uint_t flags; /* KD_FONT_FLAG_* */
1431 compat_uint_t width, height; /* font size */
1432 compat_uint_t charcount;
1433 compat_caddr_t data; /* font data with height fixed to 32 */
1434};
1435
1436static inline int
1437compat_kdfontop_ioctl(struct compat_console_font_op __user *fontop,
1438 int perm, struct console_font_op *op, struct vc_data *vc)
1439{
1440 int i;
1441
1442 if (copy_from_user(op, fontop, sizeof(struct compat_console_font_op)))
1443 return -EFAULT;
1444 if (!perm && op->op != KD_FONT_OP_GET)
1445 return -EPERM;
1446 op->data = compat_ptr(((struct compat_console_font_op *)op)->data);
1447 op->flags |= KD_FONT_FLAG_OLD;
1448 i = con_font_op(vc, op);
1449 if (i)
1450 return i;
1451 ((struct compat_console_font_op *)op)->data = (unsigned long)op->data;
1452 if (copy_to_user(fontop, op, sizeof(struct compat_console_font_op)))
1453 return -EFAULT;
1454 return 0;
1455}
1456
1457struct compat_unimapdesc {
1458 unsigned short entry_ct;
1459 compat_caddr_t entries;
1460};
1461
1462static inline int
1463compat_unimap_ioctl(unsigned int cmd, struct compat_unimapdesc __user *user_ud,
1464 int perm, struct vc_data *vc)
1465{
1466 struct compat_unimapdesc tmp;
1467 struct unipair __user *tmp_entries;
1468
1469 if (copy_from_user(&tmp, user_ud, sizeof tmp))
1470 return -EFAULT;
1471 tmp_entries = compat_ptr(tmp.entries);
1472 if (tmp_entries)
1473 if (!access_ok(VERIFY_WRITE, tmp_entries,
1474 tmp.entry_ct*sizeof(struct unipair)))
1475 return -EFAULT;
1476 switch (cmd) {
1477 case PIO_UNIMAP:
1478 if (!perm)
1479 return -EPERM;
1480 return con_set_unimap(vc, tmp.entry_ct, tmp_entries);
1481 case GIO_UNIMAP:
1482 if (!perm && fg_console != vc->vc_num)
1483 return -EPERM;
1484 return con_get_unimap(vc, tmp.entry_ct, &(user_ud->entry_ct), tmp_entries);
1485 }
1486 return 0;
1487}
1488
1489long vt_compat_ioctl(struct tty_struct *tty, struct file * file,
1490 unsigned int cmd, unsigned long arg)
1491{
1492 struct vc_data *vc = tty->driver_data;
1493 struct console_font_op op; /* used in multiple places here */
1494 struct kbd_struct *kbd;
1495 unsigned int console;
1496 void __user *up = (void __user *)arg;
1497 int perm;
1498 int ret = 0;
1499
1500 console = vc->vc_num;
1501
1502 lock_kernel();
1503
1504 if (!vc_cons_allocated(console)) { /* impossible? */
1505 ret = -ENOIOCTLCMD;
1506 goto out;
1507 }
1508
1509 /*
1510 * To have permissions to do most of the vt ioctls, we either have
1511 * to be the owner of the tty, or have CAP_SYS_TTY_CONFIG.
1512 */
1513 perm = 0;
1514 if (current->signal->tty == tty || capable(CAP_SYS_TTY_CONFIG))
1515 perm = 1;
1516
1517 kbd = kbd_table + console;
1518 switch (cmd) {
1519 /*
1520 * these need special handlers for incompatible data structures
1521 */
1522 case PIO_FONTX:
1523 case GIO_FONTX:
1524 ret = compat_fontx_ioctl(cmd, up, perm, &op);
1525 break;
1526
1527 case KDFONTOP:
1528 ret = compat_kdfontop_ioctl(up, perm, &op, vc);
1529 break;
1530
1531 case PIO_UNIMAP:
1532 case GIO_UNIMAP:
1533 ret = do_unimap_ioctl(cmd, up, perm, vc);
1534 break;
1535
1536 /*
1537 * all these treat 'arg' as an integer
1538 */
1539 case KIOCSOUND:
1540 case KDMKTONE:
1541#ifdef CONFIG_X86
1542 case KDADDIO:
1543 case KDDELIO:
1544#endif
1545 case KDSETMODE:
1546 case KDMAPDISP:
1547 case KDUNMAPDISP:
1548 case KDSKBMODE:
1549 case KDSKBMETA:
1550 case KDSKBLED:
1551 case KDSETLED:
1552 case KDSIGACCEPT:
1553 case VT_ACTIVATE:
1554 case VT_WAITACTIVE:
1555 case VT_RELDISP:
1556 case VT_DISALLOCATE:
1557 case VT_RESIZE:
1558 case VT_RESIZEX:
1559 goto fallback;
1560
1561 /*
1562 * the rest has a compatible data structure behind arg,
1563 * but we have to convert it to a proper 64 bit pointer.
1564 */
1565 default:
1566 arg = (unsigned long)compat_ptr(arg);
1567 goto fallback;
1568 }
1569out:
1570 unlock_kernel();
1571 return ret;
1572
1573fallback:
1574 unlock_kernel();
1575 return vt_ioctl(tty, file, cmd, arg);
1576}
1577
1578
1579#endif /* CONFIG_COMPAT */
1580
1581
1379/* 1582/*
1380 * Performs the back end of a vt switch. Called under the console 1583 * Performs the back end of a vt switch. Called under the console
1381 * semaphore. 1584 * semaphore.