Skip to content

Commit

Permalink
Merge branch 'issue458' into ub_check
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan-Jowett committed May 11, 2024
2 parents 19d3869 + e37a7ca commit a5dce52
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 49 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Dependency Review Action
#
# This Action will scan dependency manifest files that change as part of a Pull Request,
# surfacing known-vulnerable versions of the packages declared or updated in the PR.
# Once installed, if the workflow run is marked as required,
# PRs introducing known-vulnerable packages will be blocked from merging.
#
# Source repository: https://github.com/actions/dependency-review-action
name: 'Dependency Review'
on: [pull_request]

permissions:
contents: read

jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
with:
egress-policy: audit

- name: 'Checkout Repository'
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- name: 'Dependency Review'
uses: actions/dependency-review-action@0efb1d1d84fc9633afcdaad14c485cbbc90ef46c # v2.5.1
53 changes: 19 additions & 34 deletions .github/workflows/fuzzing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,32 @@
name: Fuzzing

permissions:
contents: read
contents: write

on:
workflow_call:
inputs:
arch:
description: 'Architecture'
required: true
type: string

platform:
required: true
type: string
schedule: # Run every day at 21:00 UTC
- cron: '00 21 * * *'
workflow_dispatch: # Run manually

jobs:
build:
runs-on: ${{ inputs.platform }}
strategy:
matrix:
platform:
- ubuntu-latest
arch:
- x86_64

runs-on: ${{ matrix.platform }}

steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Initialize CodeQL
if: inputs.build_codeql == true
uses: github/codeql-action/init@d39d31e687223d841ef683f52467bd88e9b21c14
with:
languages: 'cpp'

- name: Generate the cache key
id: cache_key
run: echo "VALUE=platform-${{ inputs.platform }}_arch=${{ inputs.arch }}_type=fuzzing" >> $GITHUB_OUTPUT
run: echo "VALUE=platform-${{ matrix.platform }}_arch=${{ matrix.arch }}_type=fuzzing" >> $GITHUB_OUTPUT

- name: Update the cache (ccache)
uses: actions/[email protected]
Expand All @@ -49,7 +43,7 @@ jobs:
ccache
- name: Install system dependencies (Linux)
if: inputs.platform == 'ubuntu-latest'
if: matrix.platform == 'ubuntu-latest'
run: |
sudo apt-get update
Expand All @@ -63,25 +57,20 @@ jobs:
libboost-filesystem-dev \
libelf-dev
if [[ "${{ inputs.scan_build }}" == "true" ]] ; then
sudo apt-get install -y \
clang-tools
fi
if [[ "${{ inputs.arch }}" == "arm64" ]] ; then
if [[ "${{ matrix.arch }}" == "arm64" ]] ; then
sudo apt install -y \
g++-aarch64-linux-gnu \
gcc-aarch64-linux-gnu \
qemu-user
fi
- name: Build/install libbpf From Source
if: inputs.platform == 'ubuntu-latest'
if: matrix.platform == 'ubuntu-latest'
run: ./.github/scripts/build-libbpf.sh
shell: bash

- name: Install system dependencies (macOS)
if: inputs.platform == 'macos-11'
if: matrix.platform == 'macos-11'
run: |
brew install \
cmake \
Expand All @@ -98,7 +87,7 @@ jobs:
-G Ninja \
-S . \
-B build \
-DCMAKE_BUILD_TYPE=${{ inputs.build_type }} \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DUBPF_ENABLE_LIBFUZZER=1 \
Expand All @@ -109,10 +98,6 @@ jobs:
run: |
export CCACHE_DIR="$(pwd)/ccache"
if [[ "${{ inputs.scan_build }}" == "true" ]] ; then
command_prefix="scan-build -o scan_build_report"
fi
${command_prefix} cmake \
--build build
Expand Down Expand Up @@ -152,7 +137,7 @@ jobs:
git config --global user.email '[email protected]'
git config --global user.name 'Github Action'
git commit -sm "Update fuzzing corpus"
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/iovisor/ubpf.git
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{github.repository}}.git
git push
- name: Upload artifacts
Expand Down
16 changes: 7 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ name: Main
permissions:
contents: read
security-events: write # Required by codeql task.
actions: read

on:
schedule:
Expand Down Expand Up @@ -310,14 +311,6 @@ jobs:
enable_sanitizers: true
disable_retpolines: true

# Run fuzzing on scheduled task only.
linux_fuzzing:
if: github.event_name == 'schedule'
uses: ./.github/workflows/fuzzing.yml
with:
arch: x86_64
platform: ubuntu-latest

# Disabled until https://github.com/iovisor/ubpf/issues/155 is resolved.
# linux_debug_arm64_sanitizers:
# uses: ./.github/workflows/posix.yml
Expand All @@ -340,8 +333,13 @@ jobs:

runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
with:
egress-policy: audit

- name: Coveralls Finished
uses: coverallsapp/[email protected]
uses: coverallsapp/github-action@3dfc5567390f6fa9267c0ee9c251e4c8c3f18949 # v2.2.3
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
11 changes: 8 additions & 3 deletions .github/workflows/posix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ jobs:
runs-on: ${{ inputs.platform }}

