Commit bf8690b
committed
Harden /proc/self oom and fdinfo nodes
procfs emulation now treats the OOM trio (oom_score_adj, legacy oom_adj,
read-only oom_score) as one process-wide adjustment with per-path read
and write semantics: legacy oom_adj scales to oom_score_adj on writes
(special-casing OOM_DISABLE -> SCORE_ADJ_MIN and OOM_ADJUST_MAX ->
SCORE_ADJ_MAX so the boundary intent survives the lossy multiply) and
back-clamps to [-17, 15] on reads; oom_score is read-only with a stub
zero. The OOM write path serializes the truncate+pwrite+lseek under a
new oom_write_lock and publishes the global atomic only after the
backing rewrite succeeds, so a partial-rewrite failure no longer leaves
the process-wide value diverged from a returned -1. Zero-length writes
short-circuit to success (matches Linux for proc nodes; sys_writev
previously hit -EINVAL in the parser). Stat reports st_size 0 for every
synthetic /proc file so callers that pre-size buffers from stat cannot
truncate (a 256-byte cap had silently chopped /proc/cpuinfo on hosts
with many CPUs; a 2-byte cap had reduced -1000 to -1 on oom_score_adj).
A new read-intercept path mirrors the write side. proc_intercept_read
and proc_intercept_readv let read/pread/readv/preadv on the OOM nodes
return the live atomic value rather than the per-open temp file
content, and sendfile/copy_file_range route through the same hook so
proc-source byte counts stay consistent with the value an immediately
following open would observe.
/proc/self/fdinfo gains type-specific lines for the special fd classes
elfuse implements: eventfd-count (16-char hex matching fs/eventfd.c),
sigmask (16-char hex), and timerfd clockid/ticks/it_value/it_interval.
The accessors live in src/syscall/fd.c (eventfd_fdinfo_snapshot,
signalfd_fdinfo_snapshot, timerfd_fdinfo_snapshot) and read state under
sfd_lock to prevent tearing across concurrent read/write/settime. The
per-fd lseek probe now uses fd_to_host_dup so a concurrent close+reopen
on another vCPU cannot redirect the probe to an unrelated host fd, and
errno is saved/restored across the ESPIPE-prone lseek so
non-seekable fds (sockets, pipes) do not pollute the caller's state.
/proc/self/fdinfo and /proc/self/fd no longer share one static backing
directory across opens. The previous design let a second open unlink
and recreate entries while a sibling thread iterated its dirfd; both
nodes now go through proc_open_fd_scratch, which mkdtemps a private
directory per open, populates it from a fresh fd-table snapshot, and
tracks the path in proc_scratch_dirs[] for atexit cleanup so the
previously-leaked backing dirs are reaped at process exit.
The unix-net visitor's buffer-tail margin grew from 128 to 256 bytes
to fit the longest possible row (54 fixed + 108 sun_path + newline);
the previous margin let the snprintf truncate the path and drop the
trailing newline. Eight explicit /proc/<pid>/X cases collapsed into
one general alias-and-recurse, so /proc/<our_pid>/maps,
/oom_score_adj, /limits, etc. now route through the matching
/proc/self handler.
Locked in by tests/test-tier-b.c (35 cases including oom write
persistence, out-of-range -EINVAL, oom_adj=15 -> 1000 scaling,
oom_score read-only and write-rejected, zero-length writev,
stat-size-zero, fdinfo eventfd-count hex, fdinfo sigmask, fdinfo
timerfd next expiry for periodic timers, concurrent fdinfo
enumeration, and a /proc/net/tcp sl-density regression that opens
non-TCP sockets before TCP listeners so the iterator visits rejected
sockets first; the post-fix dense sl=0,1,... output matches qemu
Linux ground truth, and a manual bug reintroduction confirms the
test catches the sparse-slot regression with sl=4 expected=0).
tests/test-io-opt.c adds sendfile and copy_file_range coverage for
the read-intercept path.1 parent 34c741f commit bf8690b
8 files changed
Lines changed: 1887 additions & 615 deletions
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
56 | 75 | | |
57 | 76 | | |
58 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
119 | 146 | | |
120 | 147 | | |
121 | 148 | | |
| |||
203 | 230 | | |
204 | 231 | | |
205 | 232 | | |
206 | | - | |
207 | | - | |
| 233 | + | |
208 | 234 | | |
209 | 235 | | |
210 | 236 | | |
| |||
319 | 345 | | |
320 | 346 | | |
321 | 347 | | |
322 | | - | |
323 | 348 | | |
324 | 349 | | |
325 | 350 | | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
| 351 | + | |
343 | 352 | | |
344 | 353 | | |
345 | 354 | | |
| |||
1073 | 1082 | | |
1074 | 1083 | | |
1075 | 1084 | | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
| 74 | + | |
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
| |||
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
| 90 | + | |
| 91 | + | |
89 | 92 | | |
90 | 93 | | |
91 | 94 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
479 | 479 | | |
480 | 480 | | |
481 | 481 | | |
| 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 | + | |
482 | 544 | | |
483 | 545 | | |
484 | 546 | | |
| |||
613 | 675 | | |
614 | 676 | | |
615 | 677 | | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
616 | 688 | | |
617 | 689 | | |
618 | 690 | | |
| |||
642 | 714 | | |
643 | 715 | | |
644 | 716 | | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
645 | 724 | | |
646 | 725 | | |
647 | 726 | | |
| |||
832 | 911 | | |
833 | 912 | | |
834 | 913 | | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
835 | 925 | | |
836 | 926 | | |
837 | 927 | | |
| |||
919 | 1009 | | |
920 | 1010 | | |
921 | 1011 | | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
922 | 1020 | | |
923 | 1021 | | |
924 | 1022 | | |
| |||
1354 | 1452 | | |
1355 | 1453 | | |
1356 | 1454 | | |
1357 | | - | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
1358 | 1461 | | |
1359 | | - | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
1360 | 1469 | | |
1361 | 1470 | | |
1362 | 1471 | | |
| |||
1443 | 1552 | | |
1444 | 1553 | | |
1445 | 1554 | | |
1446 | | - | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
1447 | 1561 | | |
1448 | | - | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
1449 | 1569 | | |
1450 | 1570 | | |
1451 | 1571 | | |
| |||
0 commit comments