Skip to contentSkip to conversation

tty: serial: return appropriate error on failure

PATCH In review Vihas Mak 3 participants 4 messages Dec 7, 2021 – Dec 8, 2021 TTY layer and serial drivers

lore
Share & tools
lore

Vihas Mak

author
#0 lore raw

PATCH 1/1 tty: serial: return appropriate error on failure

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

---
 drivers/tty/serial/serial_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/serial_core.c +1 -1
index 61e3dd022..c204bdecc 100644
@@ -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)) {
Signature · 1 line
2.30.2
maintainer
#1 lore raw
Quoted 16 lines · Vihas Mak

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

---
  drivers/tty/serial/serial_core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/serial_core.c +0 -0
index 61e3dd022..c204bdecc 100644

drivers/tty/serial/serial_core.c static int uart_set_info(struct tty_struct *tty, struct tty_port *port, · line 963

Quoted 5 lines
drivers/tty/serial/serial_core.c +1 -1
@@ -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

Quoted 4 lines
drivers/tty/serial/serial_core.c +0 -0
  	if (uport->type == PORT_UNKNOWN)
  		goto exit;
  	if (tty_port_initialized(port)) {
Signature · 2 lines
js
suse labs
maintainer
#2 lore raw
In reply to Vihas Mak
Quoted 16 lines · Vihas Mak

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

---
 drivers/tty/serial/serial_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/serial_core.c +0 -0
index 61e3dd022..c204bdecc 100644

drivers/tty/serial/serial_core.c static int uart_set_info(struct tty_struct *tty, struct tty_port *port, · line 963

Quoted 5 lines
drivers/tty/serial/serial_core.c +1 -1
@@ -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

author
#3 lore raw
Quoted 2 lines
Quoted 2 lines

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

Quoted 30 lines · Greg KH
Quoted 16 lines · Vihas Mak

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

---
 drivers/tty/serial/serial_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/serial_core.c +0 -0
index 61e3dd022..c204bdecc 100644

drivers/tty/serial/serial_core.c static int uart_set_info(struct tty_struct *tty, struct tty_port *port, · line 963

Quoted 5 lines
drivers/tty/serial/serial_core.c +1 -1
@@ -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

Signature · 2 lines
Thanks,
Vihas