28 Commits

Author SHA1 Message Date
Luke Parker
a8ca3ea1dd Restore path specifications for when the stack size CI should be run
Also schedules a weekly run to ensure this doesn't inadvertently decay.
2025-12-09 00:55:16 -05:00
Luke Parker
bd6e4271e4 Add || true to handle how cmp was returning a non-zero code for the (expectedly) different files 2025-12-09 00:48:59 -05:00
Luke Parker
1ed4261cf0 Debug cmp call in CI 2025-12-09 00:42:31 -05:00
Luke Parker
6dffe8e805 Add debugging statements to figure where the CI workflow is erroring 2025-12-09 00:33:36 -05:00
Luke Parker
af085ba9c1 Remove head -c for cut, as head -c is not POSIX-compliant
`tail -c` is however. Since we used `head -c-`, to cut off characters from the
end, the POSIX-compliant `wc -c` is used for a `strlen` we can proceed to do
the necessary arithmetic off of.

Credit to @PlasmaPower for identifying this non-compliant behavior which
necessitated this fix in response.
2025-12-09 00:31:09 -05:00
Luke Parker
d881421e7e Extend debugging when comparing SHA-256 hashes 2025-12-09 00:06:06 -05:00
Luke Parker
48914aad0a Once again fix read_stack 2025-12-08 23:58:18 -05:00
Luke Parker
7d6bac9ab4 yash, brush shells 2025-12-08 23:52:36 -05:00
Luke Parker
dcb8cbad0d Correct read_stack function 2025-12-08 23:38:42 -05:00
Luke Parker
8ad88dce9a Remove non-POSIX tcsh from list of shells 2025-12-08 23:30:51 -05:00
Luke Parker
63133ae530 Call the shells via a sh symlink to trigger their POSIX-compliant behavior (if special-cased based on how the shell was invoked) 2025-12-08 23:22:55 -05:00
Luke Parker
1ab1cad7c5 Correct order symlinks are created in 2025-12-08 22:59:42 -05:00
Luke Parker
8a5cce2ce8 Use symlinks for ash, add hush 2025-12-08 22:57:56 -05:00
Luke Parker
ec0347a73e Alias ash since the busybox package on Ubuntu doesn't provide such a symlink 2025-12-08 22:52:43 -05:00
Luke Parker
6d2a496054 Prune output of sha256sum to the hash alone
This causes the equality not to fail simply because the file names are
different.
2025-12-08 22:50:12 -05:00
Luke Parker
48a3cf5027 Fix POSIX compliance of increase_default_stack_size.sh
It turns out `\xXX` is not part of POSIX. The Octal `\ddd` is however, and is
used here.
2025-12-08 22:47:10 -05:00
Luke Parker
34dbfedc5a Expand the amount of shells tested with 2025-12-08 21:09:56 -05:00
Luke Parker
f4efa76e3f ./chelf instead of chelf 2025-12-08 20:57:23 -05:00
Luke Parker
19c18af086 Explicitly call ./muslstack instead of muslstack 2025-12-08 20:55:52 -05:00
Luke Parker
b0e40cae58 Add debug ls command 2025-12-08 20:54:42 -05:00
Luke Parker
606e67f937 Set GOBIN env variable 2025-12-08 20:53:21 -05:00
Luke Parker
fee3e2fa21 go get -> go install 2025-12-08 20:51:09 -05:00
Luke Parker
52cbc90876 Update stack size CI to only run on Linux runners 2025-12-08 20:50:01 -05:00
Luke Parker
1f39eb16c8 Remove _all_ paths scoping for the stack size CI for now 2025-12-08 20:46:01 -05:00
Luke Parker
fbe515cf9b Have stack size CI run whenever it itself is modified 2025-12-08 20:44:13 -05:00
Luke Parker
1cb6cb608f Remove paths argument from workflow_dispatch trigger 2025-12-08 20:41:25 -05:00
Luke Parker
881353fb4a Correction action definition in stack size CI 2025-12-08 20:40:22 -05:00
Luke Parker
a5f8ce9ec6 Add CI to verify increase_default_stack_size.sh functions as expected 2025-12-08 20:36:43 -05:00
4 changed files with 110 additions and 8 deletions

View File

@@ -62,7 +62,7 @@ runs:
docker system prune -a --volumes
sudo apt remove -y *docker*
# Install uidmap which will be required for the explicitly installed Docker
sudo apt install uidmap
sudo apt install -y uidmap
if: runner.os == 'Linux'
- name: Update system dependencies

View File

@@ -208,7 +208,7 @@ jobs:
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # 6.0.0
- name: shellcheck
run: |
sudo apt install shellcheck
sudo apt install -y shellcheck
find . -iname "*.sh" | while read -r script; do
shellcheck --enable=all --shell=sh --severity=info $script
done

93
.github/workflows/stack_size.yml vendored Normal file
View File

