From 8ff0f36e00626451e92511f59dd35e3ba836806f Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 28 Sep 2023 10:46:23 +0900 Subject: [PATCH] mmap-cache: check if mmap protection mode is consistent when fd is already managed Otherwise, MMapFileDescriptor with an unexpected protection mode may be returned. --- src/libsystemd/sd-journal/mmap-cache.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libsystemd/sd-journal/mmap-cache.c b/src/libsystemd/sd-journal/mmap-cache.c index 6c2c26fde80..992bf1c4fc5 100644 --- a/src/libsystemd/sd-journal/mmap-cache.c +++ b/src/libsystemd/sd-journal/mmap-cache.c @@ -551,6 +551,8 @@ int mmap_cache_add_fd(MMapCache *m, int fd, int prot, MMapFileDescriptor **ret) existing = hashmap_get(m->fds, FD_TO_PTR(fd)); if (existing) { + if (existing->prot != prot) + return -EEXIST; if (ret) *ret = existing; return 0; -- 2.47.3