]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mmap-cache: check if mmap protection mode is consistent when fd is already managed
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 28 Sep 2023 01:46:23 +0000 (10:46 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 30 Sep 2023 21:35:02 +0000 (06:35 +0900)
Otherwise, MMapFileDescriptor with an unexpected protection mode may be
returned.

src/libsystemd/sd-journal/mmap-cache.c

index 6c2c26fde803fe9f610f3c6c1af4c9743873c0aa..992bf1c4fc5a3b0ab19abdd96caa3e4f50678dbe 100644 (file)
@@ -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;