• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 16062852561

03 Jul 2025 10:04PM UTC coverage: 72.193% (+0.1%) from 72.096%
16062852561

push

github

bluca
pcrlock: process components outside of location window properly

So far, when we tried to match a component to eent log entries we
skipped those components if they were outside of our location window.
That however is too aggressive, since it means any components that are
already in the logs, but outside of the location window will be
considered unrecognized in the logs, and thus removed from the PCR
policy.

Change things around: always try to match up all components, regardless
if inside the location window or outside, but then make it non-fatal we
can't find a component outside of the location window.

Fixes: #36079

7 of 9 new or added lines in 1 file covered. (77.78%)

4116 existing lines in 75 files now uncovered.

301219 of 417241 relevant lines covered (72.19%)

730820.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.36
/src/basic/memfd-util.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <sched.h>
4
#include <stdio.h>
5
#include <sys/prctl.h>
6
#include <sys/stat.h>
7
#include <unistd.h>
8

9
#include "alloc-util.h"
10
#include "errno-util.h"
11
#include "fd-util.h"
12
#include "memfd-util.h"
13
#include "string-util.h"
14
#include "utf8.h"
15

16
int memfd_create_wrapper(const char *name, unsigned mode) {
4,939✔
17
        unsigned mode_compat;
4,939✔
18
        int mfd;
4,939✔
19

20
        assert(name);
4,939✔
21

22
        /* Wrapper around memfd_create() which adds compat with older kernels where memfd_create() didn't
23
         * support MFD_EXEC/MFD_NOEXEC_SEAL. (kernel 6.3+) */
24

25
        mfd = RET_NERRNO(memfd_create(name, mode));
4,939✔
UNCOV
26
        if (mfd != -EINVAL)
×
27
                return mfd;
4,939✔
28

UNCOV
29
        mode_compat = mode & ~(MFD_EXEC | MFD_NOEXEC_SEAL);
×
30

UNCOV
31
        if (mode == mode_compat)
×
32
                return mfd;
33

UNCOV
34
        return RET_NERRNO(memfd_create(name, mode_compat));
×
35
}
36

37
int memfd_new_full(const char *name, unsigned extra_flags) {
4,938✔
38
        _cleanup_free_ char *g = NULL;
4,938✔
39

40
        if (!name) {
4,938✔
UNCOV
41
                char pr[TASK_COMM_LEN] = {};
×
42

43
                /* If no name is specified we generate one. We include
44
                 * a hint indicating our library implementation, and
45
                 * add the thread name to it */
46

UNCOV
47
                assert_se(prctl(PR_GET_NAME, (unsigned long) pr) >= 0);
×
48

UNCOV
49
                if (isempty(pr))
×
50
                        name = "sd";
51
                else {
UNCOV
52
                        _cleanup_free_ char *e = NULL;
×
53

UNCOV
54
                        e = utf8_escape_invalid(pr);
×
55
                        if (!e)
×
56
                                return -ENOMEM;
57

UNCOV
58
                        g = strjoin("sd-", e);
×
59
                        if (!g)
×
60
                                return -ENOMEM;
61

UNCOV
62
                        name = g;
×
63
                }
64
        }
65

66
        return memfd_create_wrapper(
4,938✔
67
                        name,
68
                        MFD_CLOEXEC | MFD_NOEXEC_SEAL | extra_flags);
69
}
70

71
static int memfd_add_seals(int fd, unsigned seals) {
4,829✔
72
        assert(fd >= 0);
4,829✔
73

74
        return RET_NERRNO(fcntl(fd, F_ADD_SEALS, seals));
4,829✔
75
}
76

77
static int memfd_get_seals(int fd, unsigned *ret_seals) {
2✔
78
        int r;
2✔
79

80
        assert(fd >= 0);
2✔
81

82
        r = RET_NERRNO(fcntl(fd, F_GET_SEALS));
2✔
UNCOV
83
        if (r < 0)
×
84
                return r;
85

86
        if (ret_seals)
2✔
87
                *ret_seals = r;
2✔
88
        return 0;
89
}
90

91
int memfd_set_sealed(int fd) {
4,829✔
92
        return memfd_add_seals(fd, F_SEAL_SEAL | F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE);
4,829✔
93
}
94

95
int memfd_get_sealed(int fd) {
2✔
96
        unsigned seals;
2✔
97
        int r;
2✔
98

99
        r = memfd_get_seals(fd, &seals);
2✔
100
        if (r < 0)
2✔
101
                return r;
2✔
102

103
        /* We ignore F_SEAL_EXEC here to support older kernels. */
104
        return FLAGS_SET(seals, F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE);
2✔
105
}
106

107
int memfd_get_size(int fd, uint64_t *ret) {
3✔
108
        struct stat stat;
3✔
109

110
        assert(fd >= 0);
3✔
111
        assert(ret);
3✔
112

113
        if (fstat(fd, &stat) < 0)
3✔
UNCOV
114
                return -errno;
×
115

116
        *ret = stat.st_size;
3✔
117
        return 0;
3✔
118
}
119

120
int memfd_set_size(int fd, uint64_t sz) {
2✔
121
        assert(fd >= 0);
2✔
122

123
        return RET_NERRNO(ftruncate(fd, sz));
2✔
124
}
125

126
int memfd_new_and_seal(const char *name, const void *data, size_t sz) {
186✔
127
        _cleanup_close_ int fd = -EBADF;
186✔
128
        int r;
186✔
129

130
        assert(data || sz == 0);
186✔
131

132
        if (sz == SIZE_MAX)
186✔
133
                sz = strlen(data);
185✔
134

135
        fd = memfd_new_full(name, MFD_ALLOW_SEALING);
186✔
136
        if (fd < 0)
186✔
137
                return fd;
138

139
        if (sz > 0) {
186✔
140
                ssize_t n = pwrite(fd, data, sz, 0);
186✔
141
                if (n < 0)
186✔
UNCOV
142
                        return -errno;
×
143
                if ((size_t) n != sz)
186✔
144
                        return -EIO;
145
        }
146

147
        r = memfd_set_sealed(fd);
186✔
148
        if (r < 0)
186✔
UNCOV
149
                return r;
×
150

151
        return TAKE_FD(fd);
152
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc