-
Notifications
You must be signed in to change notification settings - Fork 60
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
new(pkg/driver): try to fetch kernel headers leveraging driverkit library when building drivers #476
Conversation
5840e09
to
aba70f8
Compare
Output for a bpf probe build against drivers
As you can see:
|
c1ddf1f
to
38b5d60
Compare
Oras bump was moved to #478. |
38b5d60
to
62c3f83
Compare
/milestone v0.8.0 |
04b52d5
to
e6b4dfd
Compare
Output for a kmod build (with dkms):
|
…ing driverkit library when building drivers. Signed-off-by: Federico Di Pierro <[email protected]>
Also, bumped driverkit to falcosecurity/driverkit#324 HEAD. Signed-off-by: Federico Di Pierro <[email protected]>
…", ...)`. Moreover, bumped driverkit to latest HEAD of PR324. Signed-off-by: Federico Di Pierro <[email protected]>
Signed-off-by: Federico Di Pierro <[email protected]>
e6b4dfd
to
7e8faf5
Compare
Bumped to driverkit v0.18.0 that contains needed change. |
Moreover, added a couple of debug logs when automatically fetching headers. Signed-off-by: Federico Di Pierro <[email protected]>
"Detected an unsupported target system, please get in touch with the Falco community. Trying to compile anyway.") | ||
} else { | ||
return "", fmt.Errorf("detected an unsupported target system, please get in touch with the Falco community") | ||
if o.Distro.String() == driverdistro.UndeterminedDistro { |
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.
We need to make the check only when distro is undetermined
. This is a fix on top of current main (bug introduced in #484)
@@ -128,6 +128,26 @@ func getOSReleaseDistro(kr *kernelrelease.KernelRelease) (Distro, error) { | |||
return distro, nil | |||
} | |||
|
|||
//nolint:gocritic // the method shall not be able to modify kr | |||
func loadKernelHeadersFromDk(distro string, kr kernelrelease.KernelRelease) (string, func(), error) { |
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.
Biggest change: try to load kernel headers from Driverkit, in a simple way:
- instantiate
driverkit builder
for the current target distro - fetch the
KernelDownloadScript
from the builder, that is the driverkit script capable of downloading and extracting kernel headers for the distro - call the script; the
KernelDownloadScript
will output to stdout a single line containing the folder where the kernel headers were extracted - return a cleanup function to later remove the downloaded headers, and the headers path
@@ -179,6 +199,25 @@ func Build(ctx context.Context, | |||
if err != nil { | |||
return "", err | |||
} | |||
|
|||
if env == nil { |
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.
Avoid a segfault when later accessing the map.
|
||
// If customizeBuild did not set any KERNELDIR env variable, | ||
// try to load kernel headers urls from driverkit. | ||
if _, found := env[drivertype.KernelDirEnv]; !found { |
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.
If no customizeBuild
added the KERNELDIR
env var to the env map, we try to autoamtically download and extract kernel headers leveraging driverkit; if we are able to do so, we emplace the new KERNELDIR
env var pointing to the extraction path for the kernel headers.
@@ -61,26 +53,26 @@ func (k *kmod) String() string { | |||
// Then, using dkms, it tries to fetch all | |||
// dkms-installed versions of the module to clean them up. | |||
func (k *kmod) Cleanup(printer *output.Printer, driverName string) error { | |||
_, err := exec.Command("bash", "-c", "hash lsmod").Output() | |||
lsmod, err := exec.LookPath("lsmod") |
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.
Switch to use exec.LookPath
instead of the ugly bash magic.
driverName, driverVersion, kr.String()) | ||
var dkmsCmdArgs string | ||
if kernelDir, found := env[KernelDirEnv]; found { | ||
dkmsCmdArgs = fmt.Sprintf(`dkms install --kernelsourcedir %q --directive="MAKE='/tmp/falco-dkms-make'" -m %q -v %q -k %q --verbose`, |
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.
If KERNELDIR
env var was passed, forward it to dkms install
too!
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.
Note: ebpf
did not need any change since it was already passing all the env to the make
command.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: FedeDP, leogr The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind feature
Any specific area of the project related to this PR?
/area library
What this PR does / why we need it:
This PR introduces a mechanism to leverage driverkit library to automatically download kernel headers for driverkit supported distros, when building drivers.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer: