From a40c683a8cf32a15b67eaa5ecc1a11f72fb4fb42 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Mon, 28 May 2018 22:50:24 +0200 Subject: Copy cdev ioctl params from user --- char.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 76 insertions(+), 9 deletions(-) diff --git a/char.c b/char.c index ae718c6..90bd16c 100644 --- a/char.c +++ b/char.c @@ -17,24 +17,91 @@ dev_t first; int major; -int next_minor = 0; +bool minors[DOOMDEV_COUNT]; +long do_new_surface(struct file *filp, unsigned long arg) +{ + struct doomdev_ioctl_create_surface param; + int not_copied; + int err; + + not_copied = copy_from_user(¶m, (void __iomem *) arg, sizeof(param)); + if (not_copied) { + err = -EFAULT; + goto error_param; + } + + err = new_surface(filp, ¶m); + +error_param: + return err; +} + +long do_new_texture(struct file *filp, unsigned long arg) +{ + struct doomdev_ioctl_create_texture param; + int not_copied; + int err; + + not_copied = copy_from_user(¶m, (void __iomem *) arg, sizeof(param)); + if (not_copied) { + err = -EFAULT; + goto error_param; + } + + err = new_texture(filp, ¶m); + +error_param: + return err; +} + +long do_new_flat(struct file *filp, unsigned long arg) +{ + struct doomdev_ioctl_create_flat param; + int not_copied; + int err; + + not_copied = copy_from_user(¶m, (void __iomem *) arg, sizeof(param)); + if (not_copied) { + err = -EFAULT; + goto error_param; + } + + err = new_flat(filp, ¶m); + +error_param: + return err; +} + +long do_new_colors(struct file *filp, unsigned long arg) +{ + struct doomdev_ioctl_create_colormaps param; + int not_copied; + int err; + + not_copied = copy_from_user(¶m, (void __iomem *) arg, sizeof(param)); + if (not_copied) { + err = -EFAULT; + goto error_param; + } + + err = new_colors(filp, ¶m); + +error_param: + return err; +} long doom_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { switch (cmd) { case DOOMDEV_IOCTL_CREATE_SURFACE: - return new_surface(filp, - (struct doomdev_ioctl_create_surface *) arg); + return do_new_surface(filp, arg); case DOOMDEV_IOCTL_CREATE_TEXTURE: - return new_texture(filp, - (struct doomdev_ioctl_create_texture *) arg); + return do_new_texture(filp, arg); case DOOMDEV_IOCTL_CREATE_FLAT: - return new_flat(filp, - (struct doomdev_ioctl_create_flat *) arg); + return do_new_flat(filp, arg); case DOOMDEV_IOCTL_CREATE_COLORMAPS: - return new_colors(filp, - (struct doomdev_ioctl_create_colormaps *) arg); + return do_new_colors(filp, arg); default: return -ENOTTY; } -- cgit v1.2.3