Re: [PATCH] serial: 8250: fix null-ptr-deref in serial8250_start_tx()

From: liwei (GF)
Date: Tue Jul 21 2020 - 22:03:29 EST


Hi Yingliang,

On 2020/7/21 22:38, Yang Yingliang wrote:
(SNIP)
>
> SERIAL_PORT_DFNS is not defined on each arch, if it's not defined,
> serial8250_set_defaults() won't be called in serial8250_isa_init_ports(),
> so the p->serial_in pointer won't be initialized, and it leads a null-ptr-deref.
> Fix this problem by calling serial8250_set_defaults() after init uart port.
>
> Signed-off-by: Yang Yingliang <yangyingliang@xxxxxxxxxx>
> ---
> drivers/tty/serial/8250/8250_core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
> index fc118f649887..cae61d1ebec5 100644
> --- a/drivers/tty/serial/8250/8250_core.c
> +++ b/drivers/tty/serial/8250/8250_core.c
> @@ -524,6 +524,7 @@ static void __init serial8250_isa_init_ports(void)
> */
> up->mcr_mask = ~ALPHA_KLUDGE_MCR;
> up->mcr_force = ALPHA_KLUDGE_MCR;
> + serial8250_set_defaults(up);

That is really a good catch, but this modification looks not good to me.

First, serial8250_set_defaults()'s parameter 'up' updated in the loop below is used to
lead to different branch in this function. So that the logic is broken.

Second, up->port.iobase and up->port.iotype are both initialized to 0, so the 'serial_in'
and 'serial_out' will be assigned to the ops for IO space with port 0 here, i don't think
that is correct.

> }
>
> /* chain base port ops to support Remote Supervisor Adapter */
> @@ -547,7 +548,6 @@ static void __init serial8250_isa_init_ports(void)
> port->membase = old_serial_port[i].iomem_base;
> port->iotype = old_serial_port[i].io_type;
> port->regshift = old_serial_port[i].iomem_reg_shift;
> - serial8250_set_defaults(up);
>
> port->irqflags |= irqflag;
> if (serial8250_isa_config != NULL)
>


Thanks,
Wei