mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] selftests: gpio: enable GPIO_CDEV_V1 for gpio-cdev-uaf
@ 2026-10-01  2:16 Danish Khateeb
  2026-10-01  2:16 ` [PATCH 2/2] selftests: gpio: expect gpio-mockup to reject a range with no lines Danish Khateeb
  0 siblings, 1 reply; 2+ messages in thread
From: Danish Khateeb @ 2026-10-01  2:16 UTC (permalink / raw)
  To: Bartosz Golaszewski, Linus Walleij
  Cc: Shuah Khan, Bamvor Jian Zhang, Tzung-Bi Shih, Samuel Moelius,
	linux-gpio, linux-kselftest, linux-kernel, Danish Khateeb

gpio-cdev-uaf.sh also tests linehandle and lineevent file descriptors,
which only exist with CONFIG_GPIO_CDEV_V1. Since commit 7673e4c7f7f9
("Do not enable the v1 uAPI by default") that option is off unless
asked for, and the gpio selftest config doesn't ask for it. Built with
that config, GPIO_GET_LINEHANDLE_IOCTL fails with EINVAL and the test
stops at its second step:

  # 2. linehandle
  # 2.1. ioctl
  # failed to get handle FD
  # failed to test handle ioctl
  # GPIO gpio-cdev-uaf test FAIL

Add the option to the config.

Fixes: c7f92042d3f3 ("selftests: gpio: Add gpio-cdev-uaf tests")
Assisted-by: LLM
Signed-off-by: Danish Khateeb <danishkhateeb03@gmail.com>
---

Notes:
    Tested on v7.3-rc5 (x86_64, KASAN and lockdep, virtme-ng) with a
    kernel config merged with tools/testing/selftests/gpio/config:
    - current config (GPIO_CDEV_V1 not set): gpio-cdev-uaf.sh fails at
      "2.1. ioctl" as above.
    - with this patch (GPIO_CDEV_V1=y is the only config change):
      gpio-cdev-uaf.sh passes, as does gpio-mockup.sh -t cdev_v1 (with
      2/2). No KASAN or lockdep reports.

 tools/testing/selftests/gpio/config | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/gpio/config b/tools/testing/selftests/gpio/config
index 1287abeaac7e..54cf6484441b 100644
--- a/tools/testing/selftests/gpio/config
+++ b/tools/testing/selftests/gpio/config
@@ -1,5 +1,6 @@
 CONFIG_GPIOLIB=y
 CONFIG_GPIO_CDEV=y
+CONFIG_GPIO_CDEV_V1=y
 CONFIG_GPIO_MOCKUP=m
 CONFIG_GPIO_SIM=m
 CONFIG_GPIO_AGGREGATOR=m
-- 
2.55.0


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

* [PATCH 2/2] selftests: gpio: expect gpio-mockup to reject a range with no lines
  2026-10-01  2:16 [PATCH 1/2] selftests: gpio: enable GPIO_CDEV_V1 for gpio-cdev-uaf Danish Khateeb
@ 2026-10-01  2:16 ` Danish Khateeb
  0 siblings, 0 replies; 2+ messages in thread
From: Danish Khateeb @ 2026-10-01  2:16 UTC (permalink / raw)
  To: Bartosz Golaszewski, Linus Walleij
  Cc: Shuah Khan, Bamvor Jian Zhang, Tzung-Bi Shih, Samuel Moelius,
	linux-gpio, linux-kselftest, linux-kernel, Danish Khateeb

Since commit 446e8c31d0fc ("gpio: mockup: reject invalid
gpio_mockup_ranges widths"), gpio-mockup refuses to load when a range
has no lines. The "no lines defined" case of gpio-mockup.sh still
expects gpio_mockup_ranges=0,0 to load and create no chip, so the test
now fails there:

  # 2.  Module load error tests
  # 2.1 no lines defined
  # test failed: insert gpio-mockup failed with error 1
  # GPIO gpio-mockup test FAIL

Check that the module rejects that range instead.

Fixes: 446e8c31d0fc ("gpio: mockup: reject invalid gpio_mockup_ranges widths")
Assisted-by: LLM
Signed-off-by: Danish Khateeb <danishkhateeb03@gmail.com>
---

Notes:
    Tested on v7.3-rc5 (x86_64, KASAN and lockdep, virtme-ng):
    - before: gpio-mockup.sh fails at 2.1, both by default and with -f.
    - after: it passes by default, with -f, and with -t cdev_v1 and
      -f -t cdev_v1 (on a GPIO_CDEV_V1=y kernel).
    - control: with "-1,32" in place of "0,0", the new check fails with
      "insert gpio-mockup with ranges <-1,32> did not fail".

 tools/testing/selftests/gpio/gpio-mockup.sh | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/gpio/gpio-mockup.sh b/tools/testing/selftests/gpio/gpio-mockup.sh
index fc2dd4c24d06..41c8a1c1502e 100755
--- a/tools/testing/selftests/gpio/gpio-mockup.sh
+++ b/tools/testing/selftests/gpio/gpio-mockup.sh
@@ -310,6 +310,16 @@ insmod_test()
 	remove_module || fail "failed to remove module with error $?"
 }
 
+# Load the module with the given ranges and check that it is rejected.
+insmod_fail_test()
+{
+	local ranges=$1
+
+	if modprobe -q $module "gpio_mockup_ranges=$ranges"; then
+		fail "insert $module with ranges <$ranges> did not fail"
+	fi
+}
+
 while getopts ":frvt:" opt; do
 	case $opt in
 	f)
@@ -378,7 +388,7 @@ if [ "$full_test" ]; then
 fi
 echo "2.  Module load error tests"
 echo "2.1 no lines defined"
-insmod_test "0,0"
+insmod_fail_test "0,0"
 if [ "$full_test" ]; then
 	echo "2.2 ignore range overlap"
 	insmod_test "0,32,0,1" 32
-- 
2.55.0


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

end of thread, other threads:[~2026-10-01  2:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-01  2:16 [PATCH 1/2] selftests: gpio: enable GPIO_CDEV_V1 for gpio-cdev-uaf Danish Khateeb
2026-10-01  2:16 ` [PATCH 2/2] selftests: gpio: expect gpio-mockup to reject a range with no lines Danish Khateeb

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

all inboxes | Powered by JetHome®