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

Lsm cgroup api #1135

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

altugbozkurt07
Copy link

@altugbozkurt07 altugbozkurt07 commented Jan 14, 2025

Hi @vadorovsky, @dave-tucker,

This is the refactored work based on the discussion we have had on discord.
Let me know if i missed anything.

Best

This change is Reviewable

Copy link

netlify bot commented Jan 14, 2025

Deploy Preview for aya-rs-docs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit f2493ab
🔍 Latest deploy log https://app.netlify.com/sites/aya-rs-docs/deploys/6787bcd81568b4000893d05e
😎 Deploy Preview https://deploy-preview-1135--aya-rs-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mergify mergify bot added aya This is about aya (userspace) aya-bpf This is about aya-bpf (kernel) aya-obj Relating to the aya-obj crate test A PR that improves test cases or CI labels Jan 14, 2025
@tamird
Copy link
Member

tamird commented Jan 14, 2025

Please avoid opening a new PR each time. There are comments I left in #1131 that remain unaddressed.

@altugbozkurt07
Copy link
Author

@tamird sorry, since we have changed the way we implemented api, i thought it deserved a new pr.

For the comments that remain unaddressed;
1- nix package is used in init crate so that is why i left it there. If you still want me to remove it from workspace and include it in specific crates where its used.
2- Done
3- Done
4- Removed the empty comment line
5- The changes proposed in this pr

Am i missing something other than what is stated in your comments?

Copy link
Member

@dave-tucker dave-tucker left a comment

Choose a reason for hiding this comment

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

I've take a quick pass over and there are a few nits that need clearing up.
Please also check that the docs build and render correctly 🙏

Cargo.toml Outdated
@@ -78,7 +78,7 @@ indoc = { version = "2.0", default-features = false }
libc = { version = "0.2.105", default-features = false }
log = { version = "0.4", default-features = false }
netns-rs = { version = "0.1", default-features = false }
nix = { version = "0.29.0", default-features = false }
nix = { version = "0.29.0", default-features = true }
Copy link
Member

Choose a reason for hiding this comment

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

Per comment in the previous review this should be:

nix = { version = "0.29.0", default-features = false }

@@ -28,6 +28,7 @@ test-case = { workspace = true }
test-log = { workspace = true, features = ["log"] }
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "time"] }
xdpilone = { workspace = true }
nix = { workspace = true, features = ["process"] }
Copy link
Member

Choose a reason for hiding this comment

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

You would add any other features that were required from nix here.
I assume you needed something from the default featureset given the change in the main Cargo.toml.

@@ -19,6 +19,7 @@ impl Lsm {
let hook = pop_string_arg(&mut args, "hook");
let sleepable = pop_bool_arg(&mut args, "sleepable");
err_on_unknown_args(&args)?;

Copy link
Member

Choose a reason for hiding this comment

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

stray newline

@@ -39,15 +40,15 @@ impl Lsm {
block: _,
} = item;
let section_prefix = if *sleepable { "lsm.s" } else { "lsm" };
let section_name: Cow<'_, _> = if let Some(hook) = hook {
format!("{}/{}", section_prefix, hook).into()
let section_name: Cow<'_, _> = if let Some(name) = hook {
Copy link
Member

Choose a reason for hiding this comment

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

There's no need to rename these variables.

} else {
section_prefix.into()
};
let fn_name = &sig.ident;
Copy link
Member

Choose a reason for hiding this comment

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

Also no need to move this line.

Copy link
Author

Choose a reason for hiding this comment

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

sorry but i didnt understand the problem on this one, can you elobarate on this ?

Copy link
Member

Choose a reason for hiding this comment

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

Just undo this change.

/// [1]: https://elixir.bootlin.com/linux/latest/source/include/linux/lsm_hook_defs.h
#[derive(Debug)]
#[doc(alias = "BPF_PROG_TYPE_LSM")]
pub struct Lsm {
pub(crate) data: ProgramData<LsmLink>,
pub(crate) attach_type: LsmAttachType,
Copy link
Member

Choose a reason for hiding this comment

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

You can remove this.

@@ -60,7 +62,7 @@ impl Lsm {
/// * `lsm_hook_name` - full name of the LSM hook that the program should
/// be attached to
pub fn load(&mut self, lsm_hook_name: &str, btf: &Btf) -> Result<(), ProgramError> {
self.data.expected_attach_type = Some(BPF_LSM_MAC);
self.data.expected_attach_type = Some(self.attach_type.into());
Copy link
Member

Choose a reason for hiding this comment

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

This can be reverted also

/// The minimum kernel version required to use this feature is 6.0.
///
/// # Examples
/// ## LSM with cgroup attachment type
Copy link
Member

Choose a reason for hiding this comment

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

Remove this subheading

Copy link
Author

Choose a reason for hiding this comment

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

if i remove this subheading, should i also remove it from lsm.rs ?

/// program.load("security_bprm_exec", &btf)?;
/// program.attach(file)?;
/// # Ok::<(), LsmError>(())
/// ```
Copy link
Member

Choose a reason for hiding this comment

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

I think you might need a newline after the end of the code block.

let prog_fd = self.fd()?;
let prog_fd = prog_fd.as_fd();
let cgroup_fd = cgroup.as_fd();
let attach_type = self.data.expected_attach_type.unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let attach_type = self.data.expected_attach_type.unwrap();
let attach_type = Some(BPF_LSM_CGROUP);

@tamird
Copy link
Member

tamird commented Jan 14, 2025

Please let us know when the tests are passing, or if you need help understanding the failures.

@altugbozkurt07
Copy link
Author

@dave-tucker thanks for your detailed feedback, i have updated the commit accordingly. Let me know if things are good to go for this one.

Copy link
Member

@tamird tamird left a comment

Choose a reason for hiding this comment

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

Tests are failing.

@@ -649,14 +651,17 @@ impl<'a> EbpfLoader<'a> {
ProgramSection::RawTracePoint => Program::RawTracePoint(RawTracePoint {
data: ProgramData::new(prog_name, obj, btf_fd, *verifier_log_level),
}),
ProgramSection::Lsm { sleepable } => {
ProgramSection::Lsm { sleepable , .. } => {
Copy link
Member

Choose a reason for hiding this comment

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

Undo this please.

@@ -1,7 +1,6 @@
//! LSM probes.
use crate::{
Copy link
Member

Choose a reason for hiding this comment

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

Restore.

@@ -967,7 +979,6 @@ impl_from_pin!(
CgroupSysctl,
LircMode2,
PerfEvent,
Lsm,
Copy link
Member

Choose a reason for hiding this comment

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

Why did this change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aya This is about aya (userspace) aya-bpf This is about aya-bpf (kernel) aya-obj Relating to the aya-obj crate test A PR that improves test cases or CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants