github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/tools/syz-env (about) 1 #!/usr/bin/env bash 2 # Copyright 2020 syzkaller project authors. All rights reserved. 3 # Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 4 5 # syz-env is a wrapper around gcr.io/syzkaller/env container, 6 # which includes all tools necessary to develop/test syzkaller. 7 # It's recommended to create an alias for this script: 8 # 9 # alias syz-env="$(go env GOPATH)/src/github.com/google/syzkaller/tools/syz-env" 10 # 11 # Then it can be used to wrap almost any make invocation as: 12 # 13 # syz-env make format 14 # syz-env make presubmit 15 # syz-env make extract SOURCEDIR=~/linux 16 # 17 # Or you may run the shell inside of the container with just syz-env. 18 # 19 # Note: this way everything runs inside of the container 20 # and uses all tools bundled in the container rather than host tools. 21 # 22 # Note: syz-env assumes a sudo-less Docker is installed, see: 23 # https://docs.docker.com/engine/install 24 # https://docs.docker.com/engine/install/linux-postinstall 25 # (Googlers see go/docker). 26 27 COMMAND="" 28 DOCKERARGS=() 29 for ARG in "$@"; do 30 while IFS='=' read KEY VAL; do 31 # If we have a kernel path passed in, we mount it in the container 32 # at /syzkaller/kernel and fix up SOURCEDIR argument. 33 if [ "$KEY" == "SOURCEDIR" ]; then 34 DOCKERARGS+=" --volume $VAL:/syzkaller/kernel:z" 35 COMMAND+=" SOURCEDIR=/syzkaller/kernel" 36 else 37 COMMAND+=" $ARG" 38 fi 39 done <<< "$ARG" 40 done 41 if [ "$CI" == "" ]; then 42 # This gives interactive shell and allows to abort commands with Ctrl+C. 43 DOCKERARGS+=" -it" 44 fi 45 if [ "$COMMAND" == "" ]; then 46 COMMAND="bash" 47 fi 48 49 SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)" 50 IMAGE="env" 51 if [ "$(basename -- "$0")" == "syz-old-env" ]; then 52 IMAGE="old-env" 53 fi 54 55 # If we're running rootless docker, files owned by the host user appear within the 56 # container as being owned by root. 57 # 58 # If we're running regular rootful docker, we need to specify --user, as otherwise 59 # processes within the container will create files with the wrong ownership. 60 if [ ! "$(docker info -f "{{println .SecurityOptions}}" | grep rootless)" ]; then 61 DOCKERARGS+=" --user $(id -u ${USER}):$(id -g ${USER})" 62 fi 63 64 # Update docker image 65 docker pull -q gcr.io/syzkaller/${IMAGE} 66 67 # Run everything as the host user, this is important for created/modified files. 68 docker run \ 69 --rm \ 70 --volume "$SCRIPT_DIR/..:/syzkaller/gopath/src/github.com/google/syzkaller:z" \ 71 --volume "$HOME/.cache:/syzkaller/.cache:z" \ 72 --volume "/var/run/docker.sock":"/var/run/docker.sock" \ 73 --workdir /syzkaller/gopath/src/github.com/google/syzkaller \ 74 --env HOME=/syzkaller \ 75 --env GOPATH=/syzkaller/gopath:/gopath \ 76 --env FUZZIT_API_KEY \ 77 --env GITHUB_REF \ 78 --env GITHUB_SHA \ 79 --env GITHUB_PR_HEAD_SHA \ 80 --env GITHUB_PR_BASE_SHA \ 81 --env GITHUB_PR_COMMITS \ 82 --env CI \ 83 ${DOCKERARGS[@]} \ 84 gcr.io/syzkaller/${IMAGE} -c "$COMMAND"