lkml.org 
[lkml]   [2020]   [Oct]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] char: ppdev: check if ioctl argument is present and valid
Date
Checking the argument passed to the ioctl is valid
or not. if not then return -EINVAL.

Signed-off-by: Harshal Chaudhari <harshalchau04@gmail.com>
---
drivers/char/ppdev.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c
index 38b46c7d1737..001392980202 100644
--- a/drivers/char/ppdev.c
+++ b/drivers/char/ppdev.c
@@ -354,7 +354,7 @@ static int pp_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
unsigned int minor = iminor(file_inode(file));
struct pp_struct *pp = file->private_data;
struct parport *port;
- void __user *argp = (void __user *)arg;
+ void __user *argp = NULL;
struct ieee1284_info *info;
unsigned char reg;
unsigned char mask;
@@ -364,6 +364,16 @@ static int pp_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
struct timespec64 ts;
int ret;

+ if (_IOC_TYPE(cmd) != PP_IOCTL)
+ return -ENOTTY;
+
+ /* check if ioctl argument is present and valid */
+ if (_IOC_DIR(cmd) != _IOC_NONE) {
+ argp = (void __user *)arg;
+ if (!argp)
+ return -EINVAL;
+ }
+
/* First handle the cases that don't take arguments. */
switch (cmd) {
case PPCLAIM:
--
2.17.1
\
 
 \ /
  Last update: 2020-10-08 20:27    [W:0.109 / U:0.792 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site