MT#55283 prevent racy reuse of poller slots

Closes #2210

Change-Id: If60d1971fc9f313b5fdf2addef4d698b02d22162
(cherry picked from commit 3865f8960d)
(cherry picked from commit a787632b19)
mr26.0.1
Richard Fuchs 4 weeks ago
parent f4d9338ca9
commit a561d29cd1

@ -31,6 +31,8 @@ struct poller_item_int {
struct poller {
int fd;
int32_t gen;
static_assert(sizeof(int) == sizeof(int32_t), "int fd is not 32 bits");
mutex_t lock;
GPtrArray *items;
};
@ -117,6 +119,8 @@ bool poller_add_item(struct poller *p, struct poller_item *i) {
if (i->u.fd < p->items->len && p->items->pdata[i->u.fd])
return false;
i->u.gen = ++p->gen;
ZERO(e);
e.events = epoll_events(i, NULL);
e.data.u64 = i->u.u64;
@ -215,6 +219,9 @@ static int poller_poll(struct poller *p, int timeout, struct epoll_event *evs, i
if (!it)
continue;
if (it->item.u.u64 != u64.u64)
continue;
obj_hold(it);
mutex_unlock(&p->lock);

@ -27,6 +27,7 @@ typedef void (*poller_func_t)(int, void *);
union poller_item_u64 {
struct {
int fd;
int32_t gen;
} __attribute__((packed));
uint64_t u64;
};

Loading…
Cancel
Save