linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "liwei (GF)" <liwei391@huawei.com>
To: Yang Yingliang <yangyingliang@huawei.com>, <gregkh@linuxfoundation.org>
Cc: <jslaby@suse.com>, LKML <linux-kernel@vger.kernel.org>,
	<linux-serial@vger.kernel.org>
Subject: Re: [PATCH] serial: 8250: fix null-ptr-deref in serial8250_start_tx()
Date: Wed, 22 Jul 2020 09:56:38 +0800	[thread overview]
Message-ID: <c56e0ecc-275c-2cd6-4f9b-8ae37656ab5b@huawei.com> (raw)
In-Reply-To: <20200721143852.4058352-1-yangyingliang@huawei.com>

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@huawei.com>
> ---
>  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

      parent reply	other threads:[~2020-07-22  2:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-21 14:38 [PATCH] serial: 8250: fix null-ptr-deref in serial8250_start_tx() Yang Yingliang
2020-07-21 10:48 ` Greg KH
2020-07-21 11:54   ` Yang Yingliang
2020-07-21 12:18     ` Yang Yingliang
2020-07-21 19:11       ` Greg KH
2020-07-22  1:56 ` liwei (GF) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c56e0ecc-275c-2cd6-4f9b-8ae37656ab5b@huawei.com \
    --to=liwei391@huawei.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=yangyingliang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).