This adds tests for the new "fd" interface to the firmware selftests. Signed-off-by: Kees Cook <keescook@xxxxxxxxxxxx> --- tools/testing/selftests/firmware/fw_userhelper.sh | 34 ++++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/firmware/fw_userhelper.sh b/tools/testing/selftests/firmware/fw_userhelper.sh index 6efbade12139..e2766613e5b5 100644 --- a/tools/testing/selftests/firmware/fw_userhelper.sh +++ b/tools/testing/selftests/firmware/fw_userhelper.sh @@ -25,6 +25,7 @@ load_fw() { local name="$1" local file="$2" + local fd="$3" # This will block until our load (below) has finished. echo -n "$name" >"$DIR"/trigger_request & @@ -40,9 +41,16 @@ load_fw() fi done - echo 1 >"$DIR"/"$name"/loading - cat "$file" >"$DIR"/"$name"/data - echo 0 >"$DIR"/"$name"/loading + if [ -z "$fd" ]; then + echo 1 >"$DIR"/"$name"/loading + cat "$file" >"$DIR"/"$name"/data + echo 0 >"$DIR"/"$name"/loading + else + if ! echo "$fd" <"$file" >"$DIR"/"$name"/fd 2>/dev/null ; then + # If the echo fails, abort to avoid timeout. + echo -1 > "$DIR"/"$name"/loading + fi + fi # Wait for request to finish. wait @@ -83,7 +91,25 @@ if ! diff -q "$FW" /dev/test_firmware >/dev/null ; then echo "$0: firmware was not loaded" >&2 exit 1 else - echo "$0: user helper firmware loading works" + echo "$0: user helper firmware via 'loading' works" +fi + +# Request a bad file descriptor, expected to fail. +load_fw "$NAME" "$FW" 100 +if diff -q "$FW" /dev/test_firmware >/dev/null ; then + echo "$0: firmware was not expected to match" >&2 + exit 1 +else + echo "$0: bad file descriptor correctly fails" +fi + +# Request with the correct file descriptor. +load_fw "$NAME" "$FW" 0 +if ! diff -q "$FW" /dev/test_firmware >/dev/null ; then + echo "$0: failed to load with good fd" >&2 + exit 1 +else + echo "$0: user helper firmware via 'fd' works" fi exit 0 -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-doc" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html