All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lin Tzu Yang" <rongh7426@gmail.com>
Cc: linux-gpio@vger.kernel.org
Subject: Re: [PATCH 2/2] selftests: gpio: add a test for gpio-virtuser
Date: Tue, 01 Dec 2026 14:39:21 +0000	[thread overview]
Message-ID: <sashiko-outbox-243501@kernel.org> (raw)
In-Reply-To: <20261201142703.900902-3-rongh7426@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] selftests: gpio: test 1.1 fails due to dev_name mismatch in
  gpio-virtuser
- [Medium] selftests: gpio: test 2.3 triggers 1-byte OOB write in
  key_show()
--

commit b7b1a25a7e497e2091e3d44b29aedb3593d4949c
Author: Lin Tzu Yang <rongh7426@gmail.com>

selftests: gpio: add a test for gpio-virtuser

This commit adds a selftest script for the gpio-virtuser driver using a
gpio-sim chip as the provider to exercise configfs and debugfs interfaces.

> diff --git a/tools/testing/selftests/gpio/gpio-virtuser.sh b/tools/testing/selftests/gpio/gpio-virtuser.sh
> new file mode 100755
> index 0000000000000..f5993904d302c
> --- /dev/null
> +++ b/tools/testing/selftests/gpio/gpio-virtuser.sh
> @@ -0,0 +1,420 @@

[ ... ]

> +echo "1.1. Lookup by chip label and offset"
> +vu_create_dev dev0
> +vu_add_entry dev0 foo 0 "gpio-virtuser-test" 3
> +test "$(cat "$CONFIGFS_VU_DIR/dev0/live")" = "0" || fail "consumer is live before enabling"
> +DEV_NAME=$(cat "$CONFIGFS_VU_DIR/dev0/dev_name")
> +vu_enable_dev dev0
> +test "$(cat "$CONFIGFS_VU_DIR/dev0/live")" = "1" || fail "consumer is not live"
> +test "$(cat "$CONFIGFS_VU_DIR/dev0/dev_name")" = "$DEV_NAME" || \
> +	fail "dev_name changed when the consumer was enabled"

[Severity: Medium]
Does this dev_name check depend on an unmerged fix to
gpio_virtuser_device_config_dev_name_show()?

In the current tree, gpio_virtuser_device_config_dev_name_show() formats
the pre-activation fallback name as "gpio-sim.%d" when dev->pdev is NULL,
whereas activating the device registers the platform device as
"gpio-virtuser.%d":

drivers/gpio/gpio-virtuser.c:gpio_virtuser_device_config_dev_name_show() {
    ...
	pdev = dev->pdev;
	if (pdev)
		return sprintf(page, "%s\n", dev_name(&pdev->dev));

	return sprintf(page, "gpio-sim.%d\n", dev->id);
}

As a result, DEV_NAME is "gpio-sim.0" before vu_enable_dev and
"gpio-virtuser.0" afterwards, causing test 1.1 to fail on every run.

[ ... ]

> +echo "2.3. A key of the maximum length reads back intact"
> +# A show that writes past the page for such a key is only caught by KASAN.
> +vu_create_dev dev0
> +mkdir -p "$ENTRY_DIR" || fail "Unable to create the lookup entry"
> +head -c 4095 /dev/zero | tr '\0' 'k' > "$ENTRY_DIR/key" || fail "long key rejected"
> +test "$(cat "$ENTRY_DIR/key" | wc -c)" -ge 4095 || fail "long key truncated"
> +test "$(cat "$ENTRY_DIR/key" | tr -d 'k\n' | wc -c)" = "0" || \
> +	fail "long key read back corrupted"
> +vu_remove_dev dev0

[Severity: Medium]
Does reading back a 4095-byte key here trigger a 1-byte slab-out-of-bounds
write in gpio_virtuser_lookup_entry_config_key_show()?

drivers/gpio/gpio-virtuser.c:gpio_virtuser_lookup_entry_config_key_show() {
    ...
	return sprintf(page, "%s\n", entry->key ?: "");
}

Configfs allocates a PAGE_SIZE (4096-byte on 4K-page kernels) read buffer
in fill_read_buffer(), so formatting a 4095-byte key plus a newline and
terminating NUL with sprintf() writes 4097 bytes and overflows the page by
1 byte unless gpio_virtuser_lookup_entry_config_key_show() is switched to
sysfs_emit() first.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201142703.900902-1-rongh7426@gmail.com?part=2

      reply	other threads:[~2026-12-01 14:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 14:27 [PATCH 0/2] gpio: virtuser: add a selftest Lin Tzu Yang
2026-12-01 14:27 ` [PATCH 1/2] Documentation: gpio: virtuser: list the accepted direction values Lin Tzu Yang
2026-12-01 14:27 ` [PATCH 2/2] selftests: gpio: add a test for gpio-virtuser Lin Tzu Yang
2026-12-01 14:39   ` sashiko-bot [this message]

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=sashiko-outbox-243501@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=rongh7426@gmail.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.