1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-23 17:34:00 +03:00

Merge pull request #18924 from keszybz/homed-inotify-crash

Homed inotify crash
This commit is contained in:
Lennart Poettering 2021-03-08 15:12:30 +01:00 committed by GitHub
commit 00248fc4f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 33 deletions

View File

@ -885,7 +885,7 @@ static int on_deferred_change(sd_event_source *s, void *userdata) {
assert(h);
h->deferred_change_event_source = sd_event_source_unref(h->deferred_change_event_source);
h->deferred_change_event_source = sd_event_source_disable_unref(h->deferred_change_event_source);
r = bus_home_path(h, &path);
if (r < 0) {

View File

@ -188,17 +188,17 @@ Home *home_free(Home *h) {
user_record_unref(h->record);
user_record_unref(h->secret);
h->worker_event_source = sd_event_source_unref(h->worker_event_source);
h->worker_event_source = sd_event_source_disable_unref(h->worker_event_source);
safe_close(h->worker_stdout_fd);
free(h->user_name);
free(h->sysfs);
h->ref_event_source_please_suspend = sd_event_source_unref(h->ref_event_source_please_suspend);
h->ref_event_source_dont_suspend = sd_event_source_unref(h->ref_event_source_dont_suspend);
h->ref_event_source_please_suspend = sd_event_source_disable_unref(h->ref_event_source_please_suspend);
h->ref_event_source_dont_suspend = sd_event_source_disable_unref(h->ref_event_source_dont_suspend);
h->pending_operations = ordered_set_free(h->pending_operations);
h->pending_event_source = sd_event_source_unref(h->pending_event_source);
h->deferred_change_event_source = sd_event_source_unref(h->deferred_change_event_source);
h->pending_event_source = sd_event_source_disable_unref(h->pending_event_source);
h->deferred_change_event_source = sd_event_source_disable_unref(h->deferred_change_event_source);
h->current_operation = operation_unref(h->current_operation);
@ -888,7 +888,7 @@ static int home_on_worker_process(sd_event_source *s, const siginfo_t *si, void
(void) hashmap_remove_value(h->manager->homes_by_worker_pid, PID_TO_PTR(h->worker_pid), h);
h->worker_pid = 0;
h->worker_event_source = sd_event_source_unref(h->worker_event_source);
h->worker_event_source = sd_event_source_disable_unref(h->worker_event_source);
if (si->si_code != CLD_EXITED) {
assert(IN_SET(si->si_code, CLD_KILLED, CLD_DUMPED));
@ -1067,7 +1067,7 @@ static int home_start_work(Home *h, const char *verb, UserRecord *hr, UserRecord
r = hashmap_put(h->manager->homes_by_worker_pid, PID_TO_PTR(pid), h);
if (r < 0) {
h->worker_event_source = sd_event_source_unref(h->worker_event_source);
h->worker_event_source = sd_event_source_disable_unref(h->worker_event_source);
return r;
}

View File

@ -860,7 +860,7 @@ static int on_deferred_auto_login(sd_event_source *s, void *userdata) {
assert(m);
m->deferred_auto_login_event_source = sd_event_source_unref(m->deferred_auto_login_event_source);
m->deferred_auto_login_event_source = sd_event_source_disable_unref(m->deferred_auto_login_event_source);
r = sd_bus_emit_properties_changed(
m->bus,

View File

@ -79,7 +79,7 @@ static void manager_watch_home(Manager *m) {
assert(m);
m->inotify_event_source = sd_event_source_unref(m->inotify_event_source);
m->inotify_event_source = sd_event_source_disable_unref(m->inotify_event_source);
m->scan_slash_home = false;
if (statfs("/home/", &sfs) < 0) {
@ -100,7 +100,9 @@ static void manager_watch_home(Manager *m) {
m->scan_slash_home = true;
r = sd_event_add_inotify(m->event, &m->inotify_event_source, "/home/", IN_CREATE|IN_CLOSE_WRITE|IN_DELETE_SELF|IN_MOVE_SELF|IN_ONLYDIR|IN_MOVED_TO|IN_MOVED_FROM|IN_DELETE, on_home_inotify, m);
r = sd_event_add_inotify(m->event, &m->inotify_event_source, "/home/",
IN_CREATE|IN_CLOSE_WRITE|IN_DELETE_SELF|IN_MOVE_SELF|IN_ONLYDIR|IN_MOVED_TO|IN_MOVED_FROM|IN_DELETE,
on_home_inotify, m);
if (r < 0)
log_full_errno(r == -ENOENT ? LOG_DEBUG : LOG_WARNING, r,
"Failed to create inotify watch on /home/, ignoring.");
@ -239,25 +241,24 @@ Manager* manager_free(Manager *m) {
HASHMAP_FOREACH(h, m->homes_by_worker_pid)
(void) home_wait_for_worker(h);
sd_bus_flush_close_unref(m->bus);
bus_verify_polkit_async_registry_free(m->polkit_registry);
m->device_monitor = sd_device_monitor_unref(m->device_monitor);
m->inotify_event_source = sd_event_source_unref(m->inotify_event_source);
m->notify_socket_event_source = sd_event_source_unref(m->notify_socket_event_source);
m->deferred_rescan_event_source = sd_event_source_unref(m->deferred_rescan_event_source);
m->deferred_gc_event_source = sd_event_source_unref(m->deferred_gc_event_source);
m->deferred_auto_login_event_source = sd_event_source_unref(m->deferred_auto_login_event_source);
sd_event_unref(m->event);
hashmap_free(m->homes_by_uid);
hashmap_free(m->homes_by_name);
hashmap_free(m->homes_by_worker_pid);
hashmap_free(m->homes_by_sysfs);
m->inotify_event_source = sd_event_source_unref(m->inotify_event_source);
bus_verify_polkit_async_registry_free(m->polkit_registry);
sd_bus_flush_close_unref(m->bus);
sd_event_unref(m->event);
m->notify_socket_event_source = sd_event_source_unref(m->notify_socket_event_source);
m->device_monitor = sd_device_monitor_unref(m->device_monitor);
m->deferred_rescan_event_source = sd_event_source_unref(m->deferred_rescan_event_source);
m->deferred_gc_event_source = sd_event_source_unref(m->deferred_gc_event_source);
m->deferred_auto_login_event_source = sd_event_source_unref(m->deferred_auto_login_event_source);
if (m->private_key)
EVP_PKEY_free(m->private_key);
@ -368,7 +369,9 @@ static int manager_add_home_by_record(
return r;
if (!streq_ptr(hr->user_name, name))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Identity's user name %s does not match file name %s, refusing.", hr->user_name, name);
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Identity's user name %s does not match file name %s, refusing.",
hr->user_name, name);
is_signed = manager_verify_user_record(m, hr);
switch (is_signed) {
@ -599,19 +602,22 @@ static int manager_acquire_uid(
other = hashmap_get(m->homes_by_uid, UID_TO_PTR(candidate));
if (other) {
log_debug("Candidate UID " UID_FMT " already used by another home directory (%s), let's try another.", candidate, other->user_name);
log_debug("Candidate UID " UID_FMT " already used by another home directory (%s), let's try another.",
candidate, other->user_name);
continue;
}
pw = getpwuid(candidate);
if (pw) {
log_debug("Candidate UID " UID_FMT " already registered by another user in NSS (%s), let's try another.", candidate, pw->pw_name);
log_debug("Candidate UID " UID_FMT " already registered by another user in NSS (%s), let's try another.",
candidate, pw->pw_name);
continue;
}
gr = getgrgid((gid_t) candidate);
if (gr) {
log_debug("Candidate UID " UID_FMT " already registered by another group in NSS (%s), let's try another.", candidate, gr->gr_name);
log_debug("Candidate UID " UID_FMT " already registered by another group in NSS (%s), let's try another.",
candidate, gr->gr_name);
continue;
}
@ -619,7 +625,8 @@ static int manager_acquire_uid(
if (r < 0)
continue;
if (r > 0) {
log_debug_errno(r, "Candidate UID " UID_FMT " already owns IPC objects, let's try another: %m", candidate);
log_debug_errno(r, "Candidate UID " UID_FMT " already owns IPC objects, let's try another: %m",
candidate);
continue;
}
@ -692,7 +699,9 @@ static int manager_add_home_by_image(
if (h && uid_is_valid(h->uid))
uid = h->uid;
else {
r = manager_acquire_uid(m, start_uid, user_name, IN_SET(storage, USER_SUBVOLUME, USER_DIRECTORY, USER_FSCRYPT) ? image_path : NULL, &uid);
r = manager_acquire_uid(m, start_uid, user_name,
IN_SET(storage, USER_SUBVOLUME, USER_DIRECTORY, USER_FSCRYPT) ? image_path : NULL,
&uid);
if (r < 0)
return log_warning_errno(r, "Failed to acquire unused UID for %s: %m", user_name);
}
@ -1660,7 +1669,7 @@ static int on_deferred_rescan(sd_event_source *s, void *userdata) {
assert(m);
m->deferred_rescan_event_source = sd_event_source_unref(m->deferred_rescan_event_source);
m->deferred_rescan_event_source = sd_event_source_disable_unref(m->deferred_rescan_event_source);
manager_enumerate_devices(m);
manager_enumerate_images(m);
@ -1698,7 +1707,7 @@ static int on_deferred_gc(sd_event_source *s, void *userdata) {
assert(m);
m->deferred_gc_event_source = sd_event_source_unref(m->deferred_gc_event_source);
m->deferred_gc_event_source = sd_event_source_disable_unref(m->deferred_gc_event_source);
manager_gc_images(m);
return 0;