steps:
- uses: actions/checkout@v4
- name: Harden Runner
uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
with:
egress-policy: audit

- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: 'recursive'

Expand All @@ -75,7 +80,7 @@ jobs:
run: echo "VALUE=platform-${{ inputs.platform }}_arch=${{ inputs.arch }}_type-${{ inputs.build_type }}_sanitizers-${{ inputs.enable_sanitizers }}_coverage-${{ inputs.enable_coverage }}_scan_build-${{ inputs.scan_build }}_retpolines-${{ inputs.disable_retpolines }}" >> $GITHUB_OUTPUT

- name: Update the cache (ccache)
uses: actions/[email protected].2
uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0
with:
path: ccache
key: ${{ steps.cache_key.outputs.VALUE }}_ccache
Expand Down Expand Up @@ -200,7 +205,7 @@ jobs:
- name: Coveralls Parallel
if: inputs.enable_coverage == true
uses: coverallsapp/[email protected]
uses: coverallsapp/github-action@3dfc5567390f6fa9267c0ee9c251e4c8c3f18949 # v2.2.3
with:
github-token: ${{ secrets.github_token }}
flag-name: run-${{inputs.build_type}}-${{inputs.platform}}-${{inputs.arch}}
Expand Down
76 changes: 76 additions & 0 deletions .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# This workflow uses actions that are not certified by GitHub. They are provided
# by a third-party and are governed by separate terms of service, privacy
# policy, and support documentation.

name: Scorecard supply-chain security
on:
# For Branch-Protection check. Only the default branch is supported. See
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection
branch_protection_rule:
# To guarantee Maintained check is occasionally updated. See
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained
schedule:
- cron: '20 7 * * 2'
push:
branches: ["main"]

# Declare default permissions as read only.
permissions: read-all

jobs:
analysis:
name: Scorecard analysis
runs-on: ubuntu-latest
permissions:
# Needed to upload the results to code-scanning dashboard.
security-events: write
# Needed to publish results and get a badge (see publish_results below).
id-token: write
contents: read
actions: read

steps:
- name: Harden Runner
uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
with:
egress-policy: audit

- name: "Checkout code"
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
with:
persist-credentials: false

- name: "Run analysis"
uses: ossf/scorecard-action@99c53751e09b9529366343771cc321ec74e9bd3d # v2.0.6
with:
results_file: results.sarif
results_format: sarif
# (Optional) "write" PAT token. Uncomment the `repo_token` line below if:
# - you want to enable the Branch-Protection check on a *public* repository, or
# - you are installing Scorecards on a *private* repository
# To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat.
# repo_token: ${{ secrets.SCORECARD_TOKEN }}

# Public repositories:
# - Publish results to OpenSSF REST API for easy access by consumers
# - Allows the repository to include the Scorecard badge.
# - See https://github.com/ossf/scorecard-action#publishing-results.
# For private repositories:
# - `publish_results` will always be set to `false`, regardless
# of the value entered here.
publish_results: true

# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: SARIF file
path: results.sarif
retention-days: 5

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@a56a03b370b87b26fde6d680755f818cfda0372b # v2.24.5
with:
sarif_file: results.sarif
2 changes: 1 addition & 1 deletion .github/workflows/udpate-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
run: |
sudo apt install doxygen
- uses: actions/checkout@v4
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Clone docs
run: |
Expand Down
14 changes: 13 additions & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,24 @@ on:
required: false
type: boolean

permissions:
contents: read

jobs:
build:
permissions:
actions: read # for github/codeql-action/init to get workflow details
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/analyze to upload SARIF results
runs-on: ${{ inputs.platform }}

steps:
- uses: actions/checkout@v4
- name: Harden Runner
uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
with:
egress-policy: audit

- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: 'recursive'

Expand Down
22 changes: 22 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.16.3
hooks:
- id: gitleaks
- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 3.0.0
hooks:
- id: shellcheck
- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
hooks:
- id: cpplint
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/pylint-dev/pylint
rev: v2.17.2
hooks:
- id: pylint
3 changes: 2 additions & 1 deletion vm/ubpf_jit_x86_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ translate(struct ubpf_vm* vm, struct jit_state* state, char** errmsg)
}

struct ebpf_inst inst = ubpf_fetch_instruction(vm, i);
state->pc_locs[i] = state->offset;

int dst = map_register(inst.dst);
int src = map_register(inst.src);
Expand All @@ -314,6 +313,8 @@ translate(struct ubpf_vm* vm, struct jit_state* state, char** errmsg)
emit_alu64_imm32(state, 0x81, 5, RSP, 8);
}

state->pc_locs[i] = state->offset;

switch (inst.opcode) {
case EBPF_OP_ADD_IMM:
emit_alu32_imm32(state, 0x81, 0, dst, inst.imm);
Expand Down

0 comments on commit a5dce52

Please sign in to comment.