| 1 |
#!/bin/bash |
| 2 |
# |
| 3 |
# Check that utilities reach the kernel through libc symbols rather than raw |
| 4 |
# syscalls. |
| 5 |
# |
| 6 |
# LD_PRELOAD wrappers (fakeroot, fakechroot, pseudo) are an essential part of |
| 7 |
# distribution build tooling, and they interpose libc symbols. A hand-written |
| 8 |
# syscall(2) goes around them: the change lands on disk, but their bookkeeping |
| 9 |
# never sees it, so every later stat() reports the old state -- silently, with |
| 10 |
# an empty stderr and exit status 0 (issue #14028). |
| 11 |
# |
| 12 |
# spell-checker:ignore fakeroot fakechroot |
| 13 |
|
| 14 |
set -e |
| 15 |
|
| 16 |
echo "=== libc Interposition Verification ===" |
| 17 |
|
| 18 |
# shellcheck disable=SC2034 # read by check-common.sh once sourced |
| 19 |
CHECK_UTILS="chmod chown" |
| 20 |
. "$(dirname "${BASH_SOURCE[0]}")/check-common.sh" |
| 21 |
|
| 22 |
require_command fakeroot |
| 23 |
|
| 24 |
# Run a utility under fakeroot and compare what fakeroot's database reports |
| 25 |
# afterwards against what the utility asked for. A raw syscall leaves the |
| 26 |
# database stale, so the observed value is the one from before the run. |
| 27 |
# |
| 28 |
# $1 test name, $2 command to run (relative to the tree), $3 stat format, |
| 29 |
# $4 expected value |
| 30 |
assert_visible_under_fakeroot() { |
| 31 |
local name="$1" cmd="$2" format="$3" expected="$4" observed tree |
| 32 |
|
| 33 |
tree="$TEMP_DIR/$name" |
| 34 |
mkdir -p "$tree/vendor" |
| 35 |
|
| 36 |
# The chown makes fakeroot track both inodes, so what it reports back comes |
| 37 |
# from its database rather than straight from the filesystem. |
| 38 |
observed=$(cd "$tree" && fakeroot sh -c \ |
| 39 |
"$CHOWN_CMD -R 7:11 . && $cmd && /usr/bin/stat -c $format vendor") |
| 40 |
|
| 41 |
if [ "$observed" != "$expected" ]; then |
| 42 |
fail_immediately "$name: fakeroot reports '$observed', expected '$expected' -- the change must go through a libc symbol, not a raw syscall (issue #14028)" |
| 43 |
fi |
| 44 |
echo "✓ $name is visible to LD_PRELOAD wrappers" |
| 45 |
} |
| 46 |
|
| 47 |
# chown itself is the vehicle for every other check, so it has to be present. |
| 48 |
CHOWN_CMD=$(util_cmd chown) || { |
| 49 |
echo "Error: chown was not built, cannot set up the checks." |
| 50 |
echo "Build it with 'cargo build --profile=${PROFILE} -p uu_chmod -p uu_chown'" |
| 51 |
exit 1 |
| 52 |
} |
| 53 |
assert_visible_under_fakeroot "chown -R" "true" "%u:%g" "7:11" |
| 54 |
|
| 55 |
if CHMOD_CMD=$(util_cmd chmod); then |
| 56 |
assert_visible_under_fakeroot "chmod -R" "$CHMOD_CMD -R 2751 ." "%a" "2751" |
| 57 |
else |
| 58 |
echo "⚠ chmod not built, skipping" |
| 59 |
fi |
| 60 |
|
| 61 |
echo "" |
| 62 |
echo "=== Summary ===" |
| 63 |
echo "All checked utilities go through libc!" |