diff mbox series

tty: serial: return appropriate error on failure

Message ID 20211207221741.50422-1-makvihas@gmail.com
State New
Headers show
Series tty: serial: return appropriate error on failure | expand

Commit Message

Vihas Mak Dec. 7, 2021, 10:17 p.m. UTC
when a user with CAP_SYS_ADMIN disabled calls ioctl (TIOCSSERIAL),
uart_set_info() returns 0 instead of -EPERM and the user remains unware
about what went wrong. Fix this.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=215205

Signed-off-by: Vihas Mak <makvihas@gmail.com>
---
 drivers/tty/serial/serial_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jiri Slaby Dec. 8, 2021, 5:44 a.m. UTC | #1
On 07. 12. 21, 23:17, Vihas Mak wrote:
> when a user with CAP_SYS_ADMIN disabled calls ioctl (TIOCSSERIAL),
> uart_set_info() returns 0 instead of -EPERM and the user remains unware
> about what went wrong. Fix this.
> 
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=215205
> 
> Signed-off-by: Vihas Mak <makvihas@gmail.com>
> ---
>   drivers/tty/serial/serial_core.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> index 61e3dd022..c204bdecc 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -960,7 +960,7 @@ static int uart_set_info(struct tty_struct *tty, struct tty_port *port,
>   		uport->fifosize = new_info->xmit_fifo_size;
>   
>    check_and_exit:
> -	retval = 0;
> +	retval = retval < 0 ? retval : 0;

This is wrong IMO. See:
https://bugzilla.kernel.org/show_bug.cgi?id=215205#c1

>   	if (uport->type == PORT_UNKNOWN)
>   		goto exit;
>   	if (tty_port_initialized(port)) {
>
Greg Kroah-Hartman Dec. 8, 2021, 5:44 a.m. UTC | #2
On Wed, Dec 08, 2021 at 03:47:41AM +0530, Vihas Mak wrote:
> when a user with CAP_SYS_ADMIN disabled calls ioctl (TIOCSSERIAL),
> uart_set_info() returns 0 instead of -EPERM and the user remains unware
> about what went wrong. Fix this.
> 
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=215205
> 
> Signed-off-by: Vihas Mak <makvihas@gmail.com>
> ---
>  drivers/tty/serial/serial_core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> index 61e3dd022..c204bdecc 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -960,7 +960,7 @@ static int uart_set_info(struct tty_struct *tty, struct tty_port *port,
>  		uport->fifosize = new_info->xmit_fifo_size;
>  
>   check_and_exit:
> -	retval = 0;
> +	retval = retval < 0 ? retval : 0;

Please no, do not use ? : unless you have to.  Spell it out and use a
real if statement.

thanks,

greg k-h
Vihas Mak Dec. 8, 2021, 2:12 p.m. UTC | #3
>> Please no, do not use ? : unless you have to.  Spell it out and use a
>> real if statement.

Okay. But I don't think it's required anymore, as Jiri pointed out in
https://bugzilla.kernel.org/show_bug.cgi?id=215205#c1

On Wed, Dec 8, 2021 at 11:15 AM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Wed, Dec 08, 2021 at 03:47:41AM +0530, Vihas Mak wrote:
> > when a user with CAP_SYS_ADMIN disabled calls ioctl (TIOCSSERIAL),
> > uart_set_info() returns 0 instead of -EPERM and the user remains unware
> > about what went wrong. Fix this.
> >
> > Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=215205
> >
> > Signed-off-by: Vihas Mak <makvihas@gmail.com>
> > ---
> >  drivers/tty/serial/serial_core.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> > index 61e3dd022..c204bdecc 100644
> > --- a/drivers/tty/serial/serial_core.c
> > +++ b/drivers/tty/serial/serial_core.c
> > @@ -960,7 +960,7 @@ static int uart_set_info(struct tty_struct *tty, struct tty_port *port,
> >               uport->fifosize = new_info->xmit_fifo_size;
> >
> >   check_and_exit:
> > -     retval = 0;
> > +     retval = retval < 0 ? retval : 0;
>
> Please no, do not use ? : unless you have to.  Spell it out and use a
> real if statement.
>
> thanks,
>
> greg k-h
diff mbox series

Patch

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 61e3dd022..c204bdecc 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -960,7 +960,7 @@  static int uart_set_info(struct tty_struct *tty, struct tty_port *port,
 		uport->fifosize = new_info->xmit_fifo_size;
 
  check_and_exit:
-	retval = 0;
+	retval = retval < 0 ? retval : 0;
 	if (uport->type == PORT_UNKNOWN)
 		goto exit;
 	if (tty_port_initialized(port)) {