All of lore.kernel.org
 help / color / mirror / Atom feed
* stack leak via uart_get_info() ?
@ 2023-10-05 16:34 Alexey Dobriyan
  2023-10-05 17:55 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Alexey Dobriyan @ 2023-10-05 16:34 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby; +Cc: linux-serial, linux-kernel

If this check ever triggers

	static int uart_get_info(struct tty_port *port, struct serial_struct *retinfo)
	{

		uport = uart_port_check(state);
	        if (!uport)
	                goto out;

then all those sysfs users will print stack contents to userspace.

Can it trigger while sysfs read is executing?


Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -775,6 +775,8 @@ static int uart_get_info(struct tty_port *port, struct serial_struct *retinfo)
 	struct uart_port *uport;
 	int ret = -ENODEV;
 
+	*retinfo = (struct serial_struct){};
+
 	/*
 	 * Ensure the state we copy is consistent and no hardware changes
 	 * occur as we go

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

* Re: stack leak via uart_get_info() ?
  2023-10-05 16:34 stack leak via uart_get_info() ? Alexey Dobriyan
@ 2023-10-05 17:55 ` Greg Kroah-Hartman
  2023-10-05 18:44   ` Alexey Dobriyan
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2023-10-05 17:55 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: Jiri Slaby, linux-serial, linux-kernel

On Thu, Oct 05, 2023 at 07:34:21PM +0300, Alexey Dobriyan wrote:
> If this check ever triggers
> 
> 	static int uart_get_info(struct tty_port *port, struct serial_struct *retinfo)
> 	{
> 
> 		uport = uart_port_check(state);
> 	        if (!uport)
> 	                goto out;
> 
> then all those sysfs users will print stack contents to userspace.
> 
> Can it trigger while sysfs read is executing?

I don't think it can ever fail, we don't even check the result in other
places, so it should all be fine.

> Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
> ---
> 
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -775,6 +775,8 @@ static int uart_get_info(struct tty_port *port, struct serial_struct *retinfo)
>  	struct uart_port *uport;
>  	int ret = -ENODEV;
>  
> +	*retinfo = (struct serial_struct){};

This is good (although I hate the implied memcpy), a real memset would
be best to ensure that any holes are also filled.  Want to do that, or
want me to?

thanks,

greg k-h

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

* Re: stack leak via uart_get_info() ?
  2023-10-05 17:55 ` Greg Kroah-Hartman
@ 2023-10-05 18:44   ` Alexey Dobriyan
  0 siblings, 0 replies; 3+ messages in thread
From: Alexey Dobriyan @ 2023-10-05 18:44 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Jiri Slaby, linux-serial, linux-kernel

On Thu, Oct 05, 2023 at 07:55:34PM +0200, Greg Kroah-Hartman wrote:
> On Thu, Oct 05, 2023 at 07:34:21PM +0300, Alexey Dobriyan wrote:
> > If this check ever triggers
> > 
> > 	static int uart_get_info(struct tty_port *port, struct serial_struct *retinfo)
> > 	{
> > 
> > 		uport = uart_port_check(state);
> > 	        if (!uport)
> > 	                goto out;
> > 
> > then all those sysfs users will print stack contents to userspace.
> > 
> > Can it trigger while sysfs read is executing?
> 
> I don't think it can ever fail, we don't even check the result in other
> places, so it should all be fine.
> 
> > Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
> > ---
> > 
> > --- a/drivers/tty/serial/serial_core.c
> > +++ b/drivers/tty/serial/serial_core.c
> > @@ -775,6 +775,8 @@ static int uart_get_info(struct tty_port *port, struct serial_struct *retinfo)
> >  	struct uart_port *uport;
> >  	int ret = -ENODEV;
> >  
> > +	*retinfo = (struct serial_struct){};
> 
> This is good (although I hate the implied memcpy), a real memset would
> be best to ensure that any holes are also filled.  Want to do that, or
> want me to?

I don't mind memset(), but "struct serial_struct" structure has kernel
pointers:

	unsigned char* iomem_base;

so it is not shipped to userspace, so padding isn't an issue.

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

end of thread, other threads:[~2023-10-05 18:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-05 16:34 stack leak via uart_get_info() ? Alexey Dobriyan
2023-10-05 17:55 ` Greg Kroah-Hartman
2023-10-05 18:44   ` Alexey Dobriyan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.