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

retsnoop: fix sign extension failure logic #50

Merged
merged 1 commit into from
Oct 1, 2023
Merged

Conversation

anakryiko
Copy link
Owner

If we decide that function is returning 32-bit integer (which is a default case when we can't get BTF information about the function, so this would be common right now for kernel module functions), we should truncate actual returned value (captured as u64) to 32-bit u32 before doing the comparisons inside IS_ERR_VALUE32().

This potentially could break some cases in fentry/fexit (-F) mode with pointer-returning functions (which is explained in the comment inside IS_ERR_VALUE32()), but those should be determined as pointer-returning from BTF information, and will be handled with IS_ERR_VALUE().

Reported-by: Maxim Samoylov max7255@meta.com

If we decide that function is returning 32-bit integer (which is
a default case when we can't get BTF information about the function, so
this would be common right now for kernel module functions), we should
truncate actual returned value (captured as u64) to 32-bit u32 before
doing the comparisons inside IS_ERR_VALUE32().

We needed to take extra caution to take into account that in
fentry/fexit (-F) mode, BPF verifier will disallow casting results for
pointer-returning functions. So we obfuscate such potential pointers by
storing them into map value and re-reading it back.

Reported-by: Maxim Samoylov <max7255@meta.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
@anakryiko anakryiko merged commit 2e31c92 into master Oct 1, 2023
1 check passed
@anakryiko anakryiko deleted the fix-sign-ext-logic branch October 1, 2023 03:54
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.

1 participant