Commit bd048df6 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] con_font_default sanitized

->con_font_default() sanitized.  We copy font name (if any) from userland
in the caller and pass it explicitly.  We are also beginning to get rid
of console_font_op in method arguments.
Signed-off-by: default avatarAl Viro <viro@parcelfarce.linux.org.uk>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent a95b87ea
...@@ -100,6 +100,7 @@ ...@@ -100,6 +100,7 @@
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <linux/bootmem.h> #include <linux/bootmem.h>
#include <linux/pm.h> #include <linux/pm.h>
#include <linux/font.h>
#include <asm/io.h> #include <asm/io.h>
#include <asm/system.h> #include <asm/system.h>
...@@ -3139,17 +3140,31 @@ int con_font_set(int currcons, struct console_font_op *op) ...@@ -3139,17 +3140,31 @@ int con_font_set(int currcons, struct console_font_op *op)
int con_font_default(int currcons, struct console_font_op *op) int con_font_default(int currcons, struct console_font_op *op)
{ {
struct console_font font = {.width = op->width, .height = op->height};
char name[MAX_FONT_NAME];
char *s = name;
int rc; int rc;
if (vt_cons[currcons]->vc_mode != KD_TEXT) if (vt_cons[currcons]->vc_mode != KD_TEXT)
return -EINVAL; return -EINVAL;
if (!op->data)
s = NULL;
else if (strncpy_from_user(name, op->data, MAX_FONT_NAME - 1) < 0)
return -EFAULT;
else
name[MAX_FONT_NAME - 1] = 0;
acquire_console_sem(); acquire_console_sem();
if (sw->con_font_default) if (sw->con_font_default)
rc = sw->con_font_default(vc_cons[currcons].d, op); rc = sw->con_font_default(vc_cons[currcons].d, &font, s);
else else
rc = -ENOSYS; rc = -ENOSYS;
release_console_sem(); release_console_sem();
if (!rc) {
op->width = font.width;
op->height = font.height;
}
return rc; return rc;
} }
......
...@@ -2272,24 +2272,21 @@ static int fbcon_set_font(struct vc_data *vc, struct console_font_op *op) ...@@ -2272,24 +2272,21 @@ static int fbcon_set_font(struct vc_data *vc, struct console_font_op *op)
return fbcon_do_set_font(vc, op, new_data, 1); return fbcon_do_set_font(vc, op, new_data, 1);
} }
static int fbcon_set_def_font(struct vc_data *vc, struct console_font_op *op) static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
{ {
struct fb_info *info = registered_fb[(int) con2fb_map[vc->vc_num]]; struct fb_info *info = registered_fb[(int) con2fb_map[vc->vc_num]];
char name[MAX_FONT_NAME];
struct font_desc *f; struct font_desc *f;
struct console_font_op crap;
if (!op->data) if (!name)
f = get_default_font(info->var.xres, info->var.yres); f = get_default_font(info->var.xres, info->var.yres);
else if (strncpy_from_user(name, op->data, MAX_FONT_NAME - 1) < 0) else if (!(f = find_font(name)))
return -EFAULT;
else {
name[MAX_FONT_NAME - 1] = 0;
if (!(f = find_font(name)))
return -ENOENT; return -ENOENT;
}
op->width = f->width; crap.op = KD_FONT_OP_SET_DEFAULT;
op->height = f->height; crap.width = font->width = f->width;
return fbcon_do_set_font(vc, op, f->data, 0); crap.height = font->height = f->height;
return fbcon_do_set_font(vc, &crap, f->data, 0);
} }
static u16 palette_red[16]; static u16 palette_red[16];
......
...@@ -52,7 +52,7 @@ static int xcurs_correction = 29; ...@@ -52,7 +52,7 @@ static int xcurs_correction = 29;
static int newport_xsize; static int newport_xsize;
static int newport_ysize; static int newport_ysize;
static int newport_set_def_font(int unit, struct console_font_op *op); static int newport_set_def_font(int unit, struct console_font *op);
#define BMASK(c) (c << 24) #define BMASK(c) (c << 24)
...@@ -531,7 +531,7 @@ static int newport_set_font(int unit, struct console_font_op *op) ...@@ -531,7 +531,7 @@ static int newport_set_font(int unit, struct console_font_op *op)
return 0; return 0;
} }
static int newport_set_def_font(int unit, struct console_font_op *op) static int newport_set_def_font(int unit, struct console_font *op)
{ {
if (font_data[unit] != FONT_DATA) { if (font_data[unit] != FONT_DATA) {
if (--REFCOUNT(font_data[unit]) == 0) if (--REFCOUNT(font_data[unit]) == 0)
...@@ -543,7 +543,7 @@ static int newport_set_def_font(int unit, struct console_font_op *op) ...@@ -543,7 +543,7 @@ static int newport_set_def_font(int unit, struct console_font_op *op)
return 0; return 0;
} }
static int newport_font_default(struct vc_data *vc, struct console_font_op *op) static int newport_font_default(struct vc_data *vc, struct console_font *op, char *name)
{ {
return newport_set_def_font(vc->vc_num, op); return newport_set_def_font(vc->vc_num, op);
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
struct vc_data; struct vc_data;
struct console_font_op; struct console_font_op;
struct console_font;
struct module; struct module;
/* /*
...@@ -42,7 +43,7 @@ struct consw { ...@@ -42,7 +43,7 @@ struct consw {
int (*con_blank)(struct vc_data *, int, int); int (*con_blank)(struct vc_data *, int, int);
int (*con_font_set)(struct vc_data *, struct console_font_op *); int (*con_font_set)(struct vc_data *, struct console_font_op *);
int (*con_font_get)(struct vc_data *, struct console_font_op *); int (*con_font_get)(struct vc_data *, struct console_font_op *);
int (*con_font_default)(struct vc_data *, struct console_font_op *); int (*con_font_default)(struct vc_data *, struct console_font *, char *);
int (*con_font_copy)(struct vc_data *, struct console_font_op *); int (*con_font_copy)(struct vc_data *, struct console_font_op *);
int (*con_resize)(struct vc_data *, unsigned int, unsigned int); int (*con_resize)(struct vc_data *, unsigned int, unsigned int);
int (*con_set_palette)(struct vc_data *, unsigned char *); int (*con_set_palette)(struct vc_data *, unsigned char *);
......
...@@ -152,6 +152,12 @@ struct console_font_op { ...@@ -152,6 +152,12 @@ struct console_font_op {
unsigned char *data; /* font data with height fixed to 32 */ unsigned char *data; /* font data with height fixed to 32 */
}; };
struct console_font {
unsigned int width, height; /* font size */
unsigned int charcount;
unsigned char *data; /* font data with height fixed to 32 */
};
#define KD_FONT_OP_SET 0 /* Set font */ #define KD_FONT_OP_SET 0 /* Set font */
#define KD_FONT_OP_GET 1 /* Get font */ #define KD_FONT_OP_GET 1 /* Get font */
#define KD_FONT_OP_SET_DEFAULT 2 /* Set font to default, data points to name / NULL */ #define KD_FONT_OP_SET_DEFAULT 2 /* Set font to default, data points to name / NULL */
......
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