public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] char: ppdev: fixed a validation issue
@ 2021-11-08 18:58 Vihas Mak
  2021-11-09  6:25 ` Greg KH
  0 siblings, 1 reply; 8+ messages in thread
From: Vihas Mak @ 2021-11-08 18:58 UTC (permalink / raw)
  To: sudipm.mukherjee; +Cc: arnd, gregkh, linux-kernel

Make sure the mode is a valid IEEE1284 mode.

Signed-off-by: Vihas Mak <makvihas@gmail.com>
---
 drivers/char/ppdev.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c
index 38b46c7d1737..3b290cbf6c66 100644
--- a/drivers/char/ppdev.c
+++ b/drivers/char/ppdev.c
@@ -333,6 +333,28 @@ static enum ieee1284_phase init_phase(int mode)
 	return IEEE1284_PH_FWD_IDLE;
 }
 
+/*
+ * Validate the mode and make sure the mode is power of two.
+ *
+ * IEEE1284_MODE_ECPRLE and IEEE1284_MODE_NIBBLE are exception
+ * to this so handle them accordingly.
+ */
+
+static int pp_validate_mode(int mode)
+{
+	if (mode == IEEE1284_MODE_ECPRLE || mode == IEEE1284_MODE_NIBBLE) {
+		return 1;
+	} else if (!(mode & (mode - 1)) &&
+		   (mode & (IEEE1284_MODE_BYTE | IEEE1284_MODE_COMPAT |
+			    IEEE1284_MODE_BECP | IEEE1284_MODE_ECP |
+			    IEEE1284_MODE_ECPSWE | IEEE1284_MODE_EPP |
+			    IEEE1284_MODE_EPPSL | IEEE1284_MODE_COMPAT |
+			    IEEE1284_MODE_EPPSWE))) {
+		return 1;
+	}
+	return 0;
+}
+
 static int pp_set_timeout(struct pardevice *pdev, long tv_sec, int tv_usec)
 {
 	long to_jiffies;
@@ -423,7 +445,11 @@ static int pp_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 
 		if (copy_from_user(&mode, argp, sizeof(mode)))
 			return -EFAULT;
-		/* FIXME: validate mode */
+
+		/* Validate mode */
+		if (!pp_validate_mode(mode))
+			return -EINVAL;
+
 		pp->state.mode = mode;
 		pp->state.phase = init_phase(mode);
 
-- 
2.25.1


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

end of thread, other threads:[~2021-11-09 17:56 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-08 18:58 [PATCH] char: ppdev: fixed a validation issue Vihas Mak
2021-11-09  6:25 ` Greg KH
2021-11-09 10:41   ` Vihas Mak
2021-11-09 11:23     ` Greg KH
2021-11-09 15:34       ` Vihas Mak
2021-11-09 15:41         ` Greg KH
2021-11-09 17:51           ` Vihas Mak
2021-11-09 17:55             ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox