char: ppdev: fixed a validation issue
Subsystems (2)
PATCH 1/1 char: ppdev: fixed a validation issue
Make sure the mode is a valid IEEE1284 mode.
--- drivers/char/ppdev.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/char/ppdev.c +27 -1
@@ -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);
Signature · 1 line
2.25.1
Greg KH
maintainerQuoted 1 line · Vihas Mak
Make sure the mode is a valid IEEE1284 mode.
What is a valid mode?
Quoted 10 lines
Signed-off-by Vihas Mak <[email protected]>--- drivers/char/ppdev.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)drivers/char/ppdev.c +0
-0
drivers/char/ppdev.c static enum ieee1284_phase init_phase(int mode) · line 342
Quoted 10 lines
drivers/char/ppdev.c +7
-0@@ -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. +*/ +
Why the extra line?
drivers/char/ppdev.c static enum ieee1284_phase init_phase(int mode) · line 343
Quoted 1 line
drivers/char/ppdev.c +1
-0+static int pp_validate_mode (int mode)
bool?
drivers/char/ppdev.c static enum ieee1284_phase init_phase(int mode) · line 356
Quoted 13 lines
drivers/char/ppdev.c +13
-0+{ +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 ; +}
How did you test this? And why is this needed now? What hardware was working that is now not going to work with this driver?
thanks,
greg k-h
Quoted 3 lines · Vihas Mak
Quoted 1 line
Make sure the mode is a valid IEEE1284 mode.
What is a valid mode?
The valid IEEE1284 modes are the ones defined in <uapi/linux/parport.h>. Currently there are 10 modes. Namely nibble mode, byte mode, ECP, ECPRLE, EPP and some specials.
Quoted 2 lines
How did you test this? And why is this needed now? What hardware was working that is now not going to work with this driver?
I tested this on my local pc using a parallel port and read the incoming data on my Raspberry PI.
I also used https://github.com/strezh/VPPSniffer. It's a simple virtual parallel port used for debugging and sniffing.
The mainline code wasn't validating the mode when a user-space program does a ioctl call to change the current mode. It might create some bugs if the new mode isn't one of the IEEE1284 modes defined in <uapi/linux/parport.h>. So it's better to throw a EINVAL beforehand, if the mode is invalid.
Quoted 2 lines
Quoted 1 line
+static int
pp_validate_mode(int mode)bool?
My bad. Will do a v2.
Thanks,
Vihas
Quoted 53 lines · Greg KH
Quoted 1 line · Vihas Mak
Make sure the mode is a valid IEEE1284 mode.
What is a valid mode?
Quoted 10 lines
Signed-off-by Vihas Mak <[email protected]>--- drivers/char/ppdev.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)drivers/char/ppdev.c +0
-0drivers/char/ppdev.c static enum ieee1284_phase init_phase(int mode) · line 342
Quoted 10 lines
drivers/char/ppdev.c +7
-0@@ -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. +*/ +Why the extra line?
drivers/char/ppdev.c static enum ieee1284_phase init_phase(int mode) · line 343
Quoted 1 line
drivers/char/ppdev.c +1
-0+static int pp_validate_mode (int mode)bool?
drivers/char/ppdev.c static enum ieee1284_phase init_phase(int mode) · line 356
Quoted 13 lines
drivers/char/ppdev.c +13
-0+{ +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 ; +}How did you test this? And why is this needed now? What hardware was working that is now not going to work with this driver?
thanks,
greg k-h
Greg KH
maintainerQuoted 7 lines · Vihas Mak
Quoted 3 lines · Vihas Mak
Quoted 1 line
Make sure the mode is a valid IEEE1284 mode.
What is a valid mode?
The valid IEEE1284 modes are the ones defined in <
uapi/linux/parport.h>. Currently there are 10 modes. Namely nibble mode, byte mode, ECP, ECPRLE, EPP and some specials.
But what happens today if code has not been sending those values properly? This is a very old driver for very old hardware.
Quoted 8 lines
Quoted 2 lines
How did you test this? And why is this needed now? What hardware was working that is now not going to work with this driver?
I tested this on my local pc using a parallel port and read the incoming data on my Raspberry PI.
I also used https://github.com/strezh/VPPSniffer. It's a simple virtual parallel port used for debugging and sniffing.
Quoted 5 lines
The mainline code wasn't validating the mode when a user-space program does a ioctl call to change the current mode. It might create some bugs if the new mode isn't one of the IEEE1284 modes defined in <
uapi/linux/parport.h>. So it's better to throw a EINVAL beforehand, if the mode is invalid.
What happens today if the mode is not set properly? Will the code paths error out eventually, or will the call succeed? The problem is that there might be code that is working today that would break with a change like this, as again, this is a very old driver.
thanks,
greg k-h
Quoted 4 lines
What happens today if the mode is not set properly? Will the code paths error out eventually, or will the call succeed? The problem is that there might be code that is working today that would break with a change like this, as again, this is a very old driver.
I see. So I guess this driver might be better off without any changes, as new changes might break things more severely.
Thanks,
Vihas
Quoted 35 lines · Greg KH
Quoted 7 lines · Vihas Mak
Quoted 3 lines · Vihas Mak
Quoted 1 line
Make sure the mode is a valid IEEE1284 mode.
What is a valid mode?
The valid IEEE1284 modes are the ones defined in <
uapi/linux/parport.h>. Currently there are 10 modes. Namely nibble mode, byte mode, ECP, ECPRLE, EPP and some specials.But what happens today if code has not been sending those values properly? This is a very old driver for very old hardware.
Quoted 8 lines
Quoted 2 lines
How did you test this? And why is this needed now? What hardware was working that is now not going to work with this driver?
I tested this on my local pc using a parallel port and read the incoming data on my Raspberry PI.
I also used https://github.com/strezh/VPPSniffer. It's a simple virtual parallel port used for debugging and sniffing.Quoted 5 lines
The mainline code wasn't validating the mode when a user-space program does a ioctl call to change the current mode. It might create some bugs if the new mode isn't one of the IEEE1284 modes defined in <
uapi/linux/parport.h>. So it's better to throw a EINVAL beforehand, if the mode is invalid.What happens today if the mode is not set properly? Will the code paths error out eventually, or will the call succeed? The problem is that there might be code that is working today that would break with a change like this, as again, this is a very old driver.
thanks,
greg k-h
Greg KH
maintainerQuoted 7 lines · Vihas Mak
Quoted 4 lines
What happens today if the mode is not set properly? Will the code paths error out eventually, or will the call succeed? The problem is that there might be code that is working today that would break with a change like this, as again, this is a very old driver.
I see. So I guess this driver might be better off without any changes, as new changes might break things more severely.
Changes in behavior always have the ability to break things. What other changes do you want to make to this old driver that might cause problems?
And you didn't answer my question above, what happens if the mode is not set properly today?
thanks,
greg k-h
Quoted 2 lines
And you didn't answer my question above, what happens if the mode is not set properly today?
It'll throw a ENOSYS if the mode is not set properly and print the following:
pr_debug("%s: Unknown mode 0x%02x\n",
port->name, port->ieee1284.mode);
Quoted 20 lines · Greg KH
Quoted 7 lines · Vihas Mak
Quoted 4 lines
What happens today if the mode is not set properly? Will the code paths error out eventually, or will the call succeed? The problem is that there might be code that is working today that would break with a change like this, as again, this is a very old driver.
I see. So I guess this driver might be better off without any changes, as new changes might break things more severely.
Changes in behavior always have the ability to break things. What other changes do you want to make to this old driver that might cause problems?
And you didn't answer my question above, what happens if the mode is not set properly today?
thanks,
greg k-h
Greg KH
maintainerQuoted 7 lines · Vihas Mak
Quoted 2 lines
And you didn't answer my question above, what happens if the mode is not set properly today?
It'll throw a ENOSYS if the mode is not set properly and print the following:
pr_debug("%s: Unknown mode 0x%02x\n",
port->name, port->ieee1284.mode);
Ah, good, so then your change is not needed at all, so why add it?
thanks,
greg k-h