@@ -0,0 +1,93 @@
name: Check Update Default Stack Size
on:
push:
paths:
- "orchestration/increase_default_stack_size.sh"
pull_request:
paths:
- "orchestration/increase_default_stack_size.sh"
workflow_dispatch:
# Also run weekly to ensure this doesn't inadvertently decay
schedule:
- cron: "0 0 * * 1"
jobs:
stack_size:
strategy:
matrix:
os: [ubuntu-latest, ubuntu-24.04, ubuntu-22.04]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # 6.0.0
- name: Download Monero
uses: ./.github/actions/monero
- name: Verify expected behavior
shell: bash
run: |
cp /usr/bin/monerod monerod
STACK=$((8 * 1024 * 1024))
cp monerod monerod-chelf
git clone https://github.com/Gottox/chelf
cd chelf
git checkout b2994186cea7b7d61a588fd06c1cc1ae75bcc21a
make
./chelf -s $STACK ../monerod-chelf
cd ..
cp monerod monerod-muslstack
GOBIN=$(pwd) go install github.com/yaegashi/muslstack@d19cc5866abce3ca59dfc1666df7cc97097d0933
./muslstack -s $STACK ./monerod-muslstack
sudo apt update -y
sudo apt install -y ksh bash dash zsh busybox mksh yash
sudo ln -s $(which busybox) /usr/bin/ash
sudo ln -s $(which busybox) /usr/bin/hush
cargo install brush-shell
for shell in sh ksh bash dash zsh ash hush mksh yash brush; do
cp monerod monerod-idss-$shell
ln -s $(which $shell) sh
./sh ./orchestration/increase_default_stack_size.sh monerod-idss-$shell
rm ./sh
done
sha256() {
sha256sum "$1" | cut -d' ' -f1
}
CHELF=$(sha256 monerod-chelf)
find . -iname "monerod-*" | while read -r bin; do
BIN=$(sha256 "$bin")
if [ ! "$CHELF" = "$BIN" ]; then
echo "Different artifact between monerod-chelf ($CHELF) and $bin ($BIN)"
exit 1
fi
done
read_stack() {
STACK_INFO=$(readelf "$1" -l | grep STACK -A1)
MEMSZ=$(echo "$STACK_INFO" | tail -n1 | sed -E s/^[[:space:]]*//g | cut -f2 -d' ')
printf "%i" $((MEMSZ))
}
INITIAL_STACK=$(read_stack monerod)
if [ "$INITIAL_STACK" -ne "0" ]; then
echo "Initial \`PT_GNU_STACK\` wasn't 0"
exit 2
fi
UPDATED_STACK=$(read_stack monerod-chelf)
if [ "$UPDATED_STACK" -ne "$STACK" ]; then
echo "Updated \`PT_GNU_STACK\` ($UPDATED_STACK) wasn't 8 MB ($STACK)"
exit 3
fi
# Only one byte should be different due to the bit pattern of 8 MB
BYTES_DIFFERENT=$(cmp -l monerod monerod-chelf | wc -l || true)
if [ "$BYTES_DIFFERENT" -ne 1 ]; then
echo "More than one byte was different between the two binaries"
exit 4
fi

View File

@@ -26,23 +26,28 @@ hex() {
read_bytes() {
dd bs=1 skip="$1" count="$2" if="$ELF" 2> /dev/null | hex
}
hex_to_octal() {
printf "ibase=16; obase=8; %s\n" "$1" | bc
}
write_bytes() {
POS=$1
BYTES=$2
while [ ! "$BYTES" = "" ]; do
NEXT=$(printf "%s" "$BYTES" | head -c2)
NEXT=$(printf "%s" "$BYTES" | cut -c-2)
# Advance to the third byte, as in, after the first two bytes
BYTES=$(printf "%s" "$BYTES" | tail -c+3)
NEXT=$(hex_to_octal "$NEXT")
# shellcheck disable=SC2059
printf "\x$NEXT" | dd conv=notrunc bs=1 seek="$POS" of="$ELF" 2> /dev/null
printf \\"$NEXT" | dd conv=notrunc bs=1 seek="$POS" of="$ELF" 2> /dev/null
POS=$((POS + 1))
done
}
# Magic
MAGIC=$(read_bytes 0 4)
EXPECTED_MAGIC=$(printf "\x7ELF" | hex)
# shellcheck disable=SC2059
EXPECTED_MAGIC=$(printf \\"$(hex_to_octal 7F)"ELF | hex)
if [ ! "$MAGIC" = "$EXPECTED_MAGIC" ]; then
echo "Not ELF"
exit 2
@@ -101,9 +106,13 @@ swap_native_endian() {
return
fi
while [ ! "$BYTES" = "" ]; do
while :; do
printf "%s" "$BYTES" | tail -c2
BYTES=$(printf "%s" "$BYTES" | head -c-2)
NEW_LENGTH=$(( $(printf "%s" "$BYTES" | wc -c) - 2 ))
if [ "$NEW_LENGTH" -eq 0 ]; then
break
fi
BYTES=$(printf "%s" "$BYTES" | cut -c-$NEW_LENGTH)
done
}
@@ -144,7 +153,7 @@ while [ "$NEXT_PROGRAM_HEADER" -ne -1 ]; do
NEXT_PROGRAM_HEADER=$(( NEXT_PROGRAM_HEADER - 1 ))
PROGRAM_HEADER=$(read_program_header "$THIS_PROGRAM_HEADER")
HEADER_TYPE=$(printf "%s" "$PROGRAM_HEADER" | head -c8)
HEADER_TYPE=$(printf "%s" "$PROGRAM_HEADER" | cut -c-8)
HEADER_TYPE=$(swap_native_endian "$HEADER_TYPE")
# `PT_GNU_STACK`
# https://github.com/torvalds/linux/blob/c2f2b01b74be8b40a2173372bcd770723f87e7b2/include/uapi/linux/elf.h#L41