Adding event mask validation for ModifyWaitEvent
Josh Kupershmidt <schmiddy@gmail.com>
From: Josh Kupershmidt <schmiddy@gmail.com>
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2026-04-06T14:57:56Z
Lists: pgsql-hackers
Attachments
- event-mask-validation-for-ModifyWaitEvent.patch (application/x-patch) patch
Hi, Please find attached a patch implementing an old FIXME comment [1] about validating the event mask in ModifyWaitEvent(). To prevent callers of ModifyWaitEvent() from passing invalid flags that can be silently accepted, I propose adding two checks: 1. Prevent setting socket wait flags on an event that has no socket, mirroring line 600 of AddWaitEventToSet() [2]. 2. Prevent promoting a non-latch event to a latch event through ModifyWaitEvent(). The setup for latch events is handled in AddWaitEventToSet(), but not supported in ModifyWaitEvent(). For example, AddWaitEventToSet() enforces "cannot wait on more than one latch" [3] per set, registering the latch pointer [4], and handles platform-specific latch behavior [5]. We do still allow the behavior documented in the comment for ModifyWaitEvent() [6] about setting a latch to NULL to disable it, and enabling again as a latch later. [1] The commit adding this code dates back to 2016, added in https://github.com/postgres/postgres/commit/98a64d0bd71#diff-6e542ba2eb1d83ef90e65cdc0912b51a295184701c7e3bd236937c43c4cac4b9R704 [2] https://github.com/postgres/postgres/blob/master/src/backend/storage/ipc/waiteventset.c#L600 [3] https://github.com/postgres/postgres/blob/master/src/backend/storage/ipc/waiteventset.c#L588-L589 [4] https://github.com/postgres/postgres/blob/master/src/backend/storage/ipc/waiteventset.c#L614-L615 [5] https://github.com/postgres/postgres/blob/master/src/backend/storage/ipc/waiteventset.c#L616-L619 [6] https://github.com/postgres/postgres/blob/master/src/backend/storage/ipc/waiteventset.c#L650-L651