netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] ptp: Return -EINVAL on ptp_clock_register if required ops are NULL
@ 2025-10-30 18:08 Tim Hostetler
  2025-11-01  0:38 ` Jakub Kicinski
  2025-11-04 11:31 ` Vadim Fedorenko
  0 siblings, 2 replies; 4+ messages in thread
From: Tim Hostetler @ 2025-10-30 18:08 UTC (permalink / raw)
  To: netdev
  Cc: richardcochran, andrew+netdev, davem, edumazet, kuba, pabeni,
	linux-kernel, Tim Hostetler, stable, Kuniyuki Iwashima,
	Harshitha Ramamurthy

ptp_clock should never be registered unless it stubs one of gettimex64()
or gettime64() and settime64(). WARN_ON_ONCE and error out if either set
of function pointers is null.

Cc: stable@vger.kernel.org
Fixes: d7d38f5bd7be ("ptp: use the 64 bit get/set time methods for the posix clock.")
Suggested-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Harshitha Ramamurthy <hramamurthy@google.com>
Signed-off-by: Tim Hostetler <thostet@google.com>
---
 drivers/ptp/ptp_clock.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
index ef020599b771..0bc79076771b 100644
--- a/drivers/ptp/ptp_clock.c
+++ b/drivers/ptp/ptp_clock.c
@@ -325,6 +325,10 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
 	if (info->n_alarm > PTP_MAX_ALARMS)
 		return ERR_PTR(-EINVAL);
 
