Skip to content

Conversation

@arthur-zhang
Copy link
Contributor

@arthur-zhang arthur-zhang commented Dec 27, 2024

Fixes

Description

cwd_read do not assign data->vfsmnt correctly.

reproduce:

sudo mount -t nfs  x.x.x.x:/data/dev/nfs_dir /home/arthur/my_run

$ mount -t
x.x.x.x:/data/dev/nfs_dir on /home/arthur/my_run
/dev/nvme0n1p5 on /home type ext4 (rw,relatime)

and cat a file in my_run dir

cat /home/arthur/my_run/a.txt

in tetragon side, it will get a path : /home/home/arthur/my_run/a.txt, but it should be /home/arthur/my_run/a.txt

cat-2152134 [003] d...1 3725192.671779: bpf_trace_printk: copy path: /home/home/arthur/my_run/a.txt

and in another production env, i found it will get path more than expected when i cat /tmp/tetragon. the prefix /scon/containers/01J6HEV7R29R4WXXS1N2CS9ATP/rootfs/ should not be obtained.

/scon/containers/01J6HEV7R29R4WXXS1N2CS9ATP/rootfs/tmp/tetragon

in the old code, mnt is pointer to the old data->mnt, which is not correct.

struct mount *mnt = data->mnt;
...
if (data->mnt != parent) {
    probe_read(&data->dentry, sizeof(data->dentry),
			    _(&mnt->mnt_mountpoint));
    data->mnt = parent;
    probe_read(&data->vfsmnt, sizeof(data->vfsmnt),
			    _(&mnt->mnt));
    return 0;
}

Changelog

Fix vfsmnt assign bug in bpf/process/bpf_process_event.h

@arthur-zhang arthur-zhang requested a review from a team as a code owner December 27, 2024 04:01
@arthur-zhang arthur-zhang changed the title fix: update cwd_read to assign vfsmnt correctly bug: fix assign vfsmnt correctly Jan 3, 2025
@olsajiri
Copy link
Contributor

olsajiri commented Jan 3, 2025

Fixes

Description

cwd_read do not assign data->vfsmnt correctly.

reproduce:

sudo mount -t nfs  x.x.x.x:/data/dev/nfs_dir /home/arthur/my_run

$ mount -t
x.x.x.x:/data/dev/nfs_dir on /home/arthur/my_run
/dev/nvme0n1p5 on /home type ext4 (rw,relatime)

and cat a file in my_run dir

cat /home/arthur/my_run/a.txt

in tetragon side, it will get a path : /home/home/arthur/my_run/a.txt, but it should be /home/arthur/my_run/a.txt

cat-2152134 [003] d...1 3725192.671779: bpf_trace_printk: copy path: /home/home/arthur/my_run/a.txt

and in another production env, i found it will get path more than expected when i cat /tmp/tetragon. the prefix /scon/containers/01J6HEV7R29R4WXXS1N2CS9ATP/rootfs/ should not be obtained.

/scon/containers/01J6HEV7R29R4WXXS1N2CS9ATP/rootfs/tmp/tetragon

in the old code, mnt is pointer to the old data->mnt, which is not correct.

struct mount *mnt = data->mnt;
...
if (data->mnt != parent) {
    probe_read(&data->dentry, sizeof(data->dentry),
			    _(&mnt->mnt_mountpoint));
    data->mnt = parent;
    probe_read(&data->vfsmnt, sizeof(data->vfsmnt),
			    _(&mnt->mnt));
    return 0;
}

Changelog

Fix vfsmnt assign bug in bpf/process/bpf_process_event.h

@arthur-zhang please put all this in the commit changelog, also any chance you could add test the issue? thanks

data->mnt = parent;
probe_read(&data->vfsmnt, sizeof(data->vfsmnt),
_(&mnt->mnt));
data->vfsmnt = &parent->mnt;
Copy link
Contributor

Choose a reason for hiding this comment

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

ok, parent->mnt is not pointer but actual vfsmnt object embedded in mount struct,
so we can just take the address from parent.. but I think you still need to use _() to get CORE involved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, i will fix it

@netlify
Copy link

netlify bot commented Jan 6, 2025

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit b32361f
🔍 Latest deploy log https://app.netlify.com/sites/tetragon/deploys/677b42c18107ed0008525bb8
😎 Deploy Preview https://deploy-preview-3261--tetragon.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.

@arthur-zhang arthur-zhang requested a review from olsajiri January 6, 2025 02:41
@kkourt kkourt self-requested a review January 6, 2025 12:09
@olsajiri olsajiri added the release-note/minor This PR introduces a minor user-visible change label Jan 8, 2025
Copy link
Contributor

@olsajiri olsajiri left a comment

Choose a reason for hiding this comment

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

please add missing changelog and it's good to go, thanks

The current code incorrectly assigns vfsmnt during path resolution, causing duplicate or unexpected path prefixes. This commit ensures correct path resolution across different mount types and environments.

Signed-off-by: arthur-zhang <happyzhangya@gmail.com>
@olsajiri olsajiri merged commit 0073b43 into cilium:main Jan 9, 2025
39 of 40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/minor This PR introduces a minor user-visible change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants