[PATCH blktests v2 2/2] nvme/046: add test for unprivileged passthrough
Shin'ichiro Kawasaki
shinichiro.kawasaki at wdc.com
Mon Feb 13 20:47:39 PST 2023
From: Kanchan Joshi <joshi.k at samsung.com>
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 at samsung.com>
[Shin'ichiro: adjusted to normal user helper functions]
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki at wdc.com>
---
tests/nvme/046 | 50 ++++++++++++++++++++++++++++++++++++++++++++++
tests/nvme/046.out | 2 ++
2 files changed, 52 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..5689a2b
--- /dev/null
+++ b/tests/nvme/046
@@ -0,0 +1,50 @@
+#!/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
+}
+
+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
index 0000000..2b5fa6a
--- /dev/null
+++ b/tests/nvme/046.out
@@ -0,0 +1,2 @@
+Running nvme/046
+Test complete
--
2.38.1
More information about the Linux-nvme
mailing list