aya: Ensure that truncated map names are NULL terminated#1216
aya: Ensure that truncated map names are NULL terminated#1216vadorovsky merged 1 commit intoaya-rs:mainfrom
Conversation
✅ Deploy Preview for aya-rs-docs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
29467f3 to
e272c87
Compare
|
@dave-tucker @tamird this looks wild https://github.com/aya-rs/aya/actions/runs/13806711273/job/38618907343?pr=1216 given no API changes in my PR. I'll try to reproduce locally, but looks that something fishy is going on with public-api. |
|
nvm, I missed #1215 |
e272c87 to
e283ee2
Compare
aya/src/sys/bpf.rs
Outdated
| // u.map_name is 16 bytes max and must be NULL terminated | ||
| let name_bytes = name.to_bytes_with_nul(); | ||
| let len = cmp::min(name_bytes.len(), u.map_name.len()); | ||
| let len = cmp::min(name_bytes.len(), u.map_name.len() - 1); |
There was a problem hiding this comment.
Hmmm I annoyed at myself:
#1165 (comment)
I should have caught that using cmp::min would strip the nul byte 😭
Do you recall offhand if the rules are the same for program names as the logic there was changed in the same commit
tamird
left a comment
There was a problem hiding this comment.
Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @dave-tucker)
aya/src/sys/bpf.rs line 97 at r1 (raw file):
if KernelVersion::at_least(4, 15, 0) { let name_bytes = name.to_bytes(); // u.map_name is 16 bytes max and must be NULL terminated
can we drop this comment and follow the style used below?
let len = ...; // Ensure NULL termination.
aya/src/sys/bpf.rs line 153 at r1 (raw file):
if let Some(name) = &aya_attr.name { let name_bytes = name.to_bytes(); let len = cmp::min(name_bytes.len(), u.prog_name.len() - 1); // Ensure NULL termination.
@dave-tucker I think I fixed this after the original commit - the truncation was happening on the ingress path
aya/src/sys/bpf.rs
Outdated
| // u.map_name is 16 bytes max and must be NULL terminated | ||
| let name_bytes = name.to_bytes_with_nul(); | ||
| let len = cmp::min(name_bytes.len(), u.map_name.len()); | ||
| let len = cmp::min(name_bytes.len(), u.map_name.len() - 1); |
tamird
left a comment
There was a problem hiding this comment.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @dave-tucker and @vadorovsky)
e283ee2 to
4eece1c
Compare
vadorovsky
left a comment
There was a problem hiding this comment.
Reviewable status: 1 of 2 files reviewed, 2 unresolved discussions (waiting on @dave-tucker and @tamird)
aya/src/sys/bpf.rs line 97 at r1 (raw file):
Previously, tamird (Tamir Duberstein) wrote…
can we drop this comment and follow the style used below?
let len = ...; // Ensure NULL termination.
Done.
Limit of map names in eBPF is 16 bytes and they have to be NULL terminated. Before this change, long names were truncated to 16 bytes. `MAP_WITH_LOOOONG_NAAAAAAAAME` would become `MAP_WITH_LOOOONG`, which doesn't contain the NULL byte. This change fixes that by truncating the name to 15 bytes, ensuring that the 16th byte is NULL. `MAP_WITH_LOOOONG_NAAAAAAAAME` is truncated to `MAP_WITH_LOOOON\0`.
tamird
left a comment
There was a problem hiding this comment.
Reviewed 1 of 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @dave-tucker)
4eece1c to
b035d79
Compare
Limit of map names in eBPF is 16 bytes and they have to be NULL terminated.
Before this change, long names were truncated to 16 bytes.
MAP_WITH_LOOOONG_NAAAAAAAAMEwould becomeMAP_WITH_LOOOONG, which doesn't contain the NULL byte.This change fixes that by truncating the name to 15 bytes, ensuring that the 16th byte is NULL.
MAP_WITH_LOOOONG_NAAAAAAAAMEis truncated toMAP_WITH_LOOOON\0.This change is