mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "T.J. Mercier" <tjmercier@google.com>
To: sumit.semwal@linaro.org, benjamin.gaignard@collabora.com,
	 Brian.Starkey@arm.com, jstultz@google.com,
	linux-media@vger.kernel.org,  dri-devel@lists.freedesktop.org,
	linaro-mm-sig@lists.linaro.org
Cc: christian.koenig@amd.com, shuah@kernel.org,
	 linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
	 "T.J. Mercier" <tjmercier@google.com>
Subject: [PATCH] kselftests: dmabuf-heaps: Open heap device files O_RDONLY
Date: Tue, 11 Aug 2026 13:41:23 -0700	[thread overview]
Message-ID: <20260811204123.3198370-1-tjmercier@google.com> (raw)

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

Users are pointing to these selftests as examples of how use dmabuf,
and encountering permission errors on systems where write permissions
are not available on /dev/dma_heap/*. Apply the principle of least
privilege to selftests which open dmabuf heaps by removing the write
access mode and using O_RDONLY for the open() instead.

The same is true for the vgem test using /dev/dri/card.

[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

Signed-off-by: T.J. Mercier <tjmercier@google.com>
---
 tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c b/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c
index fc9694fc4e89..45b420e37c97 100644
--- a/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c
+++ b/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c
@@ -48,7 +48,7 @@ static int open_vgem(void)
 
 		snprintf(name, 80, "%s%u", drmstr, i);
 
-		fd = open(name, O_RDWR);
+		fd = open(name, O_RDONLY);
 		if (fd < 0)
 			continue;
 
@@ -96,7 +96,7 @@ static int dmabuf_heap_open(char *name)
 	if (ret < 0)
 		ksft_exit_fail_msg("snprintf failed! %d\n", ret);
 
-	fd = open(buf, O_RDWR);
+	fd = open(buf, O_RDONLY);
 	if (fd < 0)
 		ksft_exit_fail_msg("open %s failed: %s\n", buf, strerror(errno));
 

base-commit: 9a11db68872055e6ead919bad04d6330851c522d
-- 
2.55.0.679.g6767b8d81c-goog


             reply	other threads:[~2026-08-11 20:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-11 20:41 T.J. Mercier [this message]
2026-08-11 20:57 ` John Stultz
2026-08-12  8:51 ` Christian König
2026-08-12 15:02 ` Sumit Semwal
2026-08-12 16:06   ` T.J. Mercier
2026-11-06 18:42     ` T.J. Mercier
2026-11-09 11:10       ` Christian König

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260811204123.3198370-1-tjmercier@google.com \
    --to=tjmercier@google.com \
    --cc=Brian.Starkey@arm.com \
    --cc=benjamin.gaignard@collabora.com \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jstultz@google.com \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=sumit.semwal@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®