Skip to content

Commit

Permalink
Add support for bpf2bpf calls with stack variables (#3997)
Browse files Browse the repository at this point in the history
* Update verifier to latest

Signed-off-by: Dave Thaler <[email protected]>

* Test bpf2bpf stack

Signed-off-by: Dave Thaler <[email protected]>

* Update verifier

Signed-off-by: Dave Thaler <[email protected]>

* Update verifier to latest

Signed-off-by: Dave Thaler <[email protected]>

* PR feedback

Signed-off-by: Dave Thaler <[email protected]>

* Update verifier

Signed-off-by: Dave Thaler <[email protected]>

* Fix build

Signed-off-by: Dave Thaler <[email protected]>

* Fix test

Signed-off-by: Dave Thaler <[email protected]>

* Fix analysis warning

Signed-off-by: Dave Thaler <[email protected]>

* Updated expected files for bindmonitor_bpf2bpf sample

Signed-off-by: Dave Thaler <[email protected]>

---------

Signed-off-by: Dave Thaler <[email protected]>
  • Loading branch information
dthaler authored Nov 13, 2024
1 parent 0a7fddd commit 7eb78c0
Show file tree
Hide file tree
Showing 20 changed files with 657 additions and 261 deletions.
10 changes: 5 additions & 5 deletions ebpfapi/ebpfapi.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api;$(SolutionDir)rpc_interface;$(SolutionDir)include;$(SolutionDir)libs\shared;$(SolutionDir)libs\shared\user;$(SolutionDir)external\usersim\cxplat\inc;$(SolutionDir)external\usersim\cxplat\inc\winuser;$(SolutionDir)libs\execution_context;$(SolutionDir)libs\api_common;$(SolutionDir)external\ebpf-verifier\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api;$(SolutionDir)rpc_interface;$(SolutionDir)include;$(SolutionDir)libs\shared;$(SolutionDir)libs\shared\user;$(SolutionDir)external\usersim\cxplat\inc;$(SolutionDir)external\usersim\cxplat\inc\winuser;$(SolutionDir)libs\execution_context;$(SolutionDir)libs\api_common;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)external\ebpf-verifier\build\_deps\gsl-src\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -112,7 +112,7 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api;$(SolutionDir)rpc_interface;$(SolutionDir)include;$(SolutionDir)libs\shared;$(SolutionDir)libs\shared\user;$(SolutionDir)external\usersim\cxplat\inc;$(SolutionDir)external\usersim\cxplat\inc\winuser;$(SolutionDir)libs\execution_context;$(SolutionDir)libs\api_common;$(SolutionDir)external\ebpf-verifier\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api;$(SolutionDir)rpc_interface;$(SolutionDir)include;$(SolutionDir)libs\shared;$(SolutionDir)libs\shared\user;$(SolutionDir)external\usersim\cxplat\inc;$(SolutionDir)external\usersim\cxplat\inc\winuser;$(SolutionDir)libs\execution_context;$(SolutionDir)libs\api_common;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)external\ebpf-verifier\build\_deps\gsl-src\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -130,7 +130,7 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api;$(SolutionDir)rpc_interface;$(SolutionDir)include;$(SolutionDir)libs\shared;$(SolutionDir)libs\shared\user;$(SolutionDir)external\usersim\cxplat\inc;$(SolutionDir)external\usersim\cxplat\inc\winuser;$(SolutionDir)libs\execution_context;$(SolutionDir)libs\api_common;$(SolutionDir)external\ebpf-verifier\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api;$(SolutionDir)rpc_interface;$(SolutionDir)include;$(SolutionDir)libs\shared;$(SolutionDir)libs\shared\user;$(SolutionDir)external\usersim\cxplat\inc;$(SolutionDir)external\usersim\cxplat\inc\winuser;$(SolutionDir)libs\execution_context;$(SolutionDir)libs\api_common;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)external\ebpf-verifier\build\_deps\gsl-src\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -146,7 +146,7 @@
<PreprocessorDefinitions>NDEBUG;EBPFAPI_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api;$(SolutionDir)rpc_interface;$(SolutionDir)include;$(SolutionDir)libs\shared;$(SolutionDir)libs\shared\user;$(SolutionDir)external\usersim\cxplat\inc;$(SolutionDir)external\usersim\cxplat\inc\winuser;$(SolutionDir)libs\execution_context;$(SolutionDir)libs\api_common;$(SolutionDir)external\ebpf-verifier\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api;$(SolutionDir)rpc_interface;$(SolutionDir)include;$(SolutionDir)libs\shared;$(SolutionDir)libs\shared\user;$(SolutionDir)external\usersim\cxplat\inc;$(SolutionDir)external\usersim\cxplat\inc\winuser;$(SolutionDir)libs\execution_context;$(SolutionDir)libs\api_common;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)external\ebpf-verifier\build\_deps\gsl-src\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -164,7 +164,7 @@
<PreprocessorDefinitions>NDEBUG;EBPFAPI_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api;$(SolutionDir)rpc_interface;$(SolutionDir)include;$(SolutionDir)libs\shared;$(SolutionDir)libs\shared\user;$(SolutionDir)external\usersim\cxplat\inc;$(SolutionDir)external\usersim\cxplat\inc\winuser;$(SolutionDir)libs\execution_context;$(SolutionDir)libs\api_common;$(SolutionDir)external\ebpf-verifier\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api;$(SolutionDir)rpc_interface;$(SolutionDir)include;$(SolutionDir)libs\shared;$(SolutionDir)libs\shared\user;$(SolutionDir)external\usersim\cxplat\inc;$(SolutionDir)external\usersim\cxplat\inc\winuser;$(SolutionDir)libs\execution_context;$(SolutionDir)libs\api_common;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)external\ebpf-verifier\build\_deps\gsl-src\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down
13 changes: 12 additions & 1 deletion ebpfapi/ebpfapi.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\libs\shared\hash.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
Expand All @@ -33,10 +36,18 @@
<ClCompile Include="..\libs\thunk\windows\platform.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\libs\shared\hash.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="Source.def">
<Filter>Source Files</Filter>
</None>
</ItemGroup>
</Project>
<ItemGroup>
<ResourceCompile Include="$(SolutionDir)resource\ebpf_resource.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>
8 changes: 4 additions & 4 deletions ebpfsvc/eBPFSvc.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api_common;$(SolutionDir)libs\api;$(SolutionDir)libs\shared\user;$(SolutionDir)libs\shared;$(SolutionDir)external\usersim\cxplat\inc;$(SolutionDir)external\usersim\cxplat\inc\winuser;$(SolutionDir)libs\service;$(SolutionDir)include;$(SolutionDir)rpc_interface;$(SolutionDir)external\ubpf\vm;$(SolutionDir)external\ubpf\vm\inc;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)external\ebpf-verifier\external;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api_common;$(SolutionDir)libs\api;$(SolutionDir)libs\shared\user;$(SolutionDir)libs\shared;$(SolutionDir)external\usersim\cxplat\inc;$(SolutionDir)external\usersim\cxplat\inc\winuser;$(SolutionDir)libs\service;$(SolutionDir)include;$(SolutionDir)rpc_interface;$(SolutionDir)external\ubpf\vm;$(SolutionDir)external\ubpf\vm\inc;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)external\ebpf-verifier\external;$(SolutionDir)external\ebpf-verifier\build\_deps\gsl-src\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -90,7 +90,7 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api_common;$(SolutionDir)libs\api;$(SolutionDir)libs\shared\user;$(SolutionDir)libs\shared;$(SolutionDir)external\usersim\cxplat\inc;$(SolutionDir)external\usersim\cxplat\inc\winuser;$(SolutionDir)libs\service;$(SolutionDir)include;$(SolutionDir)rpc_interface;$(SolutionDir)external\ubpf\vm;$(SolutionDir)external\ubpf\vm\inc;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)external\ebpf-verifier\external;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api_common;$(SolutionDir)libs\api;$(SolutionDir)libs\shared\user;$(SolutionDir)libs\shared;$(SolutionDir)external\usersim\cxplat\inc;$(SolutionDir)external\usersim\cxplat\inc\winuser;$(SolutionDir)libs\service;$(SolutionDir)include;$(SolutionDir)rpc_interface;$(SolutionDir)external\ubpf\vm;$(SolutionDir)external\ubpf\vm\inc;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)external\ebpf-verifier\external;$(SolutionDir)external\ebpf-verifier\build\_deps\gsl-src\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -111,7 +111,7 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api_common;$(SolutionDir)libs\api;$(SolutionDir)libs\shared\user;$(SolutionDir)libs\shared;$(SolutionDir)external\usersim\cxplat\inc;$(SolutionDir)external\usersim\cxplat\inc\winuser;$(SolutionDir)libs\service;$(SolutionDir)include;$(SolutionDir)rpc_interface;$(SolutionDir)external\ubpf\vm;$(SolutionDir)external\ubpf\vm\inc;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)external\ebpf-verifier\external;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api_common;$(SolutionDir)libs\api;$(SolutionDir)libs\shared\user;$(SolutionDir)libs\shared;$(SolutionDir)external\usersim\cxplat\inc;$(SolutionDir)external\usersim\cxplat\inc\winuser;$(SolutionDir)libs\service;$(SolutionDir)include;$(SolutionDir)rpc_interface;$(SolutionDir)external\ubpf\vm;$(SolutionDir)external\ubpf\vm\inc;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)external\ebpf-verifier\external;$(SolutionDir)external\ebpf-verifier\build\_deps\gsl-src\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down Expand Up @@ -163,4 +163,4 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>
</Project>
7 changes: 6 additions & 1 deletion ebpfsvc/eBPFSvc.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
<ItemGroup>
<ResourceCompile Include="$(SolutionDir)resource\ebpf_resource.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion external/ebpf-verifier
Submodule ebpf-verifier updated 73 files
+47 −26 README.md
+1 −1 ebpf-samples
+0 −0 external/CLI11/CLI11.hpp
+1 −1 external/bpf_conformance
+1 −1 external/libbtf
+1 −1 scripts/.check-license.ignore
+304 −0 scripts/format-code
+337 −0 scripts/format-code.ps1
+4 −0 scripts/pre-commit
+34 −28 src/asm_cfg.cpp
+12 −14 src/asm_files.cpp
+2 −2 src/asm_files.hpp
+2 −4 src/asm_marshal.cpp
+104 −87 src/asm_ostream.cpp
+5 −19 src/asm_ostream.hpp
+1 −1 src/asm_parse.cpp
+37 −16 src/asm_syntax.hpp
+1 −1 src/asm_unmarshal.cpp
+1 −1 src/asm_unmarshal.hpp
+69 −66 src/assertions.cpp
+0 −17 src/config.cpp
+28 −13 src/config.hpp
+1 −2 src/crab/add_bottom.hpp
+4 −4 src/crab/array_domain.cpp
+10 −10 src/crab/bitset_domain.cpp
+7 −7 src/crab/bitset_domain.hpp
+57 −47 src/crab/cfg.hpp
+89 −41 src/crab/ebpf_domain.cpp
+19 −16 src/crab/ebpf_domain.hpp
+23 −26 src/crab/fwd_analyzer.cpp
+1 −1 src/crab/fwd_analyzer.hpp
+30 −30 src/crab/split_dbm.cpp
+1 −1 src/crab/split_dbm.hpp
+11 −13 src/crab/thresholds.cpp
+3 −3 src/crab/thresholds.hpp
+9 −25 src/crab/type_domain.cpp
+3 −9 src/crab/type_domain.hpp
+1 −1 src/crab/wto.cpp
+15 −0 src/crab/wto.hpp
+4 −4 src/crab_utils/adapt_sgraph.hpp
+1 −1 src/crab_utils/debug.cpp
+1 −1 src/crab_utils/debug.hpp
+21 −21 src/crab_utils/graph_ops.hpp
+16 −17 src/crab_utils/stats.cpp
+1 −1 src/crab_utils/stats.hpp
+25 −30 src/crab_verifier.cpp
+3 −3 src/crab_verifier.hpp
+11 −0 src/ebpf_base.h
+2 −2 src/linux/gpl/spec_prototypes.cpp
+12 −11 src/linux/linux_platform.cpp
+15 −15 src/main/check.cpp
+1 −1 src/main/linux_verifier.cpp
+1 −1 src/main/run_yaml.cpp
+5 −3 src/main/utils.hpp
+9 −4 src/spec_type_descriptors.hpp
+4 −4 src/test/conformance_check.cpp
+37 −31 src/test/ebpf_yaml.cpp
+3 −3 src/test/ebpf_yaml.hpp
+5 −5 src/test/test_conformance.cpp
+14 −13 src/test/test_marshal.cpp
+1 −2 src/test/test_print.cpp
+79 −79 src/test/test_verify.cpp
+3 −3 src/test/test_wto.cpp
+18 −0 test-data/assign.yaml
+40 −0 test-data/atomic.yaml
+15 −3 test-data/call.yaml
+35 −0 test-data/calllocal.yaml
+10 −1 test-data/callx.yaml
+3 −0 test-data/jump.yaml
+198 −1 test-data/loop.yaml
+68 −0 test-data/pointer.yaml
+23 −0 test-data/stack.yaml
+13 −6 test-data/subtract.yaml
22 changes: 11 additions & 11 deletions libs/api/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ _Must_inspect_result_ ebpf_result_t
load_byte_code(
std::variant<std::string, std::vector<uint8_t>>& file_or_buffer,
_In_opt_z_ const char* section_name,
_In_ const ebpf_verifier_options_t* verifier_options,
_In_ const ebpf_verifier_options_t& verifier_options,
_In_z_ const char* pin_root_path,
_Inout_ std::vector<ebpf_program_t*>& programs,
_Inout_ std::vector<ebpf_map_t*>& maps,
Expand Down Expand Up @@ -486,7 +486,7 @@ ebpf_api_elf_enumerate_programs(
_Outptr_result_maybenull_ ebpf_api_program_info_t** infos,
_Outptr_result_maybenull_z_ const char** error_message) noexcept
{
ebpf_verifier_options_t verifier_options{false, false, false, false, true};
ebpf_verifier_options_t verifier_options{};
const ebpf_platform_t* platform = &g_ebpf_platform_windows;
std::ostringstream str;

Expand All @@ -497,7 +497,7 @@ ebpf_api_elf_enumerate_programs(
ebpf_clear_thread_local_storage();

try {
auto raw_programs = read_elf(file, section ? std::string(section) : std::string(), &verifier_options, platform);
auto raw_programs = read_elf(file, section ? std::string(section) : std::string(), verifier_options, platform);
for (const auto& raw_program : raw_programs) {
info = (ebpf_api_program_info_t*)ebpf_allocate(sizeof(*info));
if (info == nullptr) {
Expand All @@ -513,7 +513,7 @@ ebpf_api_elf_enumerate_programs(
return 1;
}
auto& program = std::get<InstructionSeq>(programOrError);
cfg_t controlFlowGraph = prepare_cfg(program, raw_program.info, true);
cfg_t controlFlowGraph = prepare_cfg(program, raw_program.info, verifier_options.cfg_opts);
std::map<std::string, int> stats = collect_stats(controlFlowGraph);
for (auto it = stats.rbegin(); it != stats.rend(); ++it) {
_ebpf_add_stat(info, it->first, it->second);
Expand Down Expand Up @@ -572,7 +572,7 @@ ebpf_api_elf_disassemble_program(
_Outptr_result_maybenull_z_ const char** disassembly,
_Outptr_result_maybenull_z_ const char** error_message) noexcept
{
ebpf_verifier_options_t verifier_options = ebpf_verifier_default_options;
ebpf_verifier_options_t verifier_options{};
const ebpf_platform_t* platform = &g_ebpf_platform_windows;
std::ostringstream error;
std::ostringstream output;
Expand All @@ -584,7 +584,7 @@ ebpf_api_elf_disassemble_program(

try {
std::string section(section_name ? section_name : "");
auto raw_programs = read_elf(file, section, &verifier_options, platform);
auto raw_programs = read_elf(file, section, verifier_options, platform);
auto found_program =
std::find_if(raw_programs.begin(), raw_programs.end(), [&program_name](const raw_program& program) {
return (program_name == nullptr) || (program.function_name == program_name);
Expand Down Expand Up @@ -649,17 +649,17 @@ _ebpf_api_elf_verify_program_from_stream(

try {
const ebpf_platform_t* platform = &g_ebpf_platform_windows;
ebpf_verifier_options_t verifier_options = ebpf_verifier_default_options;
ebpf_verifier_options_t verifier_options{};
verifier_options.assume_assertions = verbosity < EBPF_VERIFICATION_VERBOSITY_VERBOSE;
verifier_options.check_termination = true;
verifier_options.cfg_opts.check_for_termination = true;
verifier_options.print_invariants = verbosity >= EBPF_VERIFICATION_VERBOSITY_INFORMATIONAL;
verifier_options.print_failures = true;
verifier_options.mock_map_fds = true;
verifier_options.print_line_info = true;
if (!stream) {
throw std::runtime_error(std::string("No such file or directory opening ") + stream_name);
}
auto raw_programs = read_elf(stream, stream_name, section_name, &verifier_options, platform);
auto raw_programs = read_elf(stream, stream_name, section_name, verifier_options, platform);
std::optional<raw_program> found_program;
for (auto& program : raw_programs) {
if ((program_name == nullptr) || (program.function_name == program_name)) {
Expand All @@ -683,9 +683,9 @@ _ebpf_api_elf_verify_program_from_stream(
}
auto& program = std::get<InstructionSeq>(programOrError);

verifier_options.simplify = false;
verifier_options.cfg_opts.simplify = false;
bool res =
ebpf_verify_program(output, program, raw_program.info, &verifier_options, (ebpf_verifier_stats_t*)stats);
ebpf_verify_program(output, program, raw_program.info, verifier_options, (ebpf_verifier_stats_t*)stats);
if (!res) {
error << "Verification failed";
*error_message = allocate_string(error.str());
Expand Down
2 changes: 1 addition & 1 deletion libs/api/Verifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ _Must_inspect_result_ ebpf_result_t
load_byte_code(
std::variant<std::string, std::vector<uint8_t>>& file_or_buffer,
_In_opt_z_ const char* section_name,
_In_ const ebpf_verifier_options_t* verifier_options,
_In_ const ebpf_verifier_options_t& verifier_options,
_In_z_ const char* pin_root_path,
_Inout_ std::vector<ebpf_program_t*>& programs,
_Inout_ std::vector<ebpf_map_t*>& maps,
Expand Down
12 changes: 8 additions & 4 deletions libs/api/ebpf_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ _Guarded_by_(_ebpf_state_mutex) static std::vector<ebpf_object_t*> _ebpf_objects
#define SERVICE_PARAMETERS L"Parameters"
#define NPI_MODULE_ID L"NpiModuleId"

#define NO_EXCEPT_TRY noexcept try
#define NO_EXCEPT_TRY \
noexcept \
try

#define CATCH_NO_MEMORY_FD \
catch (const std::bad_alloc&) { EBPF_RETURN_FD(ebpf_fd_invalid); }
Expand Down Expand Up @@ -2278,11 +2280,12 @@ _initialize_ebpf_object_from_elf(

ebpf_result_t result = EBPF_SUCCESS;

ebpf_verifier_options_t verifier_options{false, false, false, false, false};
ebpf_verifier_options_t verifier_options{};

result = load_byte_code(
file_or_data,
nullptr,
&verifier_options,
verifier_options,
pin_root_path ? pin_root_path : DEFAULT_PIN_ROOT_PATH,
object.programs,
object.maps,
Expand Down Expand Up @@ -4174,7 +4177,8 @@ typedef struct _ebpf_ring_buffer_subscription
: unsubscribed(false), ring_buffer_map_handle(ebpf_handle_invalid), sample_callback_context(nullptr),
sample_callback(nullptr), buffer(nullptr), reply({}), async_ioctl_completion(nullptr),
async_ioctl_failed(false)
{}
{
}
~_ebpf_ring_buffer_subscription()
{
EBPF_LOG_ENTRY();
Expand Down
11 changes: 11 additions & 0 deletions libs/api_common/api_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@
#include "ebpf_api.h"
#include "ebpf_execution_context.h"
#include "ebpf_utilities.h"

#pragma warning(push)
#pragma warning(disable : 26439) // This kind of function should not throw. Declare it 'noexcept'.
#pragma warning(disable : 26451) // Arithmetic overflow: Using operator '+' on a 4 byte value and then casting the
// result to a 8 byte value.
#undef min // don't interfere with C++ min/max definitions required inside platform.hpp.
#undef max
#include "platform.hpp"
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#pragma warning(pop)

#include "windows_platform_common.hpp"

#include <errno.h>
Expand Down
10 changes: 5 additions & 5 deletions libs/service/verifier_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ _analyze(raw_program& raw_prog, const char** error_message, uint32_t* error_mess
InstructionSeq& prog = std::get<InstructionSeq>(prog_or_error);

// First try optimized for the success case.
ebpf_verifier_options_t options = ebpf_verifier_default_options;
ebpf_verifier_options_t options{};
ebpf_verifier_stats_t stats;
options.check_termination = true;
bool res = ebpf_verify_program(std::cout, prog, raw_prog.info, &options, &stats);
options.cfg_opts.check_for_termination = true;
bool res = ebpf_verify_program(std::cout, prog, raw_prog.info, options, &stats);
if (!res) {
// On failure, retry to get the more detailed error message.
std::ostringstream oss;
options.simplify = false;
options.cfg_opts.simplify = false;
options.print_failures = true;
// Until https://github.com/vbpf/ebpf-verifier/issues/643 is fixed, don't set options.assume_assertions to true.
(void)ebpf_verify_program(oss, prog, raw_prog.info, &options, &stats);
(void)ebpf_verify_program(oss, prog, raw_prog.info, options, &stats);

*error_message = allocate_string(oss.str(), error_message_size);
return EBPF_VERIFICATION_FAILED; // Error;
Expand Down
Loading

0 comments on commit 7eb78c0

Please sign in to comment.