]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic/memfd: reduce default seals to historic set
authorDavid Rheinsberg <david@readahead.eu>
Mon, 17 Jul 2023 10:01:18 +0000 (12:01 +0200)
committerDavid Rheinsberg <david@readahead.eu>
Tue, 1 Aug 2023 08:13:51 +0000 (10:13 +0200)
Rather than always setting all seals, make `memfd_set_seals()` employ
the original set of seals, that is: SEAL+GROW+SHRINK+WRITE

Historically, the memfd code was used with the out-of-tree memfd
patches, which merely supported a single seal ("SEALED", which
effectively was GROW+SHRINK+WRITE). When the code was adapted to the
upstream memfd seals, it was extended to the full seal set. With more
and more seals being added upstream, this because more problematic. In
particular, it is unclear what the function really is meant to achieve.

Instead of just adding all seals, the function is returned to its
original purpose: seal the memfd so futher modifications to its content
are prevented.

src/basic/memfd-util.c

index c4e36b0ad454d3623a90aad5d7fa8f9eea6f8f99..e21514fa9ea91497d09c3162c91c4854ffaafdce 100644 (file)
@@ -92,15 +92,9 @@ int memfd_map(int fd, uint64_t offset, size_t size, void **p) {
 }
 
 int memfd_set_sealed(int fd) {
-        int r;
-
         assert(fd >= 0);
 
-        r = RET_NERRNO(fcntl(fd, F_ADD_SEALS, F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE | F_SEAL_EXEC | F_SEAL_SEAL));
-        if (r == -EINVAL) /* old kernel ? */
-                r = RET_NERRNO(fcntl(fd, F_ADD_SEALS, F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE | F_SEAL_SEAL));
-
-        return r;
+        return RET_NERRNO(fcntl(fd, F_ADD_SEALS, F_SEAL_SEAL | F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE));
 }
 
 int memfd_get_sealed(int fd) {