[PATCH blktests] nvme/046: add test for unprivileged passthrough
Kanchan Joshi
joshi.k at samsung.com
Thu Feb 9 01:45:41 PST 2023
Ths creates a non-root user "blktest46", alters permissions for
char-device node (/dev/ngX) and runs few passthrough commands.
At the end of the test, user is deleted and permissions are reverted.
Signed-off-by: Kanchan Joshi <joshi.k at samsung.com>
---
tests/nvme/046 | 55 ++++++++++++++++++++++++++++++++++++++++++++++
tests/nvme/046.out | 2 ++
2 files changed, 57 insertions(+)
create mode 100644 tests/nvme/046
create mode 100644 tests/nvme/046.out
diff --git a/tests/nvme/046 b/tests/nvme/046
new file mode 100644
index 0000000..40bda62
--- /dev/null
+++ b/tests/nvme/046
@@ -0,0 +1,55 @@
+#!/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
+ _have_fio
+}
+
+device_requires() {
+ _require_test_dev_is_nvme
+}
+
+test_device() {
+ echo "Running ${TEST_NAME}"
+ local ngdev=${TEST_DEV/nvme/ng}
+ local usr="blktest46"
+ local perm=$(stat -c "%a" $ngdev)
+ local nsid=$(_test_dev_nvme_nsid)
+
+ useradd -m $usr
+ chmod g+r,o+r "$ngdev"
+
+ if ! su $usr -c "nvme io-passthru ${ngdev} -o 2 -l 4096 \
+ -n $nsid -r" >> "${FULL}" 2>&1; then
+ echo "Error: io-passthru read failed"
+ fi
+
+ if su $usr -c "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 ! su $usr -c "nvme id-ns ${ngdev}" >> "${FULL}" 2>&1; then
+ echo "Error: id-ns failed"
+ fi
+
+ if ! su $usr -c "nvme id-ctrl ${ngdev}" >> "${FULL}" 2>&1; then
+ echo "Error: id-ctrl failed"
+ fi
+
+ if su $usr -c "nvme ns-descs ${ngdev}" >> "${FULL}" 2>&1; then
+ echo "Error: ns-descs passed (unexpected)"
+ fi
+
+ echo "Test complete"
+ chmod $perm "$ngdev"
+ userdel -r $usr >> "${FULL}" 2>&1
+}
diff --git a/tests/nvme/046.out b/tests/nvme/046.out
new file mode 100644
index 0000000..2b5fa6a
--- /dev/null
+++ b/tests/nvme/046.out
@@ -0,0 +1,2 @@
+Running nvme/046
+Test complete
--
2.25.1
More information about the Linux-nvme
mailing list