Skip to contentSkip to conversation

selftests/udmabuf: Open /dev/udmabuf O_RDONLY

PATCH New T.J. Mercier 1 participant 1 message Jul 22 Kselftest

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 selftests/udmabuf: Open /dev/udmabuf O_RDONLY

Write permissions on the /dev/udmabuf device file are not required to issue ioctls and allocate udmabufs. Applications should be opening this file as O_RDONLY. The BPF dmabuf_iter selftest already does this. [1]

Users are pointing to these selftests as examples of how use udmabuf, and encountering permission errors on systems where write permissions are not available on /dev/udmabuf. Apply the principle of least privilege to selftests which use udmabuf by removing the write access mode from drivers/dma-buf/udmabuf.c and drivers/net/hw/ncdevmem.c.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/testing/selftests/bpf/prog_tests/dmabuf_iter.c?h=v7.1#n49

---
 tools/testing/selftests/drivers/dma-buf/udmabuf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/drivers/dma-buf/udmabuf.c +1 -1
index d78aec662586..ced0b95c876c 100644
@@ -140,7 +140,7 @@ int main(int argc, char *argv[])
 	ksft_print_header();
 	ksft_set_plan(7);
 
-	devfd = open("/dev/udmabuf", O_RDWR);
+	devfd = open("/dev/udmabuf", O_RDONLY);
 	if (devfd < 0) {
 		ksft_print_msg(
 			"%s: [skip,no-udmabuf: Unable to access DMA buffer device file]\n",

base-commit: 20f01a5565ce79923b75a2ac8e8ef2a1d7adf517

Signature · 1 line
2.55.0.229.g6434b31f56-goog