Commit 3646e40
Fix #154: hisi_gen2_read_exit_cb segfault that emptied jxf22 traces
Root cause:
unsigned char *buf = alloca(nbyte);
memset(&buf, 0, sizeof(nbyte)); // <-- bug
copy_from_process(proc->pid, remote_addr, buf, nbyte);
`memset(&buf, 0, sizeof(nbyte))` zeroed the local POINTER variable
(not the buffer it pointed at), so `buf` became NULL. The next
`copy_from_process(..., buf, ..)` then SIGSEGV'd the tracer at
`buf[i / sizeof(size_t)] = ret`.
On HISI_V2 / V2A targets where the sensor driver does an I2C read of
the chip-ID register right after `I2C_SLAVE_FORCE` (jxf22, sc2235,
ar0130, ...) ipctool died immediately after the first `i2c_read()`
line. The streamer kept running untraced and finished its 79
register writes with no observer; the captured log stopped at ~10
lines. That is the empty-trace symptom of #154 - and an inflight
hazard for other V2/V2A sensor families that follow the same probe
pattern.
The memset was redundant - copy_from_process overwrites buf in full
- so just drop it.
Supporting ptrace.c hardening (matches strace's setup):
* PTRACE_O_TRACESYSGOOD + gate syscall stops on (SIGTRAP|0x80).
Defends against a stray real SIGTRAP being processed as a syscall
enter, which would flip per-PID enter/exit parity and corrupt
every subsequent register read.
* PTRACE_O_TRACEEXEC + a PTRACE_EVENT_EXEC handler. Without it the
kernel signals execve completion with a legacy plain SIGTRAP that
the wait loop would inject back, killing the tracee.
* Drop the redundant PTRACE_ATTACH on the main tracee - it always
returned EPERM because the child PTRACE_TRACEME'd itself first.
* Drop the early `ptrace(PTRACE_SYSCALL, new_child, 0, 0)` in the
CLONE/FORK/VFORK handler - it raced with the kernel's auto-attach
and is unnecessary because the new tracee's SIGSTOP arrives
through the wait loop on its own.
* NULL-guard `syscall_open` against `copy_from_process_str()`
failure (would otherwise NULL-deref in strcmp/IS_PREFIX).
New diagnostic env knob:
* `IPCTOOL_TRACE_DEBUG=1` makes `syscall_open` and `syscall_write_exit`
log to stderr (filename, fd, callback wired). Off by default,
zero overhead unless set. Used to triage cases where /proc/<pid>/fd
shows a device open but the trace contains no banner/writes for it.
New segmenter pattern:
* `tools/trace_segment.py` adds `soi_jx` (reg 0x12, init=0x40,
stream-on=0x00) for SOI/JX 8-bit-register sensors (JXF22, JXF23,
JXH62, ...). Tried after smartsens/sony_imx so existing detection
is unchanged.
Documentation:
* `docs/sensor-driver-extraction.md`: document the segfault-induced
empty trace in "When the trace is empty anyway" with a core-dump
+ gdb recipe; document `IPCTOOL_TRACE_DEBUG=1` in Troubleshooting;
add the soi_jx row to the family table.
Verification (Definition-of-Done from #154):
[x] Hi3518EV200 + Majestic + libsns_jxf22.so capture: 79 writes
(target >=50, matches strace -f baseline).
[x] tools/trace_segment.py emits init_pattern=soi_jx with 75 init
events (was 0).
[x] tools/trace_to_driver.py emits jxf22_linear_init that passes
`gcc -Wall -Wextra -fsyntax-only`.
[x] tools/trace_diff.py vs OpenIPC/glutinium hi35xx_sensor_jxf22
reports 96.1% address / 100% value match (target >=90/>=80).
[x] tools/test_pipeline.sh (CI) still passes.
[x] SC2315E pattern detection unchanged: synthetic SmartSens
trace still hits init_pattern=smartsens (soi_jx is tried
after smartsens). Trace_to_driver/trace_diff scripts are
unchanged so an unchanged SC2315E trace produces an
unchanged diff. End-to-end re-verification on real SC2315E
hardware not run (no access from this environment).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 6084896 commit 3646e40
3 files changed
Lines changed: 111 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
| 312 | + | |
312 | 313 | | |
313 | 314 | | |
314 | 315 | | |
| |||
350 | 351 | | |
351 | 352 | | |
352 | 353 | | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
353 | 376 | | |
354 | 377 | | |
355 | 378 | | |
| |||
695 | 718 | | |
696 | 719 | | |
697 | 720 | | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
698 | 736 | | |
699 | 737 | | |
700 | 738 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| 103 | + | |
103 | 104 | | |
104 | 105 | | |
105 | 106 | | |
| |||
503 | 504 | | |
504 | 505 | | |
505 | 506 | | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
506 | 516 | | |
507 | | - | |
508 | 517 | | |
509 | 518 | | |
510 | 519 | | |
| |||
916 | 925 | | |
917 | 926 | | |
918 | 927 | | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
919 | 931 | | |
920 | 932 | | |
921 | 933 | | |
922 | 934 | | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
923 | 942 | | |
924 | 943 | | |
925 | 944 | | |
| |||
1010 | 1029 | | |
1011 | 1030 | | |
1012 | 1031 | | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
1013 | 1041 | | |
1014 | 1042 | | |
1015 | 1043 | | |
| |||
1173 | 1201 | | |
1174 | 1202 | | |
1175 | 1203 | | |
| 1204 | + | |
1176 | 1205 | | |
1177 | 1206 | | |
1178 | | - | |
1179 | | - | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
1180 | 1210 | | |
1181 | 1211 | | |
1182 | 1212 | | |
| |||
1189 | 1219 | | |
1190 | 1220 | | |
1191 | 1221 | | |
1192 | | - | |
1193 | | - | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
1194 | 1237 | | |
1195 | 1238 | | |
1196 | 1239 | | |
| |||
1212 | 1255 | | |
1213 | 1256 | | |
1214 | 1257 | | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
1215 | 1266 | | |
1216 | 1267 | | |
1217 | 1268 | | |
| |||
1231 | 1282 | | |
1232 | 1283 | | |
1233 | 1284 | | |
1234 | | - | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
1235 | 1294 | | |
1236 | 1295 | | |
1237 | 1296 | | |
| |||
1258 | 1317 | | |
1259 | 1318 | | |
1260 | 1319 | | |
1261 | | - | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
1262 | 1325 | | |
1263 | 1326 | | |
1264 | 1327 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
135 | 138 | | |
136 | 139 | | |
137 | 140 | | |
| |||
0 commit comments