+	if (WARN_ON_ONCE((!info->gettimex64 && !info->gettime64) ||
+			 !info->settime64))
+		return ERR_PTR(-EINVAL);
+
 	/* Initialize a clock structure. */
 	ptp = kzalloc(sizeof(struct ptp_clock), GFP_KERNEL);
 	if (!ptp) {
-- 
2.51.1.851.g4ebd6896fd-goog


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

* Re: [PATCH net] ptp: Return -EINVAL on ptp_clock_register if required ops are NULL
  2025-10-30 18:08 [PATCH net] ptp: Return -EINVAL on ptp_clock_register if required ops are NULL Tim Hostetler
@ 2025-11-01  0:38 ` Jakub Kicinski
  2025-11-04 11:31 ` Vadim Fedorenko
  1 sibling, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2025-11-01  0:38 UTC (permalink / raw)
  To: Tim Hostetler
  Cc: netdev, richardcochran, andrew+netdev, davem, edumazet, pabeni,
	linux-kernel, stable, Kuniyuki Iwashima, Harshitha Ramamurthy

On Thu, 30 Oct 2025 11:08:32 -0700 Tim Hostetler wrote:
> ptp_clock should never be registered unless it stubs one of gettimex64()
> or gettime64() and settime64(). WARN_ON_ONCE and error out if either set
> of function pointers is null.
> 
> Cc: stable@vger.kernel.org
> Fixes: d7d38f5bd7be ("ptp: use the 64 bit get/set time methods for the posix clock.")

This needs to go to net-next without the tags above.
The check can only help with new drivers, old ones _must_ be fixed 
like gve was. Not registering a driver is a regression.

> Suggested-by: Kuniyuki Iwashima <kuniyu@google.com>
> Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
> Reviewed-by: Harshitha Ramamurthy <hramamurthy@google.com>
> Signed-off-by: Tim Hostetler <thostet@google.com>
> ---
>  drivers/ptp/ptp_clock.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
> index ef020599b771..0bc79076771b 100644
> --- a/drivers/ptp/ptp_clock.c
> +++ b/drivers/ptp/ptp_clock.c
> @@ -325,6 +325,10 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
>  	if (info->n_alarm > PTP_MAX_ALARMS)

->n_alarm check is also input validation, you should probably fold it
into your new WARN_ON_ONCE(). Either that or remove the WARN_ON_ONCE()
annotation below. As is the checks are inconsistent.

>  		return ERR_PTR(-EINVAL);
>  
> +	if (WARN_ON_ONCE((!info->gettimex64 && !info->gettime64) ||
> +			 !info->settime64))
> +		return ERR_PTR(-EINVAL);
> +

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

* Re: [PATCH net] ptp: Return -EINVAL on ptp_clock_register if required ops are NULL
  2025-10-30 18:08 [PATCH net] ptp: Return -EINVAL on ptp_clock_register if required ops are NULL Tim Hostetler
  2025-11-01  0:38 ` Jakub Kicinski
@ 2025-11-04 11:31 ` Vadim Fedorenko
  2025-11-04 17:47   ` Tim Hostetler
  1 sibling, 1 reply; 4+ messages in thread
From: Vadim Fedorenko @ 2025-11-04 11:31 UTC (permalink / raw)
  To: Tim Hostetler, netdev
  Cc: richardcochran, andrew+netdev, davem, edumazet, kuba, pabeni,
	linux-kernel, stable, Kuniyuki Iwashima, Harshitha Ramamurthy

On 30/10/2025 18:08, Tim Hostetler wrote:
> ptp_clock should never be registered unless it stubs one of gettimex64()
> or gettime64() and settime64(). WARN_ON_ONCE and error out if either set
> of function pointers is null.
> 
> Cc: stable@vger.kernel.org
> Fixes: d7d38f5bd7be ("ptp: use the 64 bit get/set time methods for the posix clock.")
> Suggested-by: Kuniyuki Iwashima <kuniyu@google.com>
> Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
> Reviewed-by: Harshitha Ramamurthy <hramamurthy@google.com>
> Signed-off-by: Tim Hostetler <thostet@google.com>
> ---
>   drivers/ptp/ptp_clock.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
> index ef020599b771..0bc79076771b 100644
> --- a/drivers/ptp/ptp_clock.c
> +++ b/drivers/ptp/ptp_clock.c
> @@ -325,6 +325,10 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
>   	if (info->n_alarm > PTP_MAX_ALARMS)
>   		return ERR_PTR(-EINVAL);
>   
> +	if (WARN_ON_ONCE((!info->gettimex64 && !info->gettime64) ||
> +			 !info->settime64))
> +		return ERR_PTR(-EINVAL);
> +
>   	/* Initialize a clock structure. */
>   	ptp = kzalloc(sizeof(struct ptp_clock), GFP_KERNEL);
>   	if (!ptp) {


The patch itself LGTM, but I believe it should be targeted to net-next,
as it doesn't actually fix any problem with GVE patches landed net tree
already.

Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>

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

* Re: [PATCH net] ptp: Return -EINVAL on ptp_clock_register if required ops are NULL
  2025-11-04 11:31 ` Vadim Fedorenko
@ 2025-11-04 17:47   ` Tim Hostetler
  0 siblings, 0 replies; 4+ messages in thread
From: Tim Hostetler @ 2025-11-04 17:47 UTC (permalink / raw)
  To: Vadim Fedorenko
  Cc: netdev, richardcochran, andrew+netdev, davem, edumazet, kuba,
	pabeni, linux-kernel, stable, Kuniyuki Iwashima,
	Harshitha Ramamurthy

On Tue, Nov 4, 2025 at 3:32 AM Vadim Fedorenko
<vadim.fedorenko@linux.dev> wrote:
>
> The patch itself LGTM, but I believe it should be targeted to net-next,
> as it doesn't actually fix any problem with GVE patches landed net tree
> already.
>
> Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>

Thanks Vadim and Jakub, I'll spin a v2 for net-next and fold all the
input validation into one WARN_ON_ONCE per Jakub's suggestion.

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

end of thread, other threads:[~2025-11-04 17:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-30 18:08 [PATCH net] ptp: Return -EINVAL on ptp_clock_register if required ops are NULL Tim Hostetler
2025-11-01  0:38 ` Jakub Kicinski
2025-11-04 11:31 ` Vadim Fedorenko
2025-11-04 17:47   ` Tim Hostetler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).