Linux Serial subsystem development
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@kernel.org>
To: Sherry Sun <sherry.sun@nxp.com>,
	gregkh@linuxfoundation.org, ilpo.jarvinen@linux.intel.com,
	shenwei.wang@nxp.com
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-imx@nxp.com
Subject: Re: [PATCH] tty: serial: fsl_lpuart: Fix possible integer overflow
Date: Tue, 18 Jul 2023 11:33:21 +0200	[thread overview]
Message-ID: <3652da4b-8ccf-34a8-bdb7-757a3109ac54@kernel.org> (raw)
In-Reply-To: <20230718065645.6588-1-sherry.sun@nxp.com>

On 18. 07. 23, 8:56, Sherry Sun wrote:
> This patch addresses the following Coverity report, fix it by casting
> sport->port.frame_time to type u64.
> 
> CID 32305660: Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)
> Potentially overflowing expression sport->port.frame_time * 8U with type
> unsigned int (32 bits, unsigned) is evaluated using 32-bit arithmetic,
> and then used in a context that expects an expression of type u64 (64
> bits, unsigned).
> 
> Fixes: cf9aa72d2f91 ("tty: serial: fsl_lpuart: optimize the timer based EOP logic")
> Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
> ---
>   drivers/tty/serial/fsl_lpuart.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
> index c1980ea52666..07b3b26732db 100644
> --- a/drivers/tty/serial/fsl_lpuart.c
> +++ b/drivers/tty/serial/fsl_lpuart.c
> @@ -1373,7 +1373,7 @@ static inline int lpuart_start_rx_dma(struct lpuart_port *sport)
>   
>   	sport->last_residue = 0;
>   	sport->dma_rx_timeout = max(nsecs_to_jiffies(
> -		sport->port.frame_time * DMA_RX_IDLE_CHARS), 1UL);
> +		(u64)sport->port.frame_time * DMA_RX_IDLE_CHARS), 1UL);

Can you explain how that can overflow? In the worst case (1 start bit, 8 
data bits, 2 stop bits, parity bit, address bit, 50 bauds), frame_time 
would contain:
13*1e9/50 = 260,000,000. (260 ms)

Then the multiplication above is:
260,000,000*8 = 2,080,000,000. (2 seconds)

which is still less than 2^32-1.

thanks,
-- 
js
suse labs


  reply	other threads:[~2023-07-18  9:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-18  6:56 [PATCH] tty: serial: fsl_lpuart: Fix possible integer overflow Sherry Sun
2023-07-18  9:33 ` Jiri Slaby [this message]
2023-07-18  9:56   ` Ilpo Järvinen
2023-07-18 11:03     ` Sherry Sun

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=3652da4b-8ccf-34a8-bdb7-757a3109ac54@kernel.org \
    --to=jirislaby@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=shenwei.wang@nxp.com \
    --cc=sherry.sun@nxp.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