]> www.infradead.org Git - users/sagi/blktests.git/commitdiff
nvme/046: add test for unprivileged passthrough
authorKanchan Joshi <joshi.k@samsung.com>
Thu, 9 Feb 2023 09:45:41 +0000 (15:15 +0530)
committerShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Tue, 28 Feb 2023 03:47:29 +0000 (12:47 +0900)
Alters permissions for char-device node (/dev/ngX) and runs few
passthrough commands as a normal user to exercise nvme_cmd_allowed().

Signed-off-by: Kanchan Joshi <joshi.k@samsung.com>
[Shin'ichiro: adjusted to normal user helper functions]
Tested-by: Kanchan Joshi <joshi.k@samsung.com>
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
tests/nvme/046 [new file with mode: 0755]
tests/nvme/046.out [new file with mode: 0644]

diff --git a/tests/nvme/046 b/tests/nvme/046
new file mode 100755 (executable)
index 0000000..b37b9e9
--- /dev/null
@@ -0,0 +1,51 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2023 Kanchan Joshi, Samsung Electronics
+# Test for unprivileged passthrough
+
+. tests/nvme/rc
+
+DESCRIPTION="basic test for unprivileged passthrough on /dev/ngX"
+QUICK=1
+
+requires() {
+       _nvme_requires
+       _require_normal_user
+       _have_kver 6 2
+}
+
+test_device() {
+       echo "Running ${TEST_NAME}"
+       local ngdev=${TEST_DEV/nvme/ng}
+       local perm nsid
+
+       perm="$(stat -c "%a" "$ngdev")"
+       nsid="$(_test_dev_nvme_nsid)"
+
+       chmod g+r,o+r "$ngdev"
+
+       if ! _run_user "nvme io-passthru ${ngdev} -o 2 -l 4096 \
+               -n $nsid -r" >> "${FULL}" 2>&1; then
+               echo "Error: io-passthru read failed"
+       fi
+
+       if _run_user "echo hello | nvme io-passthru ${ngdev} -o 1 -l 4096 \
+               -n $nsid -r" >> "${FULL}" 2>&1; then
+               echo "Error: io-passthru write passed (unexpected)"
+       fi
+
+       if ! _run_user "nvme id-ns ${ngdev}" >> "${FULL}" 2>&1; then
+               echo "Error: id-ns failed"
+       fi
+
+       if ! _run_user "nvme id-ctrl ${ngdev}" >> "${FULL}" 2>&1; then
+               echo "Error: id-ctrl failed"
+       fi
+
+       if _run_user "nvme ns-descs ${ngdev}" >> "${FULL}" 2>&1; then
+               echo "Error: ns-descs passed (unexpected)"
+       fi
+
+       echo "Test complete"
+       chmod "$perm" "$ngdev"
+}
diff --git a/tests/nvme/046.out b/tests/nvme/046.out
new file mode 100644 (file)
index 0000000..2b5fa6a
--- /dev/null
@@ -0,0 +1,2 @@
+Running nvme/046
+Test complete