Skip to content
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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

mikeagun
Copy link
Collaborator

@mikeagun mikeagun commented Apr 24, 2024

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

Michael Agun added 2 commits April 24, 2024 12:28
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
@mikeagun mikeagun changed the title Set empty program name to hash of instructions (#3443) Set empty program name to hash of instructions Apr 24, 2024
@mikeagun mikeagun marked this pull request as draft April 25, 2024 15:44
@mikeagun
Copy link
Collaborator Author

Sorting out signed/unsigned mismatch this caused to make build fail.

@mikeagun mikeagun marked this pull request as ready for review May 23, 2024 20:24
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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"
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ebpf_program_load_bytes() always calls srand before generating random program name
3 participants