From: Carolina Jubran <cjubran@nvidia.com>
To: Prathamesh Deshpande <prathameshdeshpande7@gmail.com>
Cc: leon@kernel.org, linux-kernel@vger.kernel.org,
linux-rdma@vger.kernel.org, mbloch@nvidia.com,
netdev@vger.kernel.org, richardcochran@gmail.com,
saeedm@nvidia.com, tariqt@nvidia.com
Subject: Re: [PATCH v2] net/mlx5: Fix OOB access and stack information leak in PTP event handling
Date: Thu, 9 Apr 2026 17:10:52 +0300 [thread overview]
Message-ID: <866743c9-020b-46a7-8fe2-46936a73b534@nvidia.com> (raw)
In-Reply-To: <20260402003047.24684-1-prathameshdeshpande7@gmail.com>
Hi Prathamesh, thanks for the patch!
On 02/04/2026 3:30, Prathamesh Deshpande wrote:
> In mlx5_pps_event(), several critical issues were identified during
> review by Sashiko:
>
> 1. The 'pin' index from the hardware event was used without bounds
> checking to index 'pin_config' and 'pps_info->start', leading to
> potential out-of-bounds memory access.
> 2. 'ptp_event' was not zero-initialized. Since it contains a union,
> assigning a timestamp partially leaves the 'ts_raw' field with
> uninitialized stack memory, which can leak kernel data or
> corrupt time sync logic in hardpps().
> 3. A NULL 'pin_config' could be dereferenced if initialization failed.
> 4. 'clock->ptp' could be NULL if ptp_clock_register() failed.
>
> Fix these by zero-initializing the event struct, adding a bounds
> check against MAX_PIN_NUM, and adding appropriate NULL guards.
>
> Fixes: 7c39afb394c7 ("net/mlx5: PTP code migration to driver core section")
>
> Signed-off-by: Prathamesh Deshpande <prathameshdeshpande7@gmail.com>
> ---
> v2:
> - Zero-initialize ptp_event to prevent stack information leak [Sashiko].
> - Add bounds check for hardware pin index to prevent OOB access [Sashiko].
> - Add NULL guard for pin_config to handle initialization failures [Sashiko].
> - Add NULL check for clock->ptp as originally intended.
>
> drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
> index bd4e042077af..a4d8c5c39abc 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
> @@ -1164,12 +1164,18 @@ static int mlx5_pps_event(struct notifier_block *nb,
> pps_nb);
> struct mlx5_core_dev *mdev = clock_state->mdev;
> struct mlx5_clock *clock = mdev->clock;
> - struct ptp_clock_event ptp_event;
> + struct ptp_clock_event ptp_event = {};
> struct mlx5_eqe *eqe = data;
> int pin = eqe->data.pps.pin;
> unsigned long flags;
> u64 ns;
>
> + if (!clock->ptp_info.pin_config)
> + return NOTIFY_OK;
> +
> + if (pin < 0 || pin >= MAX_PIN_NUM)
> + return NOTIFY_OK;
pin is defined as u8 in struct mlx5_eqe_pps, so pin < 0 is dead code.
As for the upper bound: in order to receive a PPS event on a pin, the
user must
first configure it via mlx5_ptp_enable, which already validates the index
(rq->extts.index >= clock->ptp_info.n_pins returns -EINVAL) and since
the mtpps
register only defines capabilities for 8 pins, so n_pins cannot exceed
MAX_PIN_NUM.
Maybe wrap it with WARN_ON_ONCE instead of silently returning, so if future
hardware adds support for more pins we would notice rather than silently
dropping
events.
> +
> switch (clock->ptp_info.pin_config[pin].func) {
> case PTP_PF_EXTTS:
> ptp_event.index = pin;
> @@ -1185,8 +1191,8 @@ static int mlx5_pps_event(struct notifier_block *nb,
> } else {
> ptp_event.type = PTP_CLOCK_EXTTS;
> }
> - /* TODOL clock->ptp can be NULL if ptp_clock_register fails */
> - ptp_clock_event(clock->ptp, &ptp_event);
> + if (clock->ptp)
> + ptp_clock_event(clock->ptp, &ptp_event);
> break;
> case PTP_PF_PEROUT:
> if (clock->shared) {
next prev parent reply other threads:[~2026-04-09 14:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 15:31 [PATCH] net/mlx5: Fix potential NULL dereference in PTP event handling Prathamesh Deshpande
2026-04-02 0:30 ` [PATCH v2] net/mlx5: Fix OOB access and stack information leak " Prathamesh Deshpande
2026-04-09 13:54 ` Carolina Jubran
2026-04-09 13:58 ` Carolina Jubran
2026-04-09 14:07 ` Carolina Jubran
2026-04-09 14:10 ` Carolina Jubran [this message]
2026-04-09 14:16 ` Carolina Jubran
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=866743c9-020b-46a7-8fe2-46936a73b534@nvidia.com \
--to=cjubran@nvidia.com \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mbloch@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=prathameshdeshpande7@gmail.com \
--cc=richardcochran@gmail.com \
--cc=saeedm@nvidia.com \
--cc=tariqt@nvidia.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