All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] selftests: firmware: skip timeout checks for kernels without user mode helper
@ 2015-07-24 22:10 Luis R. Rodriguez
  2015-07-24 22:34 ` Kees Cook
  0 siblings, 1 reply; 2+ messages in thread
From: Luis R. Rodriguez @ 2015-07-24 22:10 UTC (permalink / raw)
  To: gregkh; +Cc: keescook, dhowells, linux-kernel, Luis R. Rodriguez

From: "Luis R. Rodriguez" <mcgrof@suse.com>

The CONFIG_FW_LOADER_USER_HELPER is mostly disabled these days, so skip
timeout setting for these kernels.

Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
---
 tools/testing/selftests/firmware/fw_filesystem.sh | 25 ++++++++++++++++++-----
 tools/testing/selftests/firmware/fw_userhelper.sh | 12 ++++++++++-
 2 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/firmware/fw_filesystem.sh b/tools/testing/selftests/firmware/fw_filesystem.sh
index 3fc6c10c2479..c4366dc74e01 100755
--- a/tools/testing/selftests/firmware/fw_filesystem.sh
+++ b/tools/testing/selftests/firmware/fw_filesystem.sh
@@ -9,7 +9,15 @@ modprobe test_firmware
 
 DIR=/sys/devices/virtual/misc/test_firmware
 
-OLD_TIMEOUT=$(cat /sys/class/firmware/timeout)
+# CONFIG_FW_LOADER_USER_HELPER has a sysfs class under /sys/class/firmware/
+# These days no one enables CONFIG_FW_LOADER_USER_HELPER so check for that
+# as an indicator for CONFIG_FW_LOADER_USER_HELPER.
+HAS_FW_LOADER_USER_HELPER=$(if [ -d /sys/class/firmware/ ]; then echo yes; else echo no; fi)
+
+if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
+	OLD_TIMEOUT=$(cat /sys/class/firmware/timeout)
+fi
+
 OLD_FWPATH=$(cat /sys/module/firmware_class/parameters/path)
 
 FWPATH=$(mktemp -d)
@@ -17,7 +25,9 @@ FW="$FWPATH/test-firmware.bin"
 
 test_finish()
 {
-	echo "$OLD_TIMEOUT" >/sys/class/firmware/timeout
+	if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
+		echo "$OLD_TIMEOUT" >/sys/class/firmware/timeout
+	fi
 	echo -n "$OLD_PATH" >/sys/module/firmware_class/parameters/path
 	rm -f "$FW"
 	rmdir "$FWPATH"
@@ -25,8 +35,11 @@ test_finish()
 
 trap "test_finish" EXIT
 
-# Turn down the timeout so failures don't take so long.
-echo 1 >/sys/class/firmware/timeout
+if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
+	# Turn down the timeout so failures don't take so long.
+	echo 1 >/sys/class/firmware/timeout
+fi
+
 # Set the kernel search path.
 echo -n "$FWPATH" >/sys/module/firmware_class/parameters/path
 
@@ -41,7 +54,9 @@ if diff -q "$FW" /dev/test_firmware >/dev/null ; then
 	echo "$0: firmware was not expected to match" >&2
 	exit 1
 else
-	echo "$0: timeout works"
+	if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
+		echo "$0: timeout works"
+	fi
 fi
 
 # This should succeed via kernel load or will fail after 1 second after
diff --git a/tools/testing/selftests/firmware/fw_userhelper.sh b/tools/testing/selftests/firmware/fw_userhelper.sh
index 6efbade12139..b9983f8e09f6 100755
--- a/tools/testing/selftests/firmware/fw_userhelper.sh
+++ b/tools/testing/selftests/firmware/fw_userhelper.sh
@@ -9,7 +9,17 @@ modprobe test_firmware
 
 DIR=/sys/devices/virtual/misc/test_firmware
 
-OLD_TIMEOUT=$(cat /sys/class/firmware/timeout)
+# CONFIG_FW_LOADER_USER_HELPER has a sysfs class under /sys/class/firmware/
+# These days no one enables CONFIG_FW_LOADER_USER_HELPER so check for that
+# as an indicator for CONFIG_FW_LOADER_USER_HELPER.
+HAS_FW_LOADER_USER_HELPER=$(if [ -d /sys/class/firmware/ ]; then echo yes; else echo no; fi)
+
+if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
+       OLD_TIMEOUT=$(cat /sys/class/firmware/timeout)
+else
+	echo "usermode helper disabled so ignoring test"
+	exit 0
+fi
 
 FWPATH=$(mktemp -d)
 FW="$FWPATH/test-firmware.bin"
-- 
2.3.2.209.gd67f9d5.dirty


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

* Re: [PATCH] selftests: firmware: skip timeout checks for kernels without user mode helper
  2015-07-24 22:10 [PATCH] selftests: firmware: skip timeout checks for kernels without user mode helper Luis R. Rodriguez
@ 2015-07-24 22:34 ` Kees Cook
  0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2015-07-24 22:34 UTC (permalink / raw)
  To: Luis R. Rodriguez; +Cc: Greg KH, David Howells, LKML, Luis R. Rodriguez

