From: Qingfang Deng <qingfang.deng@linux.dev>
To: Eric Dumazet <edumazet@google.com>,
"David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>,
Andrew Lunn <andrew+netdev@lunn.ch>,
netdev@vger.kernel.org, eric.dumazet@gmail.com,
linux-ppp@vger.kernel.org
Subject: Re: [PATCH net] ppp: annotate data races in ppp_generic
Date: Thu, 23 Jul 2026 14:24:00 +0800 [thread overview]
Message-ID: <b16aec0f-a90f-4132-820e-239ddadbe8f0@linux.dev> (raw)
In-Reply-To: <20260722101605.2868548-1-edumazet@google.com>
Hi,
On 2026/7/22 18:16, Eric Dumazet wrote:
> diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
> index ef54e0a0462a175bb989db8dda895e9ae755965f..cacc4c3a37d2cda0aea2e176e5d0638f959e18a3 100644
> --- a/drivers/net/ppp/ppp_generic.c
> +++ b/drivers/net/ppp/ppp_generic.c
> @@ -866,16 +870,16 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
> break;
>
> case PPPIOCGIDLE32:
> - idle32.xmit_idle = (jiffies - ppp->last_xmit) / HZ;
> - idle32.recv_idle = (jiffies - ppp->last_recv) / HZ;
> - if (copy_to_user(argp, &idle32, sizeof(idle32)))
> + idle32.xmit_idle = max(0L, (long)(jiffies - READ_ONCE(ppp->last_xmit))) / HZ;
> + idle32.recv_idle = max(0L, (long)(jiffies - READ_ONCE(ppp->last_recv))) / HZ;
In the original code, the difference will wrap around on a 32-bit kernel
with HZ=1000 if the session sits idle for 4,294,967.295 seconds
(approximately 49.7 days). With this change, as the difference is cast
to a long, it will be negative after 2,147,483.647 seconds
(approximately 24.9 days) and then clamped to zero by max(), making the
situation worse.
> + if (copy_to_user(argp, &idle32, sizeof(idle32)))
> break;
> err = 0;
> break;
>
> case PPPIOCGIDLE64:
> - idle64.xmit_idle = (jiffies - ppp->last_xmit) / HZ;
> - idle64.recv_idle = (jiffies - ppp->last_recv) / HZ;
> + idle64.xmit_idle = max(0L, (long)(jiffies - READ_ONCE(ppp->last_xmit))) / HZ;
> + idle64.recv_idle = max(0L, (long)(jiffies - READ_ONCE(ppp->last_recv))) / HZ;
> if (copy_to_user(argp, &idle64, sizeof(idle64)))
> break;
> err = 0;
next prev parent reply other threads:[~2026-07-23 6:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-22 10:16 [PATCH net] ppp: annotate data races in ppp_generic Eric Dumazet
2026-07-23 6:24 ` Qingfang Deng [this message]
2026-07-23 6:48 ` Eric Dumazet
2026-07-23 7:21 ` Qingfang Deng
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=b16aec0f-a90f-4132-820e-239ddadbe8f0@linux.dev \
--to=qingfang.deng@linux.dev \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=eric.dumazet@gmail.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-ppp@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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