Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ahmad Byagowi" <ahmadexp@gmail.com>
Cc: robh@kernel.org, conor+dt@kernel.org, linux-leds@vger.kernel.org,
	lee@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH net-next v5 4/7] ptp: ocp: Track EEPROM fields independently
Date: Sat, 15 Aug 2026 23:11:52 +0000	[thread overview]
Message-ID: <20260815231152.786EF1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <3186cc1f1c51b548439fda558e9e4052a481b787.1786747084.git.ahmadexp@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Kernel stack memory disclosure to userspace due to uninitialized buffer used with short reads.
- [Medium] The EEPROM discovery loop aborts on the first error, contradicting the commit's intent to track fields independently.
- [Medium] Internal `-EPROBE_DEFER` error code is leaked to userspace via the `serialnum_show` sysfs attribute.
--

--- Patch [4]: [PATCH net-next v5 4/7] ptp: ocp: Track EEPROM fields independently ---
commit c7acafdfcb181ccb357d00ccd6cff4bb48838592
Author: Ahmad Byagowi <ahmadexp@gmail.com>

ptp: ocp: Track EEPROM fields independently

This patch updates the EEPROM discovery logic to serialize reads and
track the availability of the board ID and serial number independently.
It aims to ensure that failure to read one field does not prevent the
discovery or publication of the other field.

> diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
> index 3d26ec1f7b9ec..31a4c9dfe391c 100644
> --- a/drivers/ptp/ptp_ocp.c
> +++ b/drivers/ptp/ptp_ocp.c
[ ... ]
> @@ -1969,21 +1977,50 @@ ptp_ocp_nvmem_device_put(struct nvmem_device **nvmemp)
>  	*nvmemp = NULL;
>  }
>  
> -static void
> -ptp_ocp_read_eeprom(struct ptp_ocp *bp)
> +static int
> +ptp_ocp_read_eeprom(struct ptp_ocp *bp, unsigned int fields)
>  {
>  	const struct ptp_ocp_eeprom_map *map;
>  	struct nvmem_device *nvmem;
> +	u8 data[OCP_BOARD_ID_LEN];
> +	const char *field_name = "data";
>  	const void *tag;
> -	int ret;
> -
> -	if (!bp->i2c_ctrl)
> -		return;
> +	unsigned int field;
> +	int ret = 0;
>  
>  	tag = NULL;
>  	nvmem = NULL;
[ ... ]
>  	for (map = bp->eeprom_map; map->len; map++) {
[ ... ]
> +		if (map->tag != tag) {
>  			tag = map->tag;
>  			ptp_ocp_nvmem_device_put(&nvmem);
> +		}
> +		if (!nvmem) {
>  			nvmem = ptp_ocp_nvmem_device_get(bp, tag);
>  			if (IS_ERR(nvmem)) {
>  				ret = PTR_ERR(nvmem);
> -				goto fail;
> +				goto out;

[Severity: Medium]
Since the commit message states the intent is to avoid hiding an otherwise
valid board ID when the serial EEPROM block is missing, does aborting the
loop here on the first error contradict that?

If nvmem_device_get() fails for the first entry in bp->eeprom_map, this
goto out will skip reading any subsequent entries.

>  			}
>  		}
> -		ret = nvmem_device_read(nvmem, map->off, map->len,
> -					BP_MAP_ENTRY_ADDR(bp, map));
> -		if (ret != map->len)
> -			goto fail;
> +		ret = nvmem_device_read(nvmem, map->off, map->len, data);
> +		if (ret < 0)
> +			goto out;

[Severity: Medium]
Similarly, if nvmem_device_read() fails for an entry, won't this goto out
also prevent subsequent fields from being discovered?

> +
> +		memcpy(BP_MAP_ENTRY_ADDR(bp, map), data, map->len);

[Severity: High]
Does this allow uninitialized stack memory to be copied to the persistent
device structure?

The data buffer is allocated uninitialized on the stack. If nvmem_device_read()
returns a short read (where 0 <= ret < map->len), the error check above
(ret < 0) will pass. The memcpy will then copy the entire map->len bytes,
including uninitialized kernel stack data, which could later be disclosed to
userspace via sysfs attributes like serialnum_show or the devlink interface.

> +		if (field == OCP_EEPROM_BOARD_ID) {
[ ... ]
> @@ -3757,9 +3805,17 @@ static ssize_t
>  serialnum_show(struct device *dev, struct device_attribute *attr, char *buf)
>  {
>  	struct ptp_ocp *bp = dev_get_drvdata(dev);
> +	int ret;
>  
> -	if (!bp->has_eeprom_data)
> -		ptp_ocp_read_eeprom(bp);
> +	/* Pairs with field publication in ptp_ocp_read_eeprom(). */
> +	if (!smp_load_acquire(&bp->has_serial)) {
> +		ret = ptp_ocp_read_eeprom(bp, OCP_EEPROM_SERIAL);
> +		if (ret)
> +			return ret;

[Severity: Medium]
Can this leak internal kernel error codes to userspace?

If nvmem_device_get() is not yet ready, ptp_ocp_read_eeprom() legitimately
returns -EPROBE_DEFER. Returning this directly from the sysfs show handler
will expose -EPROBE_DEFER (-517) to userspace applications, breaking the
POSIX ABI. Should this be translated to -ENODATA or -EAGAIN?

> +		/* Pairs with field publication in ptp_ocp_read_eeprom(). */
> +		if (!smp_load_acquire(&bp->has_serial))
> +			return -ENODATA;
> +	}
>  
>  	return sysfs_emit(buf, "%pM\n", bp->serial);
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1786746757.git.ahmadexp@gmail.com?part=4

  reply	other threads:[~2026-08-15 23:11 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-14 23:10 [PATCH net-next v5 0/7] ptp: ocp: Add R4006 and V9 I2C peripheral support Ahmad Byagowi
2026-08-14 23:10 ` [PATCH net-next v5 1/7] dt-bindings: leds: Add IS32FL3207 controller Ahmad Byagowi
2026-08-15 23:11   ` sashiko-bot
2026-08-14 23:10 ` [PATCH net-next v5 2/7] leds: is32fl3207: Add controller driver Ahmad Byagowi
2026-08-15 23:11   ` sashiko-bot
2026-08-14 23:10 ` [PATCH net-next v5 3/7] i2c: mux: Propagate software nodes to channel adapters Ahmad Byagowi
2026-08-15 23:11   ` sashiko-bot
2026-08-14 23:10 ` [PATCH net-next v5 4/7] ptp: ocp: Track EEPROM fields independently Ahmad Byagowi
2026-08-15 23:11   ` sashiko-bot [this message]
2026-08-14 23:10 ` [PATCH net-next v5 5/7] ptp: ocp: Add profile-driven I2C topology support Ahmad Byagowi
2026-08-15 23:11   ` sashiko-bot
2026-08-14 23:10 ` [PATCH net-next v5 6/7] ptp: ocp: Add R4006 I2C peripheral topology Ahmad Byagowi
2026-08-15 23:11   ` sashiko-bot
2026-08-14 23:10 ` [PATCH net-next v5 7/7] ptp: ocp: Add Time Card V9 " Ahmad Byagowi
2026-08-15 23:11   ` sashiko-bot

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=20260815231152.786EF1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ahmadexp@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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