On Fri, Jul 24, 2015 at 3:10 PM, Luis R. Rodriguez
<mcgrof@do-not-panic.com> wrote:
> From: "Luis R. Rodriguez" <mcgrof@suse.com>
>
> The CONFIG_FW_LOADER_USER_HELPER is mostly disabled these days, so skip
> timeout setting for these kernels.
>
> Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
> ---
>  tools/testing/selftests/firmware/fw_filesystem.sh | 25 ++++++++++++++++++-----
>  tools/testing/selftests/firmware/fw_userhelper.sh | 12 ++++++++++-
>  2 files changed, 31 insertions(+), 6 deletions(-)
>
> diff --git a/tools/testing/selftests/firmware/fw_filesystem.sh b/tools/testing/selftests/firmware/fw_filesystem.sh
> index 3fc6c10c2479..c4366dc74e01 100755
> --- a/tools/testing/selftests/firmware/fw_filesystem.sh
> +++ b/tools/testing/selftests/firmware/fw_filesystem.sh
> @@ -9,7 +9,15 @@ modprobe test_firmware
>
>  DIR=/sys/devices/virtual/misc/test_firmware
>
> -OLD_TIMEOUT=$(cat /sys/class/firmware/timeout)
> +# CONFIG_FW_LOADER_USER_HELPER has a sysfs class under /sys/class/firmware/
> +# These days no one enables CONFIG_FW_LOADER_USER_HELPER so check for that
> +# as an indicator for CONFIG_FW_LOADER_USER_HELPER.
> +HAS_FW_LOADER_USER_HELPER=$(if [ -d /sys/class/firmware/ ]; then echo yes; else echo no; fi)
> +
> +if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
> +       OLD_TIMEOUT=$(cat /sys/class/firmware/timeout)
> +fi
> +
>  OLD_FWPATH=$(cat /sys/module/firmware_class/parameters/path)
>
>  FWPATH=$(mktemp -d)
> @@ -17,7 +25,9 @@ FW="$FWPATH/test-firmware.bin"
>
>  test_finish()
>  {
> -       echo "$OLD_TIMEOUT" >/sys/class/firmware/timeout
> +       if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
> +               echo "$OLD_TIMEOUT" >/sys/class/firmware/timeout
> +       fi
>         echo -n "$OLD_PATH" >/sys/module/firmware_class/parameters/path
>         rm -f "$FW"
>         rmdir "$FWPATH"
> @@ -25,8 +35,11 @@ test_finish()
>
>  trap "test_finish" EXIT
>
> -# Turn down the timeout so failures don't take so long.
> -echo 1 >/sys/class/firmware/timeout
> +if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
> +       # Turn down the timeout so failures don't take so long.
> +       echo 1 >/sys/class/firmware/timeout
> +fi
> +
>  # Set the kernel search path.
>  echo -n "$FWPATH" >/sys/module/firmware_class/parameters/path
>
> @@ -41,7 +54,9 @@ if diff -q "$FW" /dev/test_firmware >/dev/null ; then
>         echo "$0: firmware was not expected to match" >&2
>         exit 1
>  else
> -       echo "$0: timeout works"
> +       if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
> +               echo "$0: timeout works"
> +       fi
>  fi
>
>  # This should succeed via kernel load or will fail after 1 second after
> diff --git a/tools/testing/selftests/firmware/fw_userhelper.sh b/tools/testing/selftests/firmware/fw_userhelper.sh
> index 6efbade12139..b9983f8e09f6 100755
> --- a/tools/testing/selftests/firmware/fw_userhelper.sh
> +++ b/tools/testing/selftests/firmware/fw_userhelper.sh
> @@ -9,7 +9,17 @@ modprobe test_firmware
>
>  DIR=/sys/devices/virtual/misc/test_firmware
>
> -OLD_TIMEOUT=$(cat /sys/class/firmware/timeout)
> +# CONFIG_FW_LOADER_USER_HELPER has a sysfs class under /sys/class/firmware/
> +# These days no one enables CONFIG_FW_LOADER_USER_HELPER so check for that
> +# as an indicator for CONFIG_FW_LOADER_USER_HELPER.
> +HAS_FW_LOADER_USER_HELPER=$(if [ -d /sys/class/firmware/ ]; then echo yes; else echo no; fi)
> +
> +if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
> +       OLD_TIMEOUT=$(cat /sys/class/firmware/timeout)
> +else
> +       echo "usermode helper disabled so ignoring test"
> +       exit 0
> +fi
>
>  FWPATH=$(mktemp -d)
>  FW="$FWPATH/test-firmware.bin"
> --
> 2.3.2.209.gd67f9d5.dirty
>

This looks fine. We really need a general case for "XFAIL" style
output on tests. Until then:

Acked-by: Kees Cook <keescook@chromium.org>

-Kees


-- 
Kees Cook
Chrome OS Security

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

end of thread, other threads:[~2015-07-24 22:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-24 22:10 [PATCH] selftests: firmware: skip timeout checks for kernels without user mode helper Luis R. Rodriguez
2015-07-24 22:34 ` Kees Cook

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.