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.
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
fix(driver/bpf): bpf_addr_to_kernel takes an unsigned length (less than BPF_MAX_VAR_SIZE) #1730
base: dev
Are you sure you want to change the base?
fix(driver/bpf): bpf_addr_to_kernel takes an unsigned length (less than BPF_MAX_VAR_SIZE) #1730
Changes from all commits
9caa409
4c2353a
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
This seems to increase the valid range of ulen. Previously the function would return
-EINVAL
ifulen > sizeof(struct sockaddr_storage)
, but on my machine thatsizeof
operation resolves to 128, which is far, far less thanBPF_MAX_VAR_SIZE
. Is this intended?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.
Looks like we're doing
ulen & 0xff
(more or less) below. I feel that we should return an error wheneverulen > 0xff
(otherwise the caller can request e.g. 0x1ff bytes--the value comes straight from userspace--while we copy 0xff and return success).The original check against
sizeof(struct sockaddr_storage)
feels more correct.Also, not sure what exactly BPF_FORBIDS_ZERO_ACCESS implies but if my guess (length must be > 0) is correct, both the
#ifdef
and the& 0xff
(if we revert the size check) is unnecessary (ulen will always be > 0 after line 224 and < 0xff after original line 218).Though I expect both are there to keep the verifier happy?
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.
That check seems like a leftover from move_addr_to_kernel kernel function.
Anyways, we read at maximum
ulen & 0xff
every time (seebpf_probe_read
below).After some intensive and day-long testing, we (@fntlnz and I) have not been able to break it.
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.
@gnosek The verifier rejects a check against
sizeof(struct sockaddr_storage)
.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.
Anyway the bug here was about the
int
(nowunsigned long
) parameter and the missing boundary check.Both were required by the verifier (giving two different errors on each of them). Thus, this is the scope of this PR.
In case we'd like to optimize the behaviour of the mask and the presence (or not) of ifdefs, we should approach those in another PR, imho.
As per our testing, they do not interfere with the correct functioning of the probe.
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.
So if you replace
BPF_MAX_VAR_SIZE
withsizeof(struct sockaddr_storage)
, the verifier fails?That is bizarre. That seems like a bug in the verifier.
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.
Yes, we tried in many many ways to retain that check too, but the verifier rejects it.