diff --git a/.github/workflows/check_wdk.yml b/.github/workflows/check_wdk.yml new file mode 100644 index 0000000000..82a3467e1e --- /dev/null +++ b/.github/workflows/check_wdk.yml @@ -0,0 +1,83 @@ +# Copyright (c) eBPF for Windows contributors +# SPDX-License-Identifier: MIT + +# This workflow checks for Windows Driver Kit updates and files issues when updates are needed. + +name: Check for updates to the Windows Driver Kit + +on: + # Run script every Sunday at midnight + schedule: + - cron: '0 0 * * 0' + # Allow manual triggering of the script + workflow_dispatch: + +jobs: + check: + runs-on: Windows-latest + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + + - name: Check for updates to the Windows Driver Kit + id: check_wdk + run: | + # Get the latest version of the Windows Driver Kit + $packageVersion = .\scripts\Get-LatestNugetPackageVersion.ps1 -PackageName "Microsoft.Windows.WDK.x64" + "wdk_version=$packageVersion" >> $env:GITHUB_OUTPUT + + - name: Check the version of the WDK in the repo + id: check_repo_wdk + run: | + $wdkVersion = (Get-Content -Path .\wdk.props | Select-String -Pattern "" | ForEach-Object { $_ -replace "", "" -replace "", "" }).trim() + "wdk_version=$wdkVersion" >> $env:GITHUB_OUTPUT + + - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea + if: steps.check_wdk.outputs.wdk_version != steps.check_repo_wdk.outputs.wdk_version + env: + TITLE: 'Update the Windows Driver Kit' + BODY: | + The Windows Driver Kit version in the repository does not match the latest version available on NuGet. Please update the WDK version in the repository to match the latest version available on NuGet. + The latest version is ${{steps.check_wdk.outputs.wdk_version}} and the version in the repository is ${{steps.check_repo_wdk.outputs.wdk_version}}. + To update the WDK run the following command: + ```powershell + .\scripts\Update-WdkVersion.ps1 + ``` + LABELS: bug,ci/cd + with: + script: | + const owner = process.env.GITHUB_REPOSITORY.split('/')[0] + const repo = process.env.GITHUB_REPOSITORY.split('/')[1] + const body = process.env.BODY; + const title = process.env.TITLE; + const labels = process.env.LABELS; + const label_array = labels ? labels.split(',') : []; + console.log(label_array); + // Get all issues that have these labels. + const opts = github.rest.issues.listForRepo.endpoint.merge({ + ...context.issue, + state: 'open', + labels: label_array, + }); + const issues = await github.paginate(opts); + // Look for an existing issue with the same title. + for (const issue of issues) { + if (issue.title === title) { + console.log(`Updating issue ${title}`); + await github.rest.issues.createComment({ + issue_number: issue.number, + owner, + repo, + body, + }); + return; + } + } + // Existing issue not found, create a new one. + console.log(`Creating issue ${title}`); + await github.rest.issues.create({ + owner: owner, + repo: repo, + title: title, + body: body, + labels: label_array, + }); diff --git a/.github/workflows/ossar-scan.yml b/.github/workflows/ossar-scan.yml index fca00c4e04..aa5e50ae01 100644 --- a/.github/workflows/ossar-scan.yml +++ b/.github/workflows/ossar-scan.yml @@ -81,6 +81,6 @@ jobs: - name: Upload results to Security tab if: steps.skip_check.outputs.should_skip != 'true' - uses: github/codeql-action/upload-sarif@aa578102511db1f4524ed59b8cc2bae4f6e88195 + uses: github/codeql-action/upload-sarif@df409f7d9260372bd5f19e5b04e83cb3c43714ae with: sarif_file: ${{ steps.ossar.outputs.sarifFile }} diff --git a/.github/workflows/reusable-build.yml b/.github/workflows/reusable-build.yml index 0d5c1ae6f1..cf5107480f 100644 --- a/.github/workflows/reusable-build.yml +++ b/.github/workflows/reusable-build.yml @@ -135,7 +135,7 @@ jobs: - name: Initialize CodeQL if: inputs.build_codeql == true && steps.skip_check.outputs.should_skip != 'true' - uses: github/codeql-action/init@aa578102511db1f4524ed59b8cc2bae4f6e88195 + uses: github/codeql-action/init@df409f7d9260372bd5f19e5b04e83cb3c43714ae with: languages: 'cpp' @@ -303,4 +303,4 @@ jobs: - name: Perform CodeQL Analysis if: inputs.build_codeql == true && steps.skip_check.outputs.should_skip != 'true' - uses: github/codeql-action/analyze@aa578102511db1f4524ed59b8cc2bae4f6e88195 + uses: github/codeql-action/analyze@df409f7d9260372bd5f19e5b04e83cb3c43714ae diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index a5a56ebdc1..b7b11e5173 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -76,6 +76,6 @@ jobs: # Upload the results to GitHub's code scanning dashboard. - name: "Upload to code-scanning" if: github.ref_name == 'main' - uses: github/codeql-action/upload-sarif@aa578102511db1f4524ed59b8cc2bae4f6e88195 + uses: github/codeql-action/upload-sarif@df409f7d9260372bd5f19e5b04e83cb3c43714ae with: sarif_file: results.sarif diff --git a/.github/workflows/upload-perf-results.yml b/.github/workflows/upload-perf-results.yml index 91e5d0c63e..d394acf34e 100644 --- a/.github/workflows/upload-perf-results.yml +++ b/.github/workflows/upload-perf-results.yml @@ -102,7 +102,7 @@ jobs: export PGUSER=$(cat ${{github.workspace}}/PGUSER) export PGPORT=$(cat ${{github.workspace}}/PGPORT) export PGDATABASE=$(cat ${{github.workspace}}/PGDATABASE) - psql -f ./scripts/check_perf_results.sql -v platform='${{inputs.platform}}' --csv > ${{github.workspace}}/results/regression_results.csv + psql -f ./check_perf_results.sql -v platform='${{inputs.platform}}' --csv > ${{github.workspace}}/results/regression_results.csv - name: Upload regression results uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 diff --git a/.onefuzz/OneFuzzConfig.json b/.onefuzz/OneFuzzConfig.json index 716eebfb8f..4bd1ee0c25 100644 --- a/.onefuzz/OneFuzzConfig.json +++ b/.onefuzz/OneFuzzConfig.json @@ -59,24 +59,11 @@ "PipelineId": "79576" }, "AdoTemplate": { - "Org": "mscodehub", - "Project": "eBPFForWindows", - "AssignedTo": "alanjo@microsoft.com", - "AreaPath": "eBPFForWindows", - "IterationPath": "eBPFForWindows", - "Type": "Bug", - "BaseUrl": "https://dev.azure.com/mscodehub", - "Comment": "This input caused the fuzz target {{ report.executable }} to crash. The faulting input SHA256 hash is {{ report.input_sha256 }}
", - "OnDuplicate": { - "Increment": [ - "" - ], - "Comment": "This input caused the fuzz target {{ report.executable }} to crash. The faulting input SHA256 hash is {{ report.input_sha256 }}
", - "SetState": { - "Resolved": "Active", - "Closed": "Active" - } - } + "Org": "microsoft", + "Project": "OS", + "AssignedTo": "Active", + "AreaPath": "OS\\Core\\IO Fabrics\\Transports Security and SDN\\eBPF", + "IterationPath": "OS" } }, { @@ -136,24 +123,11 @@ "PipelineId": "79576" }, "AdoTemplate": { - "Org": "mscodehub", - "Project": "eBPFForWindows", - "AssignedTo": "alanjo@microsoft.com", - "AreaPath": "eBPFForWindows", - "IterationPath": "eBPFForWindows", - "Type": "Bug", - "BaseUrl": "https://dev.azure.com/mscodehub", - "Comment": "This input caused the fuzz target {{ report.executable }} to crash. The faulting input SHA256 hash is {{ report.input_sha256 }}
", - "OnDuplicate": { - "Increment": [ - "" - ], - "Comment": "This input caused the fuzz target {{ report.executable }} to crash. The faulting input SHA256 hash is {{ report.input_sha256 }}
", - "SetState": { - "Resolved": "Active", - "Closed": "Active" - } - } + "Org": "microsoft", + "Project": "OS", + "AssignedTo": "Active", + "AreaPath": "OS\\Core\\IO Fabrics\\Transports Security and SDN\\eBPF", + "IterationPath": "OS" } }, { @@ -213,24 +187,11 @@ "PipelineId": "79576" }, "AdoTemplate": { - "Org": "mscodehub", - "Project": "eBPFForWindows", - "AssignedTo": "alanjo@microsoft.com", - "AreaPath": "eBPFForWindows", - "IterationPath": "eBPFForWindows", - "Type": "Bug", - "BaseUrl": "https://dev.azure.com/mscodehub", - "Comment": "This input caused the fuzz target {{ report.executable }} to crash. The faulting input SHA256 hash is {{ report.input_sha256 }}
", - "OnDuplicate": { - "Increment": [ - "" - ], - "Comment": "This input caused the fuzz target {{ report.executable }} to crash. The faulting input SHA256 hash is {{ report.input_sha256 }}
", - "SetState": { - "Resolved": "Active", - "Closed": "Active" - } - } + "Org": "microsoft", + "Project": "OS", + "AssignedTo": "Active", + "AreaPath": "OS\\Core\\IO Fabrics\\Transports Security and SDN\\eBPF", + "IterationPath": "OS" } }, { @@ -290,24 +251,11 @@ "PipelineId": "79576" }, "AdoTemplate": { - "Org": "mscodehub", - "Project": "eBPFForWindows", - "AssignedTo": "alanjo@microsoft.com", - "AreaPath": "eBPFForWindows", - "IterationPath": "eBPFForWindows", - "Type": "Bug", - "BaseUrl": "https://dev.azure.com/mscodehub", - "Comment": "This input caused the fuzz target {{ report.executable }} to crash. The faulting input SHA256 hash is {{ report.input_sha256 }}
", - "OnDuplicate": { - "Increment": [ - "" - ], - "Comment": "This input caused the fuzz target {{ report.executable }} to crash. The faulting input SHA256 hash is {{ report.input_sha256 }}
", - "SetState": { - "Resolved": "Active", - "Closed": "Active" - } - } + "Org": "microsoft", + "Project": "OS", + "AssignedTo": "Active", + "AreaPath": "OS\\Core\\IO Fabrics\\Transports Security and SDN\\eBPF", + "IterationPath": "OS" } }, { @@ -368,24 +316,11 @@ "PipelineId": "79576" }, "AdoTemplate": { - "Org": "mscodehub", - "Project": "eBPFForWindows", - "AssignedTo": "alanjo@microsoft.com", - "AreaPath": "eBPFForWindows", - "IterationPath": "eBPFForWindows", - "Type": "Bug", - "BaseUrl": "https://dev.azure.com/mscodehub", - "Comment": "This input caused the fuzz target {{ report.executable }} to crash. The faulting input SHA256 hash is {{ report.input_sha256 }}
", - "OnDuplicate": { - "Increment": [ - "" - ], - "Comment": "This input caused the fuzz target {{ report.executable }} to crash. The faulting input SHA256 hash is {{ report.input_sha256 }}
", - "SetState": { - "Resolved": "Active", - "Closed": "Active" - } - } + "Org": "microsoft", + "Project": "OS", + "AssignedTo": "Active", + "AreaPath": "OS\\Core\\IO Fabrics\\Transports Security and SDN\\eBPF", + "IterationPath": "OS" } }, { @@ -445,24 +380,11 @@ "PipelineId": "79576" }, "AdoTemplate": { - "Org": "mscodehub", - "Project": "eBPFForWindows", - "AssignedTo": "alanjo@microsoft.com", - "AreaPath": "eBPFForWindows", - "IterationPath": "eBPFForWindows", - "Type": "Bug", - "BaseUrl": "https://dev.azure.com/mscodehub", - "Comment": "This input caused the fuzz target {{ report.executable }} to crash. The faulting input SHA256 hash is {{ report.input_sha256 }}
", - "OnDuplicate": { - "Increment": [ - "" - ], - "Comment": "This input caused the fuzz target {{ report.executable }} to crash. The faulting input SHA256 hash is {{ report.input_sha256 }}
", - "SetState": { - "Resolved": "Active", - "Closed": "Active" - } - } + "Org": "microsoft", + "Project": "OS", + "AssignedTo": "Active", + "AreaPath": "OS\\Core\\IO Fabrics\\Transports Security and SDN\\eBPF", + "IterationPath": "OS" } } ] diff --git a/ebpf-for-windows.sln b/ebpf-for-windows.sln index b666b97ee4..21b5c126d1 100644 --- a/ebpf-for-windows.sln +++ b/ebpf-for-windows.sln @@ -324,7 +324,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "usersim", "external\usersim {231EE32B-EBA4-4FE5-A55B-DB18F539D403} = {231EE32B-EBA4-4FE5-A55B-DB18F539D403} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libbtf", "external\ebpf-verifier\build\external\libbtf\libbtf\libbtf.vcxproj", "{C15BA92B-C9A9-332F-8048-7653B21428ED}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libbtf", "external\ebpf-verifier\build\external\libbtf\libbtf\libbtf.vcxproj", "{5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}" ProjectSection(ProjectDependencies) = postProject {231EE32B-EBA4-4FE5-A55B-DB18F539D403} = {231EE32B-EBA4-4FE5-A55B-DB18F539D403} EndProjectSection @@ -384,15 +384,22 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sample_ext_app", "tests\sam EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "onebranch", "tools\onebranch\onebranch.vcxproj", "{58D6BAB8-10EF-4A99-AFF2-6B14269A8DCD}" ProjectSection(ProjectDependencies) = postProject + {02A1913F-7FF5-4C20-B230-2240B4EDEC10} = {02A1913F-7FF5-4C20-B230-2240B4EDEC10} {030A7AC6-14DC-45CF-AF34-891057AB1402} = {030A7AC6-14DC-45CF-AF34-891057AB1402} + {07DC6181-84A2-4A14-A806-5E9AF6C929C2} = {07DC6181-84A2-4A14-A806-5E9AF6C929C2} + {12161211-5463-4AA9-9B6E-552552B475DC} = {12161211-5463-4AA9-9B6E-552552B475DC} + {21C137EC-9AE3-4C8C-8E74-8BFCC999D856} = {21C137EC-9AE3-4C8C-8E74-8BFCC999D856} {231EE32B-EBA4-4FE5-A55B-DB18F539D403} = {231EE32B-EBA4-4FE5-A55B-DB18F539D403} + {4F082524-9496-44FA-8CBA-4BC0BDC62568} = {4F082524-9496-44FA-8CBA-4BC0BDC62568} {55499E36-37D4-4F86-B694-9F2990315758} = {55499E36-37D4-4F86-B694-9F2990315758} + {64AD121F-B4D4-4B38-A370-DDD4FEA6707E} = {64AD121F-B4D4-4B38-A370-DDD4FEA6707E} {69B97E52-18DC-434E-A6E4-4C0F3E88C44A} = {69B97E52-18DC-434E-A6E4-4C0F3E88C44A} {74803F80-A8BD-4A03-862B-FA96648A9BF6} = {74803F80-A8BD-4A03-862B-FA96648A9BF6} {75FE223A-3E45-4B0E-A2E8-04285E52E440} = {75FE223A-3E45-4B0E-A2E8-04285E52E440} {97E52ABB-2F1E-4AD2-AEFD-6EB7FDC0A41D} = {97E52ABB-2F1E-4AD2-AEFD-6EB7FDC0A41D} {BA065B6A-38F8-4197-8F66-87C84AFAD513} = {BA065B6A-38F8-4197-8F66-87C84AFAD513} {CA179B38-EBF5-4371-B830-73486E35250B} = {CA179B38-EBF5-4371-B830-73486E35250B} + {EED9DAC6-8B98-4C33-969A-E8CEDE8E985E} = {EED9DAC6-8B98-4C33-969A-E8CEDE8E985E} {FA9BB88D-8259-40C1-9422-BDEDF9E9CE68} = {FA9BB88D-8259-40C1-9422-BDEDF9E9CE68} EndProjectSection EndProject @@ -2735,48 +2742,48 @@ Global {030A7AC6-14DC-45CF-AF34-891057AB1402}.RelWithDebInfo|x64.Build.0 = Release|x64 {030A7AC6-14DC-45CF-AF34-891057AB1402}.RelWithDebInfo|x86.ActiveCfg = Release|Win32 {030A7AC6-14DC-45CF-AF34-891057AB1402}.RelWithDebInfo|x86.Build.0 = Release|Win32 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.Debug|ARM64.ActiveCfg = Debug|ARM64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.Debug|ARM64.Build.0 = Debug|ARM64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.Debug|x64.ActiveCfg = Debug|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.Debug|x64.Build.0 = Debug|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.Debug|x86.ActiveCfg = Debug|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.Debug|x86.Build.0 = Debug|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.FuzzerDebug|ARM64.ActiveCfg = FuzzerDebug|ARM64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.FuzzerDebug|ARM64.Build.0 = FuzzerDebug|ARM64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.FuzzerDebug|x64.ActiveCfg = FuzzerDebug|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.FuzzerDebug|x64.Build.0 = FuzzerDebug|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.FuzzerDebug|x86.ActiveCfg = FuzzerDebug|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.FuzzerDebug|x86.Build.0 = FuzzerDebug|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.MinSizeRel|ARM64.ActiveCfg = MinSizeRel|ARM64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.MinSizeRel|ARM64.Build.0 = MinSizeRel|ARM64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.MinSizeRel|x64.Build.0 = MinSizeRel|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.MinSizeRel|x86.ActiveCfg = MinSizeRel|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.MinSizeRel|x86.Build.0 = MinSizeRel|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.NativeOnlyDebug|ARM64.ActiveCfg = Debug|ARM64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.NativeOnlyDebug|ARM64.Build.0 = Debug|ARM64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.NativeOnlyDebug|x64.ActiveCfg = Debug|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.NativeOnlyDebug|x64.Build.0 = Debug|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.NativeOnlyDebug|x86.ActiveCfg = Debug|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.NativeOnlyDebug|x86.Build.0 = Debug|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.NativeOnlyRelease|ARM64.ActiveCfg = Release|ARM64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.NativeOnlyRelease|ARM64.Build.0 = Release|ARM64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.NativeOnlyRelease|x64.ActiveCfg = Release|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.NativeOnlyRelease|x64.Build.0 = Release|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.NativeOnlyRelease|x86.ActiveCfg = Release|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.NativeOnlyRelease|x86.Build.0 = Release|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.Release|ARM64.ActiveCfg = Release|ARM64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.Release|ARM64.Build.0 = Release|ARM64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.Release|x64.ActiveCfg = Release|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.Release|x64.Build.0 = Release|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.Release|x86.ActiveCfg = Release|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.Release|x86.Build.0 = Release|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.RelWithDebInfo|ARM64.ActiveCfg = RelWithDebInfo|ARM64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.RelWithDebInfo|ARM64.Build.0 = RelWithDebInfo|ARM64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.RelWithDebInfo|x86.ActiveCfg = RelWithDebInfo|x64 - {C15BA92B-C9A9-332F-8048-7653B21428ED}.RelWithDebInfo|x86.Build.0 = RelWithDebInfo|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.Debug|ARM64.Build.0 = Debug|ARM64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.Debug|x64.ActiveCfg = Debug|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.Debug|x64.Build.0 = Debug|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.Debug|x86.ActiveCfg = Debug|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.Debug|x86.Build.0 = Debug|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.FuzzerDebug|ARM64.ActiveCfg = FuzzerDebug|ARM64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.FuzzerDebug|ARM64.Build.0 = FuzzerDebug|ARM64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.FuzzerDebug|x64.ActiveCfg = FuzzerDebug|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.FuzzerDebug|x64.Build.0 = FuzzerDebug|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.FuzzerDebug|x86.ActiveCfg = FuzzerDebug|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.FuzzerDebug|x86.Build.0 = FuzzerDebug|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.MinSizeRel|ARM64.ActiveCfg = MinSizeRel|ARM64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.MinSizeRel|ARM64.Build.0 = MinSizeRel|ARM64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.MinSizeRel|x64.Build.0 = MinSizeRel|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.MinSizeRel|x86.ActiveCfg = MinSizeRel|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.MinSizeRel|x86.Build.0 = MinSizeRel|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.NativeOnlyDebug|ARM64.ActiveCfg = Debug|ARM64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.NativeOnlyDebug|ARM64.Build.0 = Debug|ARM64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.NativeOnlyDebug|x64.ActiveCfg = Debug|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.NativeOnlyDebug|x64.Build.0 = Debug|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.NativeOnlyDebug|x86.ActiveCfg = Debug|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.NativeOnlyDebug|x86.Build.0 = Debug|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.NativeOnlyRelease|ARM64.ActiveCfg = Release|ARM64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.NativeOnlyRelease|ARM64.Build.0 = Release|ARM64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.NativeOnlyRelease|x64.ActiveCfg = Release|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.NativeOnlyRelease|x64.Build.0 = Release|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.NativeOnlyRelease|x86.ActiveCfg = Release|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.NativeOnlyRelease|x86.Build.0 = Release|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.Release|ARM64.ActiveCfg = Release|ARM64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.Release|ARM64.Build.0 = Release|ARM64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.Release|x64.ActiveCfg = Release|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.Release|x64.Build.0 = Release|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.Release|x86.ActiveCfg = Release|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.Release|x86.Build.0 = Release|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.RelWithDebInfo|ARM64.ActiveCfg = RelWithDebInfo|ARM64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.RelWithDebInfo|ARM64.Build.0 = RelWithDebInfo|ARM64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.RelWithDebInfo|x86.ActiveCfg = RelWithDebInfo|x64 + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE}.RelWithDebInfo|x86.Build.0 = RelWithDebInfo|x64 {1937DB41-F3EB-4955-A636-6386DCB394F6}.Debug|ARM64.ActiveCfg = Debug|ARM64 {1937DB41-F3EB-4955-A636-6386DCB394F6}.Debug|ARM64.Build.0 = Debug|ARM64 {1937DB41-F3EB-4955-A636-6386DCB394F6}.Debug|x64.ActiveCfg = Debug|x64 @@ -3515,7 +3522,7 @@ Global {4F082524-9496-44FA-8CBA-4BC0BDC62568} = {492C9B22-9237-4996-9E33-CA14D3533616} {AA933B9F-B5D8-4AA8-AC18-98FE1A161E8A} = {69CDB6A1-434D-4BC9-9BFF-D12DF7EDBB6B} {030A7AC6-14DC-45CF-AF34-891057AB1402} = {69CDB6A1-434D-4BC9-9BFF-D12DF7EDBB6B} - {C15BA92B-C9A9-332F-8048-7653B21428ED} = {69CDB6A1-434D-4BC9-9BFF-D12DF7EDBB6B} + {5D450380-AE0C-3DAA-A0CC-F1291D1DE9EE} = {69CDB6A1-434D-4BC9-9BFF-D12DF7EDBB6B} {1937DB41-F3EB-4955-A636-6386DCB394F6} = {69CDB6A1-434D-4BC9-9BFF-D12DF7EDBB6B} {1FDAD2FD-EBD8-462A-B285-ED5174E55079} = {97D3096A-20FB-4ACB-A038-88E652FE61E3} {9388DD45-7941-45D7-B4FF-BC00F550AF17} = {69CDB6A1-434D-4BC9-9BFF-D12DF7EDBB6B} diff --git a/external/ubpf b/external/ubpf index 859e35c92f..f5e6778dd0 160000 --- a/external/ubpf +++ b/external/ubpf @@ -1 +1 @@ -Subproject commit 859e35c92f3b8179a530e168ae610f35f14e19da +Subproject commit f5e6778dd031584c40d59cba0df7293331b56339 diff --git a/libs/runtime/ebpf_ring_buffer.c b/libs/runtime/ebpf_ring_buffer.c index 65ffbdb6bc..e900a16d87 100644 --- a/libs/runtime/ebpf_ring_buffer.c +++ b/libs/runtime/ebpf_ring_buffer.c @@ -135,6 +135,14 @@ _Must_inspect_result_ ebpf_result_t ebpf_ring_buffer_output(_Inout_ ebpf_ring_buffer_t* ring, _In_reads_bytes_(length) uint8_t* data, size_t length) { ebpf_result_t result; + // Before acquiring the lock, check if there is enough space in the ring buffer. + // This is the common case when the consumer is not consuming fast enough, so no need to acquire the lock + // and slow down the producer. + size_t remaining_space = ring->length - (ring->producer_offset - ring->consumer_offset); + if (remaining_space < length) { + return EBPF_OUT_OF_SPACE; + } + ebpf_lock_state_t state = ebpf_lock_lock(&ring->lock); ebpf_ring_buffer_record_t* record = _ring_buffer_acquire_record(ring, length); diff --git a/scripts/Get-LatestNugetPackageVersion.ps1 b/scripts/Get-LatestNugetPackageVersion.ps1 new file mode 100644 index 0000000000..eab93f3d2a --- /dev/null +++ b/scripts/Get-LatestNugetPackageVersion.ps1 @@ -0,0 +1,49 @@ +# Copyright (c) eBPF for Windows contributors +# SPDX-License-Identifier: MIT + +param( + [string]$packageName +) + +<# +.SYNOPSIS +Get the latest version of a NuGet package. + +.DESCRIPTION +Queries the NuGet package manager for the latest version of a package. + +.PARAMETER packageName +The name of the package to query. + +.NOTES +This function requires the 'nuget' command to be available in the PATH. +#> + +function Get-LatestNugetPackageVersion( + [string]$packageName +) { + if ([string]::IsNullOrWhiteSpace($packageName)) { + throw "Package name cannot be empty" + } + + try { + $package = nuget list $packageName + if ($LASTEXITCODE -ne 0) { + throw "Failed to retrieve package information" + } + $packageLine = $package | Where-Object { $_ -match $packageName } + if (-not $packageLine) { + throw "Package '$packageName' not found" + } + if ($packageLine -is [array]) { + $packageLine = $packageLine[0] + } + $version = $packageLine -replace "$packageName\s+", "" + return $version + } catch { + throw "Failed to retrieve version of package '$packageName': $_" + } +} + +# Get the latest version of the Microsoft.Windows.WDK.x64 package +Get-LatestNugetPackageVersion $packageName \ No newline at end of file diff --git a/scripts/Update-WdkVersion.ps1 b/scripts/Update-WdkVersion.ps1 new file mode 100644 index 0000000000..91c71f3d75 --- /dev/null +++ b/scripts/Update-WdkVersion.ps1 @@ -0,0 +1,238 @@ +# Copyright (c) eBPF for Windows contributors +# SPDX-License-Identifier: MIT + +<# +.SYNOPSIS +Updates the WDK version in all relevant files. + +.DESCRIPTION +This script updates the WDK version in all relevant files. It queries the NuGet package manager for the version of the +'Microsoft.Windows.WDK.x64' package and updates the version number in the following files: +- wdk.props +- tools\bpf2c\templates\kernel_mode_bpf2c.vcxproj +- tools\bpf2c\templates\user_mode_bpf2c.vcxproj +- scripts\setup_build\packages.config + +The script creates a backup of each file before updating it. If an error occurs during the update, the script rolls back +all changes. + +The script requires the 'nuget' command to be available in the PATH. + +.PARAMETER None +This script does not take any parameters. + +.NOTES +This script is intended to be run from the root of the repository. +#> + +function Get-PackageVersion( + [string]$packageName +) { +<# +.SYNOPSIS +Get the version of a NuGet package. + +.DESCRIPTION +Queries the NuGet package manager for the version of a package. + +.PARAMETER packageName +The name of the package to query. + +.EXAMPLE +Get-PackageVersion "Microsoft.Windows.WDK.x64" + +.NOTES +This function requires the 'nuget' command to be available in the PATH. +#> + if ([string]::IsNullOrWhiteSpace($packageName)) { + throw "Package name cannot be empty" + } + + try { + $package = nuget list $packageName + if ($LASTEXITCODE -ne 0) { + throw "Failed to retrieve package information" + } + $packageLine = $package | Where-Object { $_ -match $packageName } + if (-not $packageLine) { + throw "Package '$packageName' not found" + } + if ($packageLine -is [array]) { + Write-Warning "Multiple versions found. Using the first one." + $packageLine = $packageLine[0] + } + $packageVersion = $packageLine -replace "$packageName\s+", "" + if (-not ($packageVersion -match '^\d+\.\d+\.\d+\.\d+$')) { + throw "Invalid version format: $packageVersion" + } + return $packageVersion + } + catch { + throw "Failed to get package version: $_" + } +} + +function Update-VersionInVsFile( + [string]$vs_file_path, + [string]$version_number +) { +<# +.SYNOPSIS +Updates the WDK version in a Visual Studio file. + +.DESCRIPTION +Updates the WDK version in a Visual Studio file by replacing the existing version number with the specified version +number. + +.PARAMETER vs_file_path +The path to the Visual Studio file to update. + +.PARAMETER version_number +The new version number to set in the file. + +.NOTES +This function creates a backup of the file before updating it. If an error occurs during the update, the function rolls +back the changes. +#> + if ([string]::IsNullOrWhiteSpace($vs_file_path)) { + throw "File path cannot be empty" + } + if (-not ($version_number -match '^\d+\.\d+\.\d+\.\d+$')) { + throw "Invalid version format: $version_number" + } + if (-not (Test-Path $vs_file_path)) { + throw "File not found: $vs_file_path" + } + try { + # Create backup + $backup_path = "$vs_file_path.bak" + Copy-Item $vs_file_path $backup_path -Force + # Read the contents of the file + $vs_file_content = Get-Content $vs_file_path + # Replace the version number in the file + $vs_file_content = $vs_file_content -replace ".*", "$version_number" + # Write the updated contents back to the file + Set-Content $vs_file_path $vs_file_content + # Print success message + Write-Output "Updated WDK version in $vs_file_path to $version_number" + } + catch { + if (Test-Path $backup_path) { + Copy-Item $backup_path $vs_file_path -Force + Remove-Item $backup_path + } + throw "Failed to update version in file: $vs_file_path" + } +} + +function Update-TemplateFile( + [string]$template_file_path, + [string]$output_file_path, + [string]$version_number +) { +<# +.SYNOPSIS +Updates the WDK version in a template file. + +.DESCRIPTION +Updates the WDK version in a template file by replacing the existing version number placeholder with the specified +version number. + +.PARAMETER template_file_path +The path to the template file to update. + +.PARAMETER output_file_path +The path to the output file to write the updated contents. + +.PARAMETER version_number +The new version number to set in the file. + +.NOTES +This function creates a backup of the output file before updating it. If an error occurs during the update, the function +rolls back the changes. +#> + + if ([string]::IsNullOrWhiteSpace($template_file_path) -or [string]::IsNullOrWhiteSpace($output_file_path)) { + throw "File paths cannot be empty" + } + if (-not ($version_number -match '^\d+\.\d+\.\d+\.\d+$')) { + throw "Invalid version format: $version_number" + } + if (-not (Test-Path $template_file_path)) { + throw "Template file not found: $template_file_path" + } + try { + # Create backup if output file exists + $backup_path = $null + if (Test-Path $output_file_path) { + $backup_path = "$output_file_path.bak" + Copy-Item $output_file_path $backup_path -Force + } + + # Read the contents of the file + $template_file_content = Get-Content $template_file_path + # Replace the version number in the file + $template_file_content = $template_file_content -replace "\$\(WDKVersion\)", $version_number + # Write the updated contents back to the file + Set-Content $output_file_path $template_file_content + # Print success message + Write-Output "Updated WDK version in $output_file_path to $version_number" + } + catch { + if ($backup_path -and (Test-Path $backup_path)) { + Copy-Item $backup_path $output_file_path -Force + Remove-Item $backup_path + } + throw "Failed to update template file: $_" + } +} + +# List of files updated by the script used for rollback. +$files_updated = @() + +# Main script logic +try { + # Paths relative to the root of the repository + $vs_files_to_update = @( + "wdk.props", + "tools\bpf2c\templates\kernel_mode_bpf2c.vcxproj", + "tools\bpf2c\templates\user_mode_bpf2c.vcxproj" + ) + + # Get the current WDK version + $wdk_version_number = Get-PackageVersion "Microsoft.Windows.WDK.x64" + + # Print the version number + Write-Output "Found WDK version: $wdk_version_number" + + # Replace version in each VS file + foreach ($vs_file in $vs_files_to_update) { + Write-Host "Updating WDK version in $vs_file" + $vs_file = $PSScriptRoot + "\..\" + $vs_file + Update-VersionInVsFile $vs_file $wdk_version_number + $files_updated += $vs_file + } + + # Generate the new packages.config file + Update-TemplateFile -template_file_path "$PSScriptRoot\..\scripts\setup_build\packages.config.template" -output_file_path "$PSScriptRoot\..\scripts\setup_build\packages.config" -version_number $wdk_version_number + $files_updated += "$PSScriptRoot\..\scripts\setup_build\packages.config" + + # Print success message + Write-Output "Updated WDK version in all files" +} +catch { + # Rollback all changes + for ($i = $files_updated.Length - 1; $i -ge 0; $i--) { + $file = $files_updated[$i] + if (Test-Path "$file.bak") { + # Rolling back changes + Write-Host "Rolling back changes in $file" + Copy-Item "$file.bak" $file -Force + Remove-Item "$file.bak" + } + } + + # Print error message + Write-Error $_ + exit 1 +} \ No newline at end of file diff --git a/scripts/setup_build/packages.config.template b/scripts/setup_build/packages.config.template new file mode 100644 index 0000000000..4c9ac07f89 --- /dev/null +++ b/scripts/setup_build/packages.config.template @@ -0,0 +1,14 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/tests/sample/sample.vcxproj b/tests/sample/sample.vcxproj index 17ee9e083e..739ff4bcda 100644 --- a/tests/sample/sample.vcxproj +++ b/tests/sample/sample.vcxproj @@ -244,7 +244,7 @@ true - + CppCode @@ -276,7 +276,7 @@ configuration. As a result of that, the eBPF store cannot be populated for sample program types and hence bpf2c cannot convert the sample program types to native images (as it needs program information for offline verification). --> - + CppCode @@ -345,7 +345,7 @@ - + CppCode diff --git a/tests/unit/test.vcxproj b/tests/unit/test.vcxproj index b61ca83ca1..05c824a6c9 100644 --- a/tests/unit/test.vcxproj +++ b/tests/unit/test.vcxproj @@ -205,9 +205,6 @@ {d6725f19-b9bf-435f-80f2-c5f3ef0f4b8f} - - {b4ad72e3-754e-40ca-9cea-d3f2c9170e51} - diff --git a/tools/bpf2c/templates/kernel_mode_bpf2c.vcxproj b/tools/bpf2c/templates/kernel_mode_bpf2c.vcxproj index 2673b69641..2c72bc2fad 100644 --- a/tools/bpf2c/templates/kernel_mode_bpf2c.vcxproj +++ b/tools/bpf2c/templates/kernel_mode_bpf2c.vcxproj @@ -4,6 +4,9 @@ SPDX-License-Identifier: MIT --> + + 10.0.26100.2161 + Debug @@ -13,24 +16,24 @@ Release x64 - + Debug - ARM + ARM64 - + Release - ARM + ARM64 $([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) 10.0.26100.0 - - - + + + - + {172DFDF9-3B0D-44AD-B780-92627EA469A2} diff --git a/tools/bpf2c/templates/user_mode_bpf2c.vcxproj b/tools/bpf2c/templates/user_mode_bpf2c.vcxproj index 1d4815c3c8..43ed6b1aa2 100644 --- a/tools/bpf2c/templates/user_mode_bpf2c.vcxproj +++ b/tools/bpf2c/templates/user_mode_bpf2c.vcxproj @@ -4,6 +4,9 @@ SPDX-License-Identifier: MIT --> + + 10.0.26100.2161 + Debug @@ -45,11 +48,11 @@ $([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) 10.0.26100.0 - - - + + + - + 16.0