The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH net v3] ptp: ocp: Fix board ID over-read
@ 2026-08-04 21:07 Ahmad Byagowi
  2026-08-04 21:18 ` Vadim Fedorenko
  2026-08-06 16:20 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Byagowi @ 2026-08-04 21:07 UTC (permalink / raw)
  To: netdev
  Cc: Richard Cochran, Vadim Fedorenko, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, linux-kernel, stable

The EEPROM board ID is a fixed 13-byte field and is not guaranteed to
contain a NUL terminator. Passing it directly to
devlink_info_version_fixed_put() treats it as a C string and may read
beyond the field.

Format at most OCP_BOARD_ID_LEN bytes into the existing local buffer
before reporting the ID. Use a precision limit because the snprintf()
output size alone does not bound the source string scan.

Fixes: 0cfcdd1ebcfe ("ptp: ocp: add nvmem interface for accessing eeprom")
Cc: stable@vger.kernel.org
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
Changes since RFC v2:
- Split the safety fix from the net-next feature series and target net.
- Use the short Fixes hash.
- Reuse the existing devlink info buffer and bound the source scan with
  string precision.
- Limit the change to the board ID over-read.

RFC v2:
https://lore.kernel.org/r/20260803205011.1249-5-ahmadexp@gmail.com/

 drivers/ptp/ptp_ocp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 35e911f1ad78c..3d26ec1f7b9ec 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -2177,9 +2177,11 @@ ptp_ocp_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req,
 	if (err)
 		return err;
 
+	snprintf(buf, sizeof(buf), "%.*s", OCP_BOARD_ID_LEN,
+		 (const char *)bp->board_id);
 	err = devlink_info_version_fixed_put(req,
 			DEVLINK_INFO_VERSION_GENERIC_BOARD_ID,
-			bp->board_id);
+			buf);
 	if (err)
 		return err;
 
-- 
2.50.1 (Apple Git-155)

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

* Re: [PATCH net v3] ptp: ocp: Fix board ID over-read
  2026-08-04 21:07 [PATCH net v3] ptp: ocp: Fix board ID over-read Ahmad Byagowi
@ 2026-08-04 21:18 ` Vadim Fedorenko
  2026-08-06 16:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Vadim Fedorenko @ 2026-08-04 21:18 UTC (permalink / raw)
  To: Ahmad Byagowi, netdev
  Cc: Richard Cochran, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, linux-kernel, stable

On 04.08.2026 22:07, Ahmad Byagowi wrote:
> The EEPROM board ID is a fixed 13-byte field and is not guaranteed to
> contain a NUL terminator. Passing it directly to
> devlink_info_version_fixed_put() treats it as a C string and may read
> beyond the field.
> 
> Format at most OCP_BOARD_ID_LEN bytes into the existing local buffer
> before reporting the ID. Use a precision limit because the snprintf()
> output size alone does not bound the source string scan.
> 
> Fixes: 0cfcdd1ebcfe ("ptp: ocp: add nvmem interface for accessing eeprom")
> Cc: stable@vger.kernel.org
> Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
> ---
> Changes since RFC v2:
> - Split the safety fix from the net-next feature series and target net.
> - Use the short Fixes hash.
> - Reuse the existing devlink info buffer and bound the source scan with
>    string precision.
> - Limit the change to the board ID over-read.
> 
> RFC v2:
> https://lore.kernel.org/r/20260803205011.1249-5-ahmadexp@gmail.com/
> 
>   drivers/ptp/ptp_ocp.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
> index 35e911f1ad78c..3d26ec1f7b9ec 100644
> --- a/drivers/ptp/ptp_ocp.c
> +++ b/drivers/ptp/ptp_ocp.c
> @@ -2177,9 +2177,11 @@ ptp_ocp_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req,
>   	if (err)
>   		return err;
>   
> +	snprintf(buf, sizeof(buf), "%.*s", OCP_BOARD_ID_LEN,
> +		 (const char *)bp->board_id);
>   	err = devlink_info_version_fixed_put(req,
>   			DEVLINK_INFO_VERSION_GENERIC_BOARD_ID,
> -			bp->board_id);
> +			buf);
>   	if (err)
>   		return err;
>   
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>

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

* Re: [PATCH net v3] ptp: ocp: Fix board ID over-read
  2026-08-04 21:07 [PATCH net v3] ptp: ocp: Fix board ID over-read Ahmad Byagowi
  2026-08-04 21:18 ` Vadim Fedorenko
@ 2026-08-06 16:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-08-06 16:20 UTC (permalink / raw)
  To: Ahmad Byagowi
  Cc: netdev, richardcochran, vadim.fedorenko, andrew+netdev, davem,
	edumazet, kuba, pabeni, linux-kernel, stable

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue,  4 Aug 2026 14:07:51 -0700 you wrote:
> The EEPROM board ID is a fixed 13-byte field and is not guaranteed to
> contain a NUL terminator. Passing it directly to
> devlink_info_version_fixed_put() treats it as a C string and may read
> beyond the field.
> 
> Format at most OCP_BOARD_ID_LEN bytes into the existing local buffer
> before reporting the ID. Use a precision limit because the snprintf()
> output size alone does not bound the source string scan.
> 
> [...]

Here is the summary with links:
  - [net,v3] ptp: ocp: Fix board ID over-read
    https://git.kernel.org/netdev/net/c/6b69f2ef10cd

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2026-08-06 16:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-04 21:07 [PATCH net v3] ptp: ocp: Fix board ID over-read Ahmad Byagowi
2026-08-04 21:18 ` Vadim Fedorenko
2026-08-06 16:20 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox