fix(sondib): repair SID lookup control flow
- Jump into the initialized track lookup loop before checking deletion state. - Apply the binary fix at image build time and remove the concurrent cleaner.
This commit is contained in:
1 parent
1963df2802
commit
10aa91c067
2 files changed
+24
-5
No files matched your search
+8
-1
@@ -1,12 +1,19 @@
|
||||
FROM python:3.11-slim-bookworm AS patcher
|
||||
|
||||
COPY patch_sondibd.py /patch/
|
||||
COPY bin/sondibd /patch/sondibd
|
||||
RUN python3 /patch/patch_sondibd.py /patch/sondibd
|
||||
|
||||
FROM debian:bookworm-slim
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends libc6 util-linux passwd && rm -rf /var/lib/apt/lists/* && useradd --system --uid 10010 --user-group --home-dir /data --shell /usr/sbin/nologin sondib && mkdir -p /data/uploads && chown -R 10010:10010 /data
|
||||
|
||||
WORKDIR /app
|
||||
COPY bin/ /app/bin/
|
||||
COPY --from=patcher /patch/sondibd /app/bin/sondibd
|
||||
RUN chmod 0755 /app/bin/*
|
||||
|
||||
WORKDIR /data
|
||||
EXPOSE 7777
|
||||
|
||||
ENTRYPOINT ["/bin/sh", "-c", "( while :; do setpriv --reuid=sondib --regid=sondib --clear-groups /app/bin/sdclean /data; sleep 10; done ) & mkdir -p /data/uploads && chown -R sondib:sondib /data && trap 'exit 0' TERM INT; while :; do setpriv --reuid=sondib --regid=sondib --clear-groups /app/bin/sondibd; rc=$?; echo \"sondibd exited with code $rc; restarting in 1s\" >&2; sleep 1; done"]
|
||||
ENTRYPOINT ["/bin/sh", "-c", "mkdir -p /data/uploads && chown -R sondib:sondib /data && trap 'exit 0' TERM INT; while :; do setpriv --reuid=sondib --regid=sondib --clear-groups /app/bin/sondibd; rc=$?; echo \"sondibd exited with code $rc; restarting in 1s\" >&2; sleep 1; done"]
|
||||
+16
-4
@@ -14,6 +14,7 @@ from pathlib import Path
|
||||
|
||||
TEXT_VA_BASE = 0x400000
|
||||
GUARD_VA = 0x404120
|
||||
ENTRY_VA = 0x40410A
|
||||
MATCH_VA = 0x404154
|
||||
GUARD_SIZE = 0x20
|
||||
|
||||
@@ -23,6 +24,8 @@ OLD_GUARD = bytes.fromhex(
|
||||
"66 2e 0f 1f 84 00 00 00 00 00"
|
||||
)
|
||||
OLD_BRANCH = bytes.fromhex("74 0e")
|
||||
ENTRY_JUMP = bytes.fromhex("eb 34")
|
||||
OLD_ENTRY = OLD_GUARD[:len(ENTRY_JUMP)]
|
||||
|
||||
|
||||
def file_offset(virtual_address: int) -> int:
|
||||
@@ -33,19 +36,27 @@ def patch(path: Path) -> None:
|
||||
data = bytearray(path.read_bytes())
|
||||
guard_offset = file_offset(GUARD_VA)
|
||||
match_offset = file_offset(MATCH_VA)
|
||||
entry_offset = file_offset(ENTRY_VA)
|
||||
guard = bytes(data[guard_offset:guard_offset + GUARD_SIZE])
|
||||
branch = bytes(data[match_offset:match_offset + len(OLD_BRANCH)])
|
||||
entry = bytes(data[entry_offset:entry_offset + len(ENTRY_JUMP)])
|
||||
|
||||
if branch == bytes.fromhex("74 ca"):
|
||||
changed = False
|
||||
if entry == OLD_ENTRY:
|
||||
data[entry_offset:entry_offset + len(ENTRY_JUMP)] = ENTRY_JUMP
|
||||
changed = True
|
||||
elif entry != ENTRY_JUMP:
|
||||
raise SystemExit(f"unexpected sondibd entry bytes in {path}")
|
||||
# Upgrade the first revision: returning NULL immediately made callers
|
||||
# that probe an old SID take a slow error path. Skipping the deleted
|
||||
# record preserves the original search contract and is safe if a SID
|
||||
# was ever duplicated in the in-memory table.
|
||||
# that probe an old SID take a slow error path.
|
||||
if data[guard_offset + 7:guard_offset + 9] == bytes.fromhex("75 39"):
|
||||
data[guard_offset + 7:guard_offset + 9] = bytes.fromhex("75 2d")
|
||||
changed = True
|
||||
if changed:
|
||||
path.write_bytes(data)
|
||||
return
|
||||
if branch != OLD_BRANCH or guard != OLD_GUARD:
|
||||
if branch != OLD_BRANCH or guard != OLD_GUARD or entry != OLD_ENTRY:
|
||||
raise SystemExit(f"unexpected sondibd bytes in {path}")
|
||||
|
||||
# je 0x404120; then skip track+0x21d when it is non-zero.
|
||||
@@ -54,6 +65,7 @@ def patch(path: Path) -> None:
|
||||
"75 2d " # jne 0x404156 (continue the search)
|
||||
"48 89 c8 c3" # mov rax, rcx; ret
|
||||
)
|
||||
data[entry_offset:entry_offset + len(ENTRY_JUMP)] = ENTRY_JUMP
|
||||
data[guard_offset:guard_offset + GUARD_SIZE] = guard_code.ljust(GUARD_SIZE, b"\x90")
|
||||
data[match_offset:match_offset + len(OLD_BRANCH)] = bytes.fromhex("74 ca")
|
||||
path.write_bytes(data)
|
||||
|
||||
Reference in new issue
Block a user