From fbaa3c989086c3a09eab0886e324f69a49339e9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Sat, 15 Jun 2024 02:40:46 -0700 Subject: [PATCH] BpfRingbuf.h - use exclusively locked map MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As currently implemented, it is not safe to open (and mmap) the same kernel -> userspace ringbuffer multiple times. Note: it's likely, that as implemented, even a single instance is not thread safe without external locking. Test: TreeHugger, atest bpf_existence_test bpf_module_test bpf-time-in-state-tests libbpf_android_test Signed-off-by: Maciej Żenczykowski Change-Id: Iea6908746a58e7412c0ce89da29a764aefeaef47 --- staticlibs/native/bpf_headers/include/bpf/BpfRingbuf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/staticlibs/native/bpf_headers/include/bpf/BpfRingbuf.h b/staticlibs/native/bpf_headers/include/bpf/BpfRingbuf.h index d7163588fc..cd51004066 100644 --- a/staticlibs/native/bpf_headers/include/bpf/BpfRingbuf.h +++ b/staticlibs/native/bpf_headers/include/bpf/BpfRingbuf.h @@ -151,7 +151,7 @@ class BpfRingbuf : public BpfRingbufBase { inline base::Result BpfRingbufBase::Init(const char* path) { - mRingFd.reset(mapRetrieveRW(path)); + mRingFd.reset(mapRetrieveExclusiveRW(path)); if (!mRingFd.ok()) { return android::base::ErrnoError() << "failed to retrieve ringbuffer at " << path;