USB: serial: debug: do not echo input by default

commit 00af4f3dda upstream.

This driver is intended as a "client" end of the console connection.
When connected to a host it's supposed to receive debug logs, and
possibly allow to interact with whatever debug console is available
there. Feeding messages back, depending on a configuration may cause log
messages be executed as shell commands (which can be really bad if one
is unlucky, imagine a log message like "prevented running `rm -rf
/home`"). In case of Xen, it exposes sysrq-like debug interface, and
feeding it its own logs will pretty quickly hit 'R' for "instant
reboot".

Contrary to a classic serial console, the USB one cannot be configured
ahead of time, as the device shows up only when target OS is up. And at
the time device is opened to execute relevant ioctl, it's already too
late, especially when logs start flowing shortly after device is
initialized.
Avoid the issue by changing default to no echo for this type of devices.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
[ johan: amend summary; disable also ECHONL ]
Cc: stable@vger.kernel.org
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Marek Marczykowski-Górecki 2024-07-15 12:44:53 +02:00 committed by Greg Kroah-Hartman
parent 128e82e41c
commit 0761ba080a

View File

@ -76,6 +76,11 @@ static void usb_debug_process_read_urb(struct urb *urb)
usb_serial_generic_process_read_urb(urb); usb_serial_generic_process_read_urb(urb);
} }
static void usb_debug_init_termios(struct tty_struct *tty)
{
tty->termios.c_lflag &= ~(ECHO | ECHONL);
}
static struct usb_serial_driver debug_device = { static struct usb_serial_driver debug_device = {
.driver = { .driver = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
@ -85,6 +90,7 @@ static struct usb_serial_driver debug_device = {
.num_ports = 1, .num_ports = 1,
.bulk_out_size = USB_DEBUG_MAX_PACKET_SIZE, .bulk_out_size = USB_DEBUG_MAX_PACKET_SIZE,
.break_ctl = usb_debug_break_ctl, .break_ctl = usb_debug_break_ctl,
.init_termios = usb_debug_init_termios,
.process_read_urb = usb_debug_process_read_urb, .process_read_urb = usb_debug_process_read_urb,
}; };
@ -96,6 +102,7 @@ static struct usb_serial_driver dbc_device = {
.id_table = dbc_id_table, .id_table = dbc_id_table,
.num_ports = 1, .num_ports = 1,
.break_ctl = usb_debug_break_ctl, .break_ctl = usb_debug_break_ctl,
.init_termios = usb_debug_init_termios,
.process_read_urb = usb_debug_process_read_urb, .process_read_urb = usb_debug_process_read_urb,
}; };