Commit f94e445
Shanire
Close the transfer socket and set CLOEXEC on received listener fds
get_fds_from() leaks two kinds of file descriptors on every graceful
upgrade:
- The connection returned by accept() is a bare RawFd that is never
closed; only listen_fd is. Every completed upgrade therefore leaks
one connected unix socket for the lifetime of the process.
- recvmsg() is called with MsgFlags::empty(), so the listening sockets
received over SCM_RIGHTS do not have FD_CLOEXEC set. Those fds are
held for the lifetime of the process, so they are inherited by every
child it later execs.
The second one also interacts with the unclaimed-fd cleanup added in
"Close unclaimed inherited listening sockets on graceful upgrade": an fd
that reaches a process through exec() is not in the Fds table, so
listen_addresses() cannot close it. Deployments that start the new
generation by forking from the old one (needed when the service manager
tracks a cgroup) receive each listening socket twice, and only one of the
two copies is visible to that cleanup.
Take ownership of the accepted connection with OwnedFd so it is closed on
every path out of the function, including the early return from cmsgs()?,
and pass MSG_CMSG_CLOEXEC so the received descriptors get FD_CLOEXEC
atomically rather than through a follow-up fcntl().
The added test covers both defects independently: reverting
MSG_CMSG_CLOEXEC makes it report the missing flag, and reverting the
OwnedFd makes it find the accepted socket still open.
Signed-off-by: Shanire <shanire86@gmail.com>1 parent 0046038 commit f94e445
1 file changed
Lines changed: 99 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
191 | 198 | | |
192 | 199 | | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
193 | 204 | | |
194 | | - | |
| 205 | + | |
195 | 206 | | |
196 | 207 | | |
197 | | - | |
| 208 | + | |
198 | 209 | | |
199 | 210 | | |
200 | 211 | | |
| |||
387 | 398 | | |
388 | 399 | | |
389 | 400 | | |
| 401 | + | |
390 | 402 | | |
391 | 403 | | |
392 | 404 | | |
| |||
468 | 480 | | |
469 | 481 | | |
470 | 482 | | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
471 | 567 | | |
472 | 568 | | |
473 | 569 | | |
| |||
0 commit comments