Linux Serial subsystem development
 help / color / mirror / Atom feed
From: Michal Simek <michal.simek@xilinx.com>
To: Geert Uytterhoeven <geert@linux-m68k.org>,
	Michal Simek <michal.simek@xilinx.com>
Cc: "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS"
	<devicetree@vger.kernel.org>, Barry Song <baohua@kernel.org>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Linux-Renesas <linux-renesas-soc@vger.kernel.org>,
	Vineet Gupta <vgupta@synopsys.com>,
	linux-serial@vger.kernel.org, Jiri Slaby <jslaby@suse.com>,
	arcml <linux-snps-arc@lists.infradead.org>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 9/9] serial: xuartps: Fix out-of-bounds access through DT alias
Date: Tue, 20 Feb 2018 12:27:28 +0100	[thread overview]
Message-ID: <6cabf7c6-302e-efa9-8f4d-25fd35ecddad@xilinx.com> (raw)
In-Reply-To: <CAMuHMdUOKMM5mSrnnrxCi0gX_TbjYkj7vwn11b2D5p7XigM+Ag@mail.gmail.com>

On 20.2.2018 11:38, Geert Uytterhoeven wrote:
> Hi Michal,
> 
> On Tue, Feb 20, 2018 at 11:22 AM, Michal Simek <michal.simek@xilinx.com> wrote:
>> On 20.2.2018 10:40, Geert Uytterhoeven wrote:
>>> The cdns_uart_port[] array is indexed using a value derived from the
>>> "serialN" alias in DT, which may lead to an out-of-bounds access.
>>>
>>> Fix this by adding a range check.
>>>
>>> Fixes: 1f118c02a1819856 ("serial: xuartps: Fix out-of-bounds access through DT alias")
>>
>> I didn't find this sha1 - patch name is this one.
> 
> Bummer, I totally screwed up my scripting...
> 
> Fixes: 928e9263492069ee ("tty: xuartps: Initialize ports according to aliases")
> 
>>> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
>>> ---
>>>  drivers/tty/serial/xilinx_uartps.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c
>>> index b9b2bc76bcac606c..abcb4d09a2d866d0 100644
>>> --- a/drivers/tty/serial/xilinx_uartps.c
>>> +++ b/drivers/tty/serial/xilinx_uartps.c
>>> @@ -1110,7 +1110,7 @@ static struct uart_port *cdns_uart_get_port(int id)
>>>       struct uart_port *port;
>>>
>>>       /* Try the given port id if failed use default method */
>>> -     if (cdns_uart_port[id].mapbase != 0) {
>>> +     if (id < CDNS_UART_NR_PORTS && cdns_uart_port[id].mapbase != 0) {
>>>               /* Find the next unused port */
>>>               for (id = 0; id < CDNS_UART_NR_PORTS; id++)
>>>                       if (cdns_uart_port[id].mapbase == 0)
>>>
>>
>> Below should be better fix for this driver.
> 
> I considered that, too, but...
> 
>> --- a/drivers/tty/serial/xilinx_uartps.c
>> +++ b/drivers/tty/serial/xilinx_uartps.c
>> @@ -1109,6 +1109,9 @@ static struct uart_port *cdns_uart_get_port(int id)
>>  {
>>         struct uart_port *port;
>>
>> +       if (id >= CDNS_UART_NR_PORTS)
>> +               return NULL;
>> +
>>         /* Try the given port id if failed use default method */
>>         if (cdns_uart_port[id].mapbase != 0) {
>>                 /* Find the next unused port */
>> @@ -1117,9 +1120,6 @@ static struct uart_port *cdns_uart_get_port(int id)
>>                                 break;
>>         }
>>
>> -       if (id >= CDNS_UART_NR_PORTS)
>> -               return NULL;
>> -
> 
> ... the above check cannot be removed, as it is needed to support the loop
> above to find an unused port.

You are right.
I have checked 4 patches I have sent in past which didn't reach mainline
(probably because of RFC)
Take a look at
https://www.spinics.net/lists/linux-serial/msg27106.html

I have removed cdns_uart_port array completely there.

Thanks,
Michal

  reply	other threads:[~2018-02-20 11:27 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-20  9:40 [PATCH 0/9] serial: Fix out-of-bounds accesses through DT aliases Geert Uytterhoeven
2018-02-20  9:40 ` [PATCH 1/9] serial: arc_uart: Fix out-of-bounds access through DT alias Geert Uytterhoeven
2018-02-20 10:50   ` Geert Uytterhoeven
2018-02-20  9:40 ` [PATCH 2/9] serial: fsl_lpuart: " Geert Uytterhoeven
2018-02-20 10:51   ` Geert Uytterhoeven
2018-02-20  9:40 ` [PATCH 3/9] serial: imx: " Geert Uytterhoeven
2018-02-20 10:31   ` Uwe Kleine-König
2018-02-20 10:49     ` Geert Uytterhoeven
2018-02-20  9:40 ` [PATCH 4/9] serial: mxs-auart: " Geert Uytterhoeven
2018-02-20 10:51   ` Geert Uytterhoeven
2018-02-20  9:40 ` [PATCH 5/9] serial: pxa: " Geert Uytterhoeven
2018-02-20 10:52   ` Geert Uytterhoeven
2018-02-20  9:40 ` [PATCH 6/9] serial: samsung: " Geert Uytterhoeven
2018-02-20 10:52   ` Geert Uytterhoeven
2018-02-20  9:40 ` [PATCH 7/9] serial: sh-sci: " Geert Uytterhoeven
2018-02-20 10:53   ` Geert Uytterhoeven
2018-02-20  9:40 ` [PATCH 8/9] serial: sirf: " Geert Uytterhoeven
2018-02-20 10:53   ` Geert Uytterhoeven
2018-02-20  9:40 ` [PATCH 9/9] serial: xuartps: " Geert Uytterhoeven
2018-02-20 10:22   ` Michal Simek
2018-02-20 10:38     ` Geert Uytterhoeven
2018-02-20 11:27       ` Michal Simek [this message]
2018-02-20 12:27         ` Geert Uytterhoeven
2018-02-20 12:39           ` Michal Simek

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=6cabf7c6-302e-efa9-8f4d-25fd35ecddad@xilinx.com \
    --to=michal.simek@xilinx.com \
    --cc=baohua@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=geert+renesas@glider.be \
    --cc=geert@linux-m68k.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=linux-snps-arc@lists.infradead.org \
    --cc=vgupta@synopsys.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