Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: run sanitizers #955

Merged
merged 42 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
1e5d6ef
ci: run sanitizers
dunglas Aug 5, 2024
00a0fd5
debug
dunglas Aug 6, 2024
1c15012
debug
dunglas Aug 6, 2024
2973bc7
test
dunglas Aug 6, 2024
0161c8c
test
dunglas Aug 6, 2024
f6a3592
test
dunglas Aug 6, 2024
4921370
test
dunglas Aug 6, 2024
1b11eba
test
dunglas Aug 6, 2024
02ffaaf
test
dunglas Aug 6, 2024
0215f8e
test
dunglas Aug 6, 2024
b6c866e
test
dunglas Aug 6, 2024
de47916
try without -shared-libasan
dunglas Aug 7, 2024
27083bb
more tests
dunglas Aug 7, 2024
b180394
cleanup
dunglas Aug 7, 2024
2963674
suppr
dunglas Aug 7, 2024
8cfa273
try without ASAN
dunglas Aug 7, 2024
66ca769
try without ASAN
dunglas Aug 7, 2024
8ded8d2
try without ASAN
dunglas Aug 8, 2024
f9fcb2c
try without ASAN
dunglas Aug 8, 2024
44577b4
try without ASAN
dunglas Aug 8, 2024
a17ddaf
try without ASAN
dunglas Aug 8, 2024
e1ca367
add back ASAN
dunglas Aug 8, 2024
338c3da
wip
dunglas Aug 8, 2024
754ef94
wip
dunglas Aug 8, 2024
57af913
MSAN
dunglas Aug 8, 2024
e3fc910
wip
dunglas Aug 8, 2024
07ffa2c
add buffer overflow
dunglas Aug 8, 2024
cd9a98d
print as much details as possible
dunglas Aug 8, 2024
2c4db04
fix ldflags
dunglas Aug 8, 2024
064fc19
simplify flags
dunglas Aug 8, 2024
118676b
fix flags
dunglas Aug 9, 2024
db24209
fix flags
dunglas Aug 9, 2024
5e4777a
wip
dunglas Aug 9, 2024
bdd74f2
wip
dunglas Aug 9, 2024
c5b9cb5
wip
dunglas Aug 9, 2024
15db0d2
cleanup
dunglas Aug 9, 2024
5931016
disable more things
dunglas Aug 9, 2024
ca26934
test without cache
dunglas Aug 9, 2024
ea245a6
fix
dunglas Aug 9, 2024
6d1b870
cleanup
dunglas Aug 9, 2024
089df41
add ZEND_RC_DEBUG
dunglas Aug 9, 2024
e69ce22
fix
dunglas Aug 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions .github/workflows/sanitizers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
---
name: Sanitizers
on:
pull_request:
branches:
- main
paths-ignore:
- 'docs/**'
push:
branches:
- main
paths-ignore:
- 'docs/**'
permissions:
contents: read
jobs:
# Adapted from https://github.com/beberlei/hdrhistogram-php
sanitizers:
name: ${{ matrix.sanitizer }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sanitizer: ['asan', 'msan']
env:
CFLAGS: -g -O0 -fsanitize=${{ matrix.sanitizer == 'asan' && 'address' || 'memory' }} -DZEND_TRACK_ARENA_ALLOC
LDFLAGS: -fsanitize=${{ matrix.sanitizer == 'asan' && 'address' || 'memory' }}
CC: clang
CXX: clang++
USE_ZEND_ALLOC: 0
LIBRARY_PATH: ${{ github.workspace }}/php/target/lib
LD_LIBRARY_PATH: ${{ github.workspace }}/php/target/lib
steps:
-
name: Remove local PHP
run: sudo apt-get remove --purge --autoremove 'php*' 'libmemcached*'
-
uses: actions/checkout@v4
-
uses: actions/setup-go@v5
with:
go-version: '1.22'
cache-dependency-path: |
go.sum
caddy/go.sum
-
name: Determine PHP version
id: determine-php-version
run: |
curl -fsSL 'https://www.php.net/releases/index.php?json&max=1&version=8.3' -o version.json
echo version="$(jq -r 'keys[0]' version.json)" >> "$GITHUB_OUTPUT"
echo archive="$(jq -r '.[] .source[] | select(.filename |endswith(".xz")) | "https://www.php.net/distributions/" + .filename' version.json)" >> "$GITHUB_OUTPUT"
-
name: Cache PHP
id: cache-php
uses: actions/cache@v4
with:
path: php/target
key: php-sanitizers-${{ matrix.sanitizer }}-${{ runner.arch }}-${{ steps.determine-php-version.outputs.version }}
-
if: steps.cache-php.outputs.cache-hit != 'true'
name: Compile PHP
run: |
mkdir php/
curl -fsSL "${{ steps.determine-php-version.outputs.archive }}" | tar -Jx -C php --strip-components=1
cd php/
./configure \
CFLAGS="$CFLAGS" \
LDFLAGS="$LDFLAGS" \
--enable-debug \
--enable-embed \
--enable-zts \
--enable-option-checking=fatal \
--disable-zend-signals \
--without-sqlite3 \
--without-pdo-sqlite \
--without-libxml \
--disable-dom \
--disable-simplexml \
--disable-xml \
--disable-xmlreader \
--disable-xmlwriter \
--without-pcre-jit \
--disable-opcache-jit \
--disable-cli \
--disable-cgi \
--disable-phpdbg \
--without-pear \
--disable-mbregex \
--enable-werror \
${{ matrix.sanitizer == 'msan' && '--enable-memory-sanitizer' || '' }} \
--prefix="$(pwd)/target/"
make -j"$(getconf _NPROCESSORS_ONLN)"
sudo make install
-
name: Add PHP to the PATH
run: echo "$(pwd)/php/target/bin" >> "$GITHUB_PATH"
-
name: Set Set CGO flags
run: |
{
echo "CGO_CFLAGS=$CFLAGS $(php-config --includes)"
echo "CGO_LDFLAGS=$LDFLAGS $(php-config --ldflags) $(php-config --libs)"
} >> "$GITHUB_ENV"
-
name: Compile tests
run: go test -${{ matrix.sanitizer }} -v -x -c
-
name: Run tests
run: ./frankenphp.test -test.v
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
echo '<?php phpinfo();' > /app/public/index.php

COPY --link caddy/frankenphp/Caddyfile /etc/caddy/Caddyfile
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/

Check warning on line 27 in Dockerfile

View workflow job for this annotation

GitHub Actions / build (php-8-2-22-bookworm, linux/386)

Base image platform does not match expected target platform

InvalidBaseImagePlatform: Base image mlocati/php-extension-installer was pulled with platform "linux/amd64", expected "linux/386" for current build

Check warning on line 27 in Dockerfile

View workflow job for this annotation

GitHub Actions / build (php-8-2-22-bookworm, linux/arm/v7)

Base image platform does not match expected target platform

InvalidBaseImagePlatform: Base image mlocati/php-extension-installer was pulled with platform "linux/amd64", expected "linux/arm/v7" for current build

Check warning on line 27 in Dockerfile

View workflow job for this annotation

GitHub Actions / build (php-8-2-22-bookworm, linux/arm64)

Base image platform does not match expected target platform

InvalidBaseImagePlatform: Base image mlocati/php-extension-installer was pulled with platform "linux/amd64", expected "linux/arm64" for current build

Check warning on line 27 in Dockerfile

View workflow job for this annotation

GitHub Actions / build (php-8-3-10-bookworm, linux/386)

Base image platform does not match expected target platform

InvalidBaseImagePlatform: Base image mlocati/php-extension-installer was pulled with platform "linux/amd64", expected "linux/386" for current build

Check warning on line 27 in Dockerfile

View workflow job for this annotation

GitHub Actions / build (php-8-3-10-bookworm, linux/arm/v7)

Base image platform does not match expected target platform

InvalidBaseImagePlatform: Base image mlocati/php-extension-installer was pulled with platform "linux/amd64", expected "linux/arm/v7" for current build

Check warning on line 27 in Dockerfile

View workflow job for this annotation

GitHub Actions / build (php-8-3-10-bookworm, linux/arm64)

Base image platform does not match expected target platform

InvalidBaseImagePlatform: Base image mlocati/php-extension-installer was pulled with platform "linux/amd64", expected "linux/arm64" for current build

CMD ["--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"]
HEALTHCHECK CMD curl -f http://localhost:2019/metrics || exit 1
Expand Down Expand Up @@ -86,9 +86,10 @@
COPY --link internal internal
COPY --link testdata testdata

# todo: automate this?
# see https://github.com/docker-library/php/blob/master/8.2/bookworm/zts/Dockerfile#L57-L59 for PHP values
ENV CGO_LDFLAGS="-lssl -lcrypto -lreadline -largon2 -lcurl -lonig -lz $PHP_LDFLAGS" CGO_CFLAGS="-DFRANKENPHP_VERSION=$FRANKENPHP_VERSION $PHP_CFLAGS" CGO_CPPFLAGS=$PHP_CPPFLAGS
# See https://github.com/docker-library/php/blob/master/8.3/bookworm/zts/Dockerfile#L57-L59 for PHP values
ENV CGO_CFLAGS="-DFRANKENPHP_VERSION=$FRANKENPHP_VERSION $PHP_CFLAGS"
ENV CGO_CPPFLAGS=$PHP_CPPFLAGS
ENV CGO_LDFLAGS="-lssl -lcrypto -lreadline -largon2 -lcurl -lonig -lz $PHP_LDFLAGS"

WORKDIR /go/src/app/caddy/frankenphp
RUN GOBIN=/usr/local/bin go install -ldflags "-w -s -X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION PHP $PHP_VERSION Caddy'" && \
Expand Down
7 changes: 4 additions & 3 deletions alpine.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
echo '<?php phpinfo();' > /app/public/index.php

COPY --link caddy/frankenphp/Caddyfile /etc/caddy/Caddyfile
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/

Check warning on line 26 in alpine.Dockerfile

View workflow job for this annotation

GitHub Actions / build (php-8-2-22-alpine, linux/386)

Base image platform does not match expected target platform

InvalidBaseImagePlatform: Base image mlocati/php-extension-installer was pulled with platform "linux/amd64", expected "linux/386" for current build

Check warning on line 26 in alpine.Dockerfile

View workflow job for this annotation

GitHub Actions / build (php-8-2-22-alpine, linux/arm/v7)

Base image platform does not match expected target platform

InvalidBaseImagePlatform: Base image mlocati/php-extension-installer was pulled with platform "linux/amd64", expected "linux/arm/v7" for current build

Check warning on line 26 in alpine.Dockerfile

View workflow job for this annotation

GitHub Actions / build (php-8-2-22-alpine, linux/arm64)

Base image platform does not match expected target platform

InvalidBaseImagePlatform: Base image mlocati/php-extension-installer was pulled with platform "linux/amd64", expected "linux/arm64" for current build

Check warning on line 26 in alpine.Dockerfile

View workflow job for this annotation

GitHub Actions / build (php-8-3-10-alpine, linux/386)

Base image platform does not match expected target platform

InvalidBaseImagePlatform: Base image mlocati/php-extension-installer was pulled with platform "linux/amd64", expected "linux/386" for current build

Check warning on line 26 in alpine.Dockerfile

View workflow job for this annotation

GitHub Actions / build (php-8-3-10-alpine, linux/arm/v7)

Base image platform does not match expected target platform

InvalidBaseImagePlatform: Base image mlocati/php-extension-installer was pulled with platform "linux/amd64", expected "linux/arm/v7" for current build

Check warning on line 26 in alpine.Dockerfile

View workflow job for this annotation

GitHub Actions / build (php-8-3-10-alpine, linux/arm64)

Base image platform does not match expected target platform

InvalidBaseImagePlatform: Base image mlocati/php-extension-installer was pulled with platform "linux/amd64", expected "linux/arm64" for current build

CMD ["--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"]
HEALTHCHECK CMD curl -f http://localhost:2019/metrics || exit 1
Expand Down Expand Up @@ -104,9 +104,10 @@
COPY --link internal internal
COPY --link testdata testdata

# todo: automate this?
# see https://github.com/docker-library/php/blob/master/8.2/bookworm/zts/Dockerfile#L57-L59 for php values
ENV CGO_LDFLAGS="-lssl -lcrypto -lreadline -largon2 -lcurl -lonig -lz $PHP_LDFLAGS" CGO_CFLAGS="-DFRANKENPHP_VERSION=$FRANKENPHP_VERSION $PHP_CFLAGS" CGO_CPPFLAGS=$PHP_CPPFLAGS
# See https://github.com/docker-library/php/blob/master/8.3/alpine3.20/zts/Dockerfile#L53-L55
ENV CGO_CFLAGS="-DFRANKENPHP_VERSION=$FRANKENPHP_VERSION $PHP_CFLAGS"
ENV CGO_CPPFLAGS=$PHP_CPPFLAGS
ENV CGO_LDFLAGS="-lssl -lcrypto -lreadline -largon2 -lcurl -lonig -lz $PHP_LDFLAGS"

WORKDIR /go/src/app/caddy/frankenphp
RUN GOBIN=/usr/local/bin go install -ldflags "-w -s -extldflags '-Wl,-z,stack-size=0x80000' -X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION PHP $PHP_VERSION Caddy'" && \
Expand Down
6 changes: 6 additions & 0 deletions build-static.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,20 @@ else
./bin/spc build --debug --enable-zts --build-embed ${extraOpts} "${PHP_EXTENSIONS}" --with-libs="${PHP_EXTENSION_LIBS}"
fi

# See https://github.com/docker-library/php/blob/master/8.3/alpine3.20/zts/Dockerfile#L53-L55
CGO_CFLAGS="-DFRANKENPHP_VERSION=${FRANKENPHP_VERSION} -I${PWD}/buildroot/include/ $(./buildroot/bin/php-config --includes | sed s#-I/#-I"${PWD}"/buildroot/#g)"
if [ -n "${DEBUG_SYMBOLS}" ]; then
CGO_CFLAGS="-g ${CGO_CFLAGS}"
else
CGO_CFLAGS="-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 ${CGO_CFLAGS}"
fi
export CGO_CFLAGS
export CGO_CPPFLAGS="${CGO_CFLAGS}"

if [ "${os}" = "mac" ]; then
export CGO_LDFLAGS="-framework CoreFoundation -framework SystemConfiguration"
elif [ "${os}" = "linux" ] && [ -z "${DEBUG_SYMBOLS}" ]; then
CGO_LDFLAGS="-Wl,-O1 -pie"
fi

CGO_LDFLAGS="${CGO_LDFLAGS} ${PWD}/buildroot/lib/libbrotlicommon.a ${PWD}/buildroot/lib/libbrotlienc.a ${PWD}/buildroot/lib/libbrotlidec.a $(./buildroot/bin/php-config --ldflags || true) $(./buildroot/bin/php-config --libs || true)"
Expand Down
7 changes: 2 additions & 5 deletions frankenphp.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ package frankenphp
// We also set these flags for hardening: https://github.com/docker-library/php/blob/master/8.2/bookworm/zts/Dockerfile#L57-L59

// #cgo darwin pkg-config: libxml-2.0
// #cgo CFLAGS: -Wall -Werror -fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
// #cgo CFLAGS: -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib
// #cgo CFLAGS: -DTHREAD_NAME=frankenphp
// #cgo linux CFLAGS: -D_GNU_SOURCE
// #cgo CPPFLAGS: -fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
// #cgo darwin LDFLAGS: -L/opt/homebrew/opt/libiconv/lib -liconv
// #cgo linux LDFLAGS: -Wl,-O1 -lresolv
// #cgo LDFLAGS: -pie -L/usr/local/lib -L/usr/lib -lphp -ldl -lm -lutil
// #cgo linux LDFLAGS: -lresolv
// #cgo LDFLAGS: -L/usr/local/lib -L/usr/lib -lphp -ldl -lm -lutil
// #include <stdlib.h>
// #include <stdint.h>
// #include <php_variables.h>
Expand Down
Loading