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

program: don't return error when kmod BTF is disabled #1440

Merged

Conversation

orishuss
Copy link
Contributor

In kernels where the flag CONFIG_DEBUG_INFO_BTF_MODULES is not set, including kernels 5.10 and below (because the flag was introduced in 5.11), loading a program that attaches to kernel module functions and relied on CORE failed because the module's BTF is not available.

This fix allows the program to run, obviously only as long as it only relies on the kernel's BTF and not on the specific module's BTF.

Fixes: #1436. Tested on the same example included in the issue: when using the fixed package, the program attaches successfully.

@orishuss orishuss requested review from dylandreimerink and a team as code owners April 17, 2024 11:24
@orishuss orishuss force-pushed the bugfix/kernel-module-program-relocation-fail branch 2 times, most recently from 89722af to a52d372 Compare April 17, 2024 11:28
Copy link
Member

@dylandreimerink dylandreimerink left a comment

Choose a reason for hiding this comment

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

Changes look good to me. Note that the commit isn't signed off

@lmb
Copy link
Collaborator

lmb commented Apr 17, 2024

Could you extend testdata/manyprogs.c to include one section for kprobe/ctnetlink_fill_info or similar? Then we should get coverage of this on our 5.10 CI run.

@orishuss orishuss force-pushed the bugfix/kernel-module-program-relocation-fail branch 4 times, most recently from c035ab3 to 9b6aefc Compare April 21, 2024 07:19
@lmb lmb force-pushed the bugfix/kernel-module-program-relocation-fail branch from 1b7ad20 to 3b9d208 Compare April 22, 2024 10:57
@lmb lmb changed the title Fix kernel module program relocation fail program: don't return error when kmod BTF is disabled Apr 22, 2024
@lmb
Copy link
Collaborator

lmb commented Apr 22, 2024

I've had to drop the test in manyprogs.c since the file is only used from benchmarks. I tried to come up with a way to test this in CI, but it's not straight forward :( I also updated your first commit to include the useful PR description.

Unrelated to this, I want to make sure that the new semantics actually make sense.

  • If your kernel lacks kmod BTF you will be able to load a kprobe with an AttachTo in a kmod. This is necessary to keep the old behaviour.
  • You won't get an error from the library if your code tries to use types from the module. Instead you'll get some harder-to-diagnose error from the verifier. This is because we don't know upfront whether a program does rely on types from the kmod or not.

In kernels where the flag CONFIG_DEBUG_INFO_BTF_MODULES is not set,
including kernels 5.10 and below (because the flag was introduced in 5.11),
loading a program that attaches to kernel module functions and relied on
CORE failed because the module's BTF is not available.

This fix allows the program to run, obviously only as long as it only
relies on the kernel's BTF and not on the specific module's BTF.

Fixes: cilium#1436
Signed-off-by: Ori Shussman <[email protected]>
@lmb lmb force-pushed the bugfix/kernel-module-program-relocation-fail branch from 3b9d208 to 085d688 Compare April 22, 2024 11:07
@lmb lmb merged commit 20ddfe1 into cilium:main Apr 22, 2024
15 checks passed
@lmb
Copy link
Collaborator

lmb commented Apr 22, 2024

Thanks for your contribution!

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.

program: relocation of program targeting a module fails if CONFIG_DEBUG_INFO_BTF_MODULES is disabled
3 participants