linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] char: ppdev: check if ioctl argument is present and valid
@ 2020-10-08 18:27 Harshal Chaudhari
  2020-10-08 19:35 ` Arnd Bergmann
  2020-10-09  4:57 ` Greg KH
  0 siblings, 2 replies; 11+ messages in thread
From: Harshal Chaudhari @ 2020-10-08 18:27 UTC (permalink / raw)
  To: gregkh; +Cc: arnd, sudipm.mukherjee, linux-kernel, harshalchau04

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


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-10-24 21:28 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-08 18:27 [PATCH] char: ppdev: check if ioctl argument is present and valid Harshal Chaudhari
2020-10-08 19:35 ` Arnd Bergmann
2020-10-09  4:57 ` Greg KH
2020-10-10  0:08   ` Sudip Mukherjee
2020-10-10  9:10     ` Sudip Mukherjee
2020-10-13  9:01       ` harshal chaudhari
2020-10-13 10:58         ` Greg KH
2020-10-13 11:12         ` David Laight
     [not found]           ` <CAFEvwu=76mPtXSEgpwSoRC0rC0tkU5BiEx1X5O2VwVSPJ7m4Rw@mail.gmail.com>
2020-10-24 19:21             ` Arnd Bergmann
2020-10-24 20:16               ` harshal chaudhari
2020-10-24 21:22               ` David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).