mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Arnd Bergmann" <arnd@arndb.de>
To: "Linmao Li" <lilinmao@kylinos.cn>,
	"Sudip Mukherjee" <sudipm.mukherjee@gmail.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ppdev: prevent overflow when setting port timeout
Date: Thu, 16 Jul 2026 08:33:47 +0200	[thread overview]
Message-ID: <3da6045d-de5e-4d8c-8a78-c22d89f7c8d1@app.fastmail.com> (raw)
In-Reply-To: <20260716013923.19494-1-lilinmao@kylinos.cn>

On Thu, Jul 16, 2026, at 03:39, Linmao Li wrote:
> PPSETTIME64 supplies the timeval fields as s64 values, but
> pp_set_timeout() narrows tv_usec to int and calculates tv_sec * HZ in a
> signed long. Large positive values can therefore be truncated or overflow
> and install an unintended timeout.
>
> Keep both fields as s64, reject a non-canonical microsecond value, and
> use timespec64_to_jiffies() to cap excessively large timeouts at
> MAX_JIFFY_OFFSET. This is a behavior change because both PPSETTIME
> ioctls could previously accept values with tv_usec >= USEC_PER_SEC.
> The validation follows the precedent set by sock_set_timeout().
>
> Fixes: 3b9ab374a1e6 ("ppdev: convert to y2038 safe")
> Signed-off-by: Linmao Li <lilinmao@kylinos.cn>

Good catch!

> -	to_jiffies = usecs_to_jiffies(tv_usec);
> -	to_jiffies += tv_sec * HZ;
> +	ts.tv_sec = tv_sec;
> +	ts.tv_nsec = tv_usec * NSEC_PER_USEC;
> +	to_jiffies = timespec64_to_jiffies(&ts);
>  	if (to_jiffies <= 0)
>  		return -EINVAL;

This is a bit more expensive, but it's clearly not performance
critical and I agree that the added range checking is a
nice improvement here.

I also checked codesearch.debian.net to see if any callers
might rely on passing out-of-range arguments, but the only
caller I found (pyparallel) is guaranteed to pass a
normalized timeval.

Reviewed-by: Arnd Bergmann <arnd@arndb.de>

      reply	other threads:[~2026-07-16  6:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-16  1:39 Linmao Li
2026-07-16  6:33 ` Arnd Bergmann [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=3da6045d-de5e-4d8c-8a78-c22d89f7c8d1@app.fastmail.com \
    --to=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=lilinmao@kylinos.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sudipm.mukherjee@gmail.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

all inboxes | Powered by JetHome®