linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Harshal Chaudhari <harshalchau04@gmail.com>
To: gregkh@linuxfoundation.org
Cc: arnd@arndb.de, sudipm.mukherjee@gmail.com,
	linux-kernel@vger.kernel.org, harshalchau04@gmail.com
Subject: [PATCH] char: ppdev: check if ioctl argument is present and valid
Date: Thu,  8 Oct 2020 23:57:13 +0530	[thread overview]
Message-ID: <20201008182713.2764-1-harshalchau04@gmail.com> (raw)

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


             reply	other threads:[~2020-10-08 18:27 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-08 18:27 Harshal Chaudhari [this message]
2020-10-08 19:35 ` [PATCH] char: ppdev: check if ioctl argument is present and valid 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201008182713.2764-1-harshalchau04@gmail.com \
    --to=harshalchau04@gmail.com \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sudipm.mukherjee@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).