1
0
mirror of https://github.com/systemd/systemd synced 2026-03-19 11:34:46 +01:00

Compare commits

..

3 Commits

Author SHA1 Message Date
Yu Watanabe
cf79f61238 calendarspec: day of month also needs to be reset when year is changed
Fixes #40260.
2026-01-04 20:05:43 +09:00
Lennart Poettering
82dea1c925 switch-root: don't do rm_rf() of old superblock on switch root if pivot_root() worked
We do the rm_rf_children() call only because in some cases we cannot
pivot_root() and hence the orginal root superblock stays pinned, and we
thus have to empty it to minimize its memory use. But if pivot_root()
worked (and the umount() for the old root), then there's really no need
to do this work.

Dropping this codepath is useful in context of Christian's recent work
to make the original initrd tmpfs unmountable, which means pivot_root()
will work, and thus there's no need to empty the tmpfs anymore, and we
can speed up boot a bit.

Fixes: #40250
2026-01-04 19:41:24 +09:00
Lennart Poettering
855b4cd731 analyze: properly handle nvpcrs that have not been initialized yet
Let's explicitly check if NvPCRs are fully set up (allocated, anchored)
before we try to show them.

Alternative to: #40184
2026-01-04 18:57:50 +09:00
5 changed files with 56 additions and 25 deletions

View File

@ -27,10 +27,11 @@ static int add_nvpcr_to_table(Tpm2Context **c, Table *t, const char *name) {
r = tpm2_nvpcr_read(*c, /* session= */ NULL, name, &digest, &nv_index); r = tpm2_nvpcr_read(*c, /* session= */ NULL, name, &digest, &nv_index);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to read NvPCR '%s': %m", name); return log_error_errno(r, "Failed to read NvPCR '%s': %m", name);
if (r > 0) { /* set? */
h = hexmem(digest.iov_base, digest.iov_len); h = hexmem(digest.iov_base, digest.iov_len);
if (!h) if (!h)
return log_oom(); return log_oom();
}
} else { } else {
r = tpm2_nvpcr_get_index(name, &nv_index); r = tpm2_nvpcr_get_index(name, &nv_index);
if (r < 0) if (r < 0)

View File

@ -1194,9 +1194,10 @@ static int tm_within_bounds(struct tm *tm, bool utc) {
* other sub time units are already reset in find_next(). * other sub time units are already reset in find_next().
*/ */
int cmp; int cmp;
if ((cmp = CMP(t.tm_year, tm->tm_year)) != 0) if ((cmp = CMP(t.tm_year, tm->tm_year)) != 0) {
t.tm_mon = 0; t.tm_mon = 0;
else if ((cmp = CMP(t.tm_mon, tm->tm_mon)) != 0) t.tm_mday = 1;
} else if ((cmp = CMP(t.tm_mon, tm->tm_mon)) != 0)
t.tm_mday = 1; t.tm_mday = 1;
else if ((cmp = CMP(t.tm_mday, tm->tm_mday)) != 0) else if ((cmp = CMP(t.tm_mday, tm->tm_mday)) != 0)
t.tm_hour = 0; t.tm_hour = 0;

View File

@ -54,7 +54,7 @@ int switch_root(const char *new_root,
if (new_root_fd < 0) if (new_root_fd < 0)
return log_error_errno(errno, "Failed to open target directory '%s': %m", new_root); return log_error_errno(errno, "Failed to open target directory '%s': %m", new_root);
r = fds_are_same_mount(old_root_fd, new_root_fd); r = fds_are_same_mount(old_root_fd, new_root_fd); /* checks if referenced inodes and mounts match */
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to check if old and new root directory/mount are the same: %m"); return log_error_errno(r, "Failed to check if old and new root directory/mount are the same: %m");
if (r > 0) { if (r > 0) {
@ -186,8 +186,8 @@ int switch_root(const char *new_root,
if (chdir(".") < 0) if (chdir(".") < 0)
return log_error_errno(errno, "Failed to change directory: %m"); return log_error_errno(errno, "Failed to change directory: %m");
}
/* Now empty the old root superblock */
if (istmp > 0) { if (istmp > 0) {
struct stat rb; struct stat rb;
@ -198,6 +198,11 @@ int switch_root(const char *new_root,
* it will stop at mount boundaries */ * it will stop at mount boundaries */
(void) rm_rf_children(TAKE_FD(old_root_fd), 0, &rb); /* takes possession of the dir fd, even on failure */ (void) rm_rf_children(TAKE_FD(old_root_fd), 0, &rb); /* takes possession of the dir fd, even on failure */
} }
} else
/* NB: we don't bother with emptying the old root superblock here, under the assumption the
* pivot_root() + umount() sufficiently detached from the superblock to the point we don't
* need to empty it anymore */
log_debug("Pivoting root worked.");
return 0; return 0;
} }

View File

@ -7474,6 +7474,21 @@ int tpm2_nvpcr_read(
if (r < 0) if (r < 0)
return r; return r;
/* Check if the NvPCR is already anchored */
const char *anchor_fname = strjoina("/run/systemd/nvpcr/", name, ".anchor");
r = access_nofollow(anchor_fname, F_OK);
if (r < 0) {
if (r != -ENOENT)
return log_debug_errno(r, "Failed to check if '%s' exists: %m", anchor_fname);
/* valid, but not anchored */
*ret_value = (struct iovec) {};
if (ret_nv_index)
*ret_nv_index = p.nv_index;
return 0;
}
_cleanup_(tpm2_handle_freep) Tpm2Handle *nv_handle = NULL; _cleanup_(tpm2_handle_freep) Tpm2Handle *nv_handle = NULL;
r = tpm2_index_to_handle( r = tpm2_index_to_handle(
c, c,
@ -7488,6 +7503,7 @@ int tpm2_nvpcr_read(
log_debug("Successfully acquired handle to NV index 0x%" PRIx32 ".", p.nv_index); log_debug("Successfully acquired handle to NV index 0x%" PRIx32 ".", p.nv_index);
if (r > 0) {
r = tpm2_read_nv_index( r = tpm2_read_nv_index(
c, c,
/* session= */ NULL, /* session= */ NULL,
@ -7497,10 +7513,16 @@ int tpm2_nvpcr_read(
if (r < 0) if (r < 0)
return r; return r;
r = 1;
} else {
*ret_value = (struct iovec) {};
r = 0;
}
if (ret_nv_index) if (ret_nv_index)
*ret_nv_index = p.nv_index; *ret_nv_index = p.nv_index;
return 0; return r;
#else /* HAVE_OPENSSL */ #else /* HAVE_OPENSSL */
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "OpenSSL support is disabled."); return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "OpenSSL support is disabled.");
#endif #endif

View File

@ -219,6 +219,8 @@ TEST(calendar_spec_next) {
test_next("Sun *-*-* 01:00:00 Europe/Dublin", "IST", 1616412478000000, 1617494400000000); test_next("Sun *-*-* 01:00:00 Europe/Dublin", "IST", 1616412478000000, 1617494400000000);
/* Europe/Dublin TZ that moves DST backwards */ /* Europe/Dublin TZ that moves DST backwards */
test_next("hourly", "IST-1GMT-0,M10.5.0/1,M3.5.0/1", 1743292800000000, 1743296400000000); test_next("hourly", "IST-1GMT-0,M10.5.0/1,M3.5.0/1", 1743292800000000, 1743296400000000);
/* Check when the year changes, see issue #40260 */
test_next("*-*-1/11 23:00:00 UTC", "", 1763938800000000, 1764630000000000);
} }
TEST(calendar_spec_from_string) { TEST(calendar_spec_from_string) {