mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] serial: 8250_pci1xxxx: off by one in pci1xxxx_process_read_data()
@ 2024-01-10 18:52 Dan Carpenter
  2024-01-10 19:11 ` Hugo Villeneuve
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2024-01-10 18:52 UTC (permalink / raw)
  To: Rengarajan S
  Cc: Kumaravel Thiagarajan, Tharun Kumar P, Greg Kroah-Hartman,
	Jiri Slaby, linux-serial, linux-kernel, kernel-janitors

These > comparisons should be >= to prevent writing one element beyond
the end of the rx_buff[] array.  The buffer has RX_BUF_SIZE[] elements.

Fixes: aba8290f368d ("8250: microchip: pci1xxxx: Add Burst mode reception support in uart driver for writing into FIFO")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
From static analysis, not testing.

 drivers/tty/serial/8250/8250_pci1xxxx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_pci1xxxx.c b/drivers/tty/serial/8250/8250_pci1xxxx.c
index 558c4c7f3104..cd258922bd78 100644
--- a/drivers/tty/serial/8250/8250_pci1xxxx.c
+++ b/drivers/tty/serial/8250/8250_pci1xxxx.c
@@ -302,7 +302,7 @@ static void pci1xxxx_process_read_data(struct uart_port *port,
 	 * to read, the data is received one byte at a time.
 	 */
 	while (valid_burst_count--) {
-		if (*buff_index > (RX_BUF_SIZE - UART_BURST_SIZE))
+		if (*buff_index >= (RX_BUF_SIZE - UART_BURST_SIZE))
 			break;
 		burst_buf = (u32 *)&rx_buff[*buff_index];
 		*burst_buf = readl(port->membase + UART_RX_BURST_FIFO);
@@ -311,7 +311,7 @@ static void pci1xxxx_process_read_data(struct uart_port *port,
 	}
 
 	while (*valid_byte_count) {
-		if (*buff_index > RX_BUF_SIZE)
+		if (*buff_index >= RX_BUF_SIZE)
 			break;
 		rx_buff[*buff_index] = readb(port->membase +
 					     UART_RX_BYTE_FIFO);
-- 
2.43.0


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

* Re: [PATCH] serial: 8250_pci1xxxx: off by one in pci1xxxx_process_read_data()
  2024-01-10 18:52 [PATCH] serial: 8250_pci1xxxx: off by one in pci1xxxx_process_read_data() Dan Carpenter
@ 2024-01-10 19:11 ` Hugo Villeneuve
  2024-01-10 19:19   ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Hugo Villeneuve @ 2024-01-10 19:11 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Rengarajan S, Kumaravel Thiagarajan, Tharun Kumar P,
	Greg Kroah-Hartman, Jiri Slaby, linux-serial, linux-kernel,
	kernel-janitors

On Wed, 10 Jan 2024 21:52:28 +0300
Dan Carpenter <dan.carpenter@linaro.org> wrote:

> These > comparisons should be >= to prevent writing one element beyond
> the end of the rx_buff[] array.  The buffer has RX_BUF_SIZE[] elements.

Hi,
your commit title message is very confusing and doesn't hint that this
is a bug fix (or a potential bug fix)...

Hugo Villeneuve


> 
> Fixes: aba8290f368d ("8250: microchip: pci1xxxx: Add Burst mode reception support in uart driver for writing into FIFO")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
> From static analysis, not testing.
> 
>  drivers/tty/serial/8250/8250_pci1xxxx.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_pci1xxxx.c b/drivers/tty/serial/8250/8250_pci1xxxx.c
> index 558c4c7f3104..cd258922bd78 100644
> --- a/drivers/tty/serial/8250/8250_pci1xxxx.c
> +++ b/drivers/tty/serial/8250/8250_pci1xxxx.c
> @@ -302,7 +302,7 @@ static void pci1xxxx_process_read_data(struct uart_port *port,
>  	 * to read, the data is received one byte at a time.
>  	 */
>  	while (valid_burst_count--) {
> -		if (*buff_index > (RX_BUF_SIZE - UART_BURST_SIZE))
> +		if (*buff_index >= (RX_BUF_SIZE - UART_BURST_SIZE))
>  			break;
>  		burst_buf = (u32 *)&rx_buff[*buff_index];
>  		*burst_buf = readl(port->membase + UART_RX_BURST_FIFO);
> @@ -311,7 +311,7 @@ static void pci1xxxx_process_read_data(struct uart_port *port,
>  	}
>  
>  	while (*valid_byte_count) {
> -		if (*buff_index > RX_BUF_SIZE)
> +		if (*buff_index >= RX_BUF_SIZE)
>  			break;
>  		rx_buff[*buff_index] = readb(port->membase +
>  					     UART_RX_BYTE_FIFO);
> -- 
> 2.43.0
> 
> 

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

* Re: [PATCH] serial: 8250_pci1xxxx: off by one in pci1xxxx_process_read_data()
  2024-01-10 19:11 ` Hugo Villeneuve
@ 2024-01-10 19:19   ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2024-01-10 19:19 UTC (permalink / raw)
  To: Hugo Villeneuve
  Cc: Rengarajan S, Kumaravel Thiagarajan, Tharun Kumar P,
	Greg Kroah-Hartman, Jiri Slaby, linux-serial, linux-kernel,
	kernel-janitors

On Wed, Jan 10, 2024 at 02:11:46PM -0500, Hugo Villeneuve wrote:
> On Wed, 10 Jan 2024 21:52:28 +0300
> Dan Carpenter <dan.carpenter@linaro.org> wrote:
> 
> > These > comparisons should be >= to prevent writing one element beyond
> > the end of the rx_buff[] array.  The buffer has RX_BUF_SIZE[] elements.
> 
> Hi,
> your commit title message is very confusing and doesn't hint that this
> is a bug fix (or a potential bug fix)...
> 

Most C programmers know what an "off by one" is...  But sure I can add
"fix" to the subject.  I debated either way, but left it off because the
subject was already too long.

regards,
dan carpenter


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

end of thread, other threads:[~2024-01-10 19:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-10 18:52 [PATCH] serial: 8250_pci1xxxx: off by one in pci1xxxx_process_read_data() Dan Carpenter
2024-01-10 19:11 ` Hugo Villeneuve
2024-01-10 19:19   ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®