Skip to content

Commit 803bd62

Browse files
committed
signal: serialize signalfd mask update against signal-dispatch read
set_mask() wrote _mask without any lock, while the signal-dispatch path reads it via watches() while holding registry_lock. A concurrent signalfd() mask update racing a signal delivery could read a torn/stale sigset_t and mis-route a single signal. Take registry_lock in set_mask() so the update is serialized against the dispatch-time reads (matching the lock the read side already holds).
1 parent e18263d commit 803bd62

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

libc/signalfd.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ class signal_fd final : public special_file {
6666
poll_wake(this, POLLIN);
6767
}
6868

69-
void set_mask(const sigset_t& mask) { _mask = mask; }
69+
// Update the watched-signal set. Taken under registry_lock (the same lock
70+
// held while the signal-dispatch path calls watches()), so a concurrent
71+
// signalfd() mask update cannot race a delivery's read of _mask.
72+
void set_mask(const sigset_t& mask) {
73+
WITH_LOCK(registry_lock) { _mask = mask; }
74+
}
7075

7176
private:
7277
mutable mutex _mutex;

0 commit comments

Comments
 (0)