-
Notifications
You must be signed in to change notification settings - Fork 206
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
Set empty program name to hash of instructions #3493
base: main
Are you sure you want to change the base?
Set empty program name to hash of instructions #3493
Conversation
This puts hash.cpp/hash.h in a more central location for use by other project files.
ebpf_program_load_bytes now hashes the instructions and uses that for the name instead of generating a random number. Closes microsoft#3443
Sorting out signed/unsigned mismatch this caused to make build fail. |
REQUIRE(program_info.nr_map_ids == 0); | ||
REQUIRE(program_info.map_ids == 0); | ||
REQUIRE(program_info.name != NULL); | ||
// Name should contain SHA256 hash in hex (minus last char to stay under BPF_OBJ_NAME_LEN) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Name should contain SHA256 hash in hex (minus last char to stay under BPF_OBJ_NAME_LEN) | |
// Name should contain SHA256 hash in hex (minus last char to stay under BPF_OBJ_NAME_LEN). |
@@ -1,10 +1,10 @@ | |||
// Copyright (c) eBPF for Windows contributors | |||
// SPDX-License-Identifier: MIT | |||
|
|||
#include "../../libs/shared/hash.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than putting the path here, it's better to put it in the include path in the vcxproj file.
Description
Resolves #3443 by using the SHA256 hash of the program instructions as the program name instead of using
rand()
to generate the name.Instruction lists are now given a unique name (fixing the issue), and this solution avoids any potential problems from changing the
rand()
state for the process. Only the first 63 characters of the hash are used to keep under bpf object length limit (64).As part of this change, hash.cpp and hash.h were moved from tests/libs/util to libs/shared so they are in a more central location for use in other project files.
Testing
Adds ebpf_program_load_bytes-name-gen test case in end_to_end.cpp
Documentation
N/A
Installation
N/A