From: Yu Watanabe Date: Thu, 28 Sep 2023 01:46:23 +0000 (+0900) Subject: mmap-cache: check if mmap protection mode is consistent when fd is already managed X-Git-Tag: v255-rc1~338^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8ff0f36e00626451e92511f59dd35e3ba836806f;p=thirdparty%2Fsystemd.git mmap-cache: check if mmap protection mode is consistent when fd is already managed Otherwise, MMapFileDescriptor with an unexpected protection mode may be returned. --- 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;