-
Notifications
You must be signed in to change notification settings - Fork 252
Canonicalize pin paths #4274
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
Merged
Merged
Canonicalize pin paths #4274
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fcbf713
Canonicalize pin paths using filesystem canonicalization rules
dthaler 193c1ee
Update some bpftool_tests
dthaler 3701e09
Add decision to PinPaths.md
dthaler cd81ff8
Address PR feedback
dthaler ee67e12
Address PR feedback
dthaler 2b9d7ac
Export ebpf_canonicalize_pin_path
dthaler 123f846
PR feedback
dthaler 976a8ac
Update tests per discussion in triage meeting
dthaler 72c28d2
More regression test updates in bpftool test
dthaler 59ad375
Add another test case
dthaler cdc4766
Merge branch 'main' into canonicalize-paths
dthaler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
# Pin path design | ||
|
||
On Linux, objects can be pinned to a filesystem path. As a result: | ||
* Pins can be enumerated or removed via normal filesystem APIs/utilities | ||
* Pin paths are case-sensitive | ||
* The path component separator is a forward slash ('/') | ||
* Pin paths typically begin with "/sys/fs/bpf/", but could begin with other | ||
paths. Relative paths like "mymap" are then relative to that prefix. | ||
* ".." and "." components are resolved. | ||
|
||
On Windows, pin paths are not currently part of the filesystem. As a result, | ||
pins cannot be removed via normal filesystem deletion APIs/utilities and instead | ||
ebpf_get_next_pinned_object_path() and ebpf_object_unpin() are exposed | ||
for enumeration and unpinning, respectively. | ||
|
||
This leaves open the question of what syntax(es) we support on Windows for pin paths. | ||
|
||
## Criteria for Evaluation | ||
|
||
The following are criteria for evaluating each option: | ||
|
||
1. Slashes: Paths must be accepted using either '/' or '\\' and be canonicalized. | ||
|
||
1. Kernel: Canonicalization must be the same in kernel-mode (for native) and user-mode (for JIT). | ||
|
||
1. LocalFile: A pin path should not collide with the path of another file in the Windows filesystem. | ||
|
||
1. RemoteFile: Avoid confusion with remote paths. | ||
|
||
1. FileAPIs: Paths should work with Windows file APIs in the future once a BPF filesystem is implemented. | ||
|
||
1. CaseSensitive: Paths should be case-sensitive. | ||
|
||
## Options | ||
|
||
### Native (Actual file system path) | ||
|
||
Example: C:\ebpf\global\my\pin\path | ||
|
||
In this option, querying the path of a pinned object would give an actual file system path. | ||
This might be confusing if the path conflicts with an actual path where there may be files, | ||
so additional care would be needed to fail such a pin. | ||
|
||
Furthermore, an actual file system path would be case-insensitive rather than case-sensitive. | ||
Another implementation challenge is that the logic for forming pin paths for native programs | ||
is in the kernel (to minimize security concerns), and there isn't an easy way to get the | ||
system drive, and picking "C:" would be fairly arbitrary. | ||
|
||
### Mnt (Actual file system path in Linux-style syntax) | ||
|
||
Example: /mnt/c/ebpf/global/my/pin/path | ||
|
||
Like the previous option, the current or system drive letter is still needed, so this has | ||
the same issues as the previous option. | ||
|
||
### Virtual (Windows device path with another virtual drive for BPF) | ||
|
||
Example: BPF:\my\pin\path | ||
dthaler marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Note that this is a device path not a "file system" path per se. | ||
|
||
In this option, there would be no collisions with actual files, and the path can be case | ||
sensitive if the "BPF:" driver declares it as such. Similarly, ".." resolution would work if | ||
the driver implements it as such. | ||
|
||
As for portability, canonicalization could ensure that Linux style paths like | ||
"/sys/fs/bpf/my/pin/path" would be canonicalized to "BPF:\sys\fs\bpf\my\pin\path" allowing | ||
portability in that respect. Querying the pin path using a Windows-specific | ||
API on an object would show the canonical path. | ||
|
||
### Linux (Linux-like file system path) | ||
|
||
Example: /sys/fs/bpf/my/pin/path | ||
|
||
In this option, the path would look the same as on Linux where | ||
the canonical form uses forward slash rather than backslash. | ||
It cannot be used with other Windows file system APIs in the future. | ||
|
||
### UNC (UNC path) | ||
|
||
Example: \\BPF\my\pin\path | ||
dthaler marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
In this option, "BPF" would be a special "host" like "localhost" or "?". | ||
However, it may be confusing if there is another host with the name "bpf", | ||
or at least lead people to believe there might be. | ||
|
||
### Others | ||
|
||
There are also "\\?\" and "\\.\" paths on Windows, but these don't | ||
appear to provide any value that one or more of the other options don't | ||
already provide so are omitted from the rest of the evaluation. | ||
|
||
## Evaluation Matrix | ||
|
||
The matrix below shows how each option evaluates using the | ||
criteria discussed above. "Y" means the option is good, | ||
"N" means the option is bad, and "-" means it would be somewhere | ||
in between good and bad. | ||
|
||
| Criteria | Native | Mnt | Virtual | Linux | UNC | | ||
| ------------- | ------ | --- | ------- | ----- | --- | | ||
| Slashes | Y | Y | Y | Y | Y | | ||
| Kernel | - | - | Y | Y | Y | | ||
| LocalFile | - | - | Y | Y | Y | | ||
| RemoteFile | Y | Y | Y | Y | N | | ||
| FileAPIs | Y | N | Y | N | Y | | ||
| CaseSensitive | N | N | Y | Y | Y | | ||
|
||
## Decision | ||
|
||
Based on the evaluation matrix, the Virtual form | ||
("BPF:\my\pin\path") will be the canonical form. | ||
|
||
In addition, for portability, the Linux form ("/sys/fs/bpf/my/pin/path") | ||
will be accepted as valid, as will the older eBPF for Windows | ||
path ("/ebpf/global/my/pin/path"). These will be canonicalized | ||
to "BPF:\my\pin\path" internally. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.