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

bpf: fix path truncation in cwd and copying path arguments #3427

Merged
merged 6 commits into from
Feb 24, 2025

Conversation

mtardy
Copy link
Member

@mtardy mtardy commented Feb 20, 2025

We bumped the size of the underlying prepend_name buffer to 4096 #2764 but many users were still truncating the returned size to 255.

Fix path truncations in event values for cwd and path/file function arguments. The function responsible for reading dentry was upgraded to 4096 but some users were still using the previous limitation of 256.

@mtardy mtardy added the release-note/bug This PR fixes an issue in a previous release of Tetragon. label Feb 20, 2025
Copy link

netlify bot commented Feb 20, 2025

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit f655438
🔍 Latest deploy log https://app.netlify.com/sites/tetragon/deploys/67b8943cca1d23000824b63a
😎 Deploy Preview https://deploy-preview-3427--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.

The functions called by copy_path were updated to support up to 4096
long paths, from d_path_local to prepend_name. However, before that
update, copy_path was updated to reuse the work done via d_path_local.
Eventually, it didn't take into account that the returned buffer can be
well beyond 256 chars now. The patch fixes this by truncating to 4095
chars instead of 255.

Signed-off-by: Mahe Tardy <[email protected]>
@mtardy mtardy force-pushed the pr/mtardy/fix-path-truncation branch 2 times, most recently from c61ad84 to f655438 Compare February 21, 2025 14:56
Commit 834b5fe ("String: Support longer exact match strings") added
limitations on the size of strings parsed in userspace from the kernel
which ended up creating a bug: longer strings can technically be passed
in the event args and truncating ended up parsing incorrect flag and
i_mode values. Since the size is a security measure, I don't see the
point of limiting the value based on kernel value.

Signed-off-by: Mahe Tardy <[email protected]>
The asm was maybe no longer necessary and was restricting the maximum
size to be 1188.

Signed-off-by: Mahe Tardy <[email protected]>
@mtardy mtardy force-pushed the pr/mtardy/fix-path-truncation branch from f655438 to 8a8506f Compare February 21, 2025 15:01
This test make sure that we don't have a regression on the bug fixed in
the previous commit about truncating long args.

Signed-off-by: Mahe Tardy <[email protected]>
The current working directory was truncated to 256 while the underlying
buffer read into a buffer of 4096. This patch is raising the truncation
to 4096, making it complete as it's the max on linux.

Signed-off-by: Mahe Tardy <[email protected]>
Add a checker for a long cwd. Maybe this should be split into two
different tests but in a way it tests the same thing, reuse the same
directory structure, and we end up not having to restart tetragon twice.

Signed-off-by: Mahe Tardy <[email protected]>
@mtardy mtardy force-pushed the pr/mtardy/fix-path-truncation branch from 8a8506f to ab9fdf5 Compare February 21, 2025 19:14
@mtardy mtardy changed the title bpf: fix path truncation in copying path arguments bpf: fix path truncation in cwd and copying path arguments Feb 24, 2025
@mtardy mtardy marked this pull request as ready for review February 24, 2025 11:04
@mtardy mtardy requested a review from a team as a code owner February 24, 2025 11:04
@mtardy mtardy requested review from jrfastab, kevsecurity, olsajiri, tpapagian and kkourt and removed request for jrfastab February 24, 2025 11:04
@mtardy
Copy link
Member Author

mtardy commented Feb 24, 2025

Hey @kevsecurity, could you check that 3e39741 is okay for you? Not sure why those specific lines were added in the first place, it seems wrong.

@kkourt
Copy link
Contributor

kkourt commented Feb 24, 2025

Thanks @mtardy. Should we add backport tags for this PR?

Copy link
Member

@tpapagian tpapagian left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@mtardy
Copy link
Member Author

mtardy commented Feb 24, 2025

Thanks @mtardy. Should we add backport tags for this PR?

Mmh yes indeed, #2764 is included until v1.2.0 so it seems it should be straightforward to backport up to v1.2.0.

@mtardy mtardy added needs-backport/1.2 This PR needs backporting to 1.2 needs-backport/1.3 This PR needs backporting to 1.3 labels Feb 24, 2025
Copy link
Contributor

@kevsecurity kevsecurity left a comment

Choose a reason for hiding this comment

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

LGTM

@kevsecurity
Copy link
Contributor

Hey @kevsecurity, could you check that 3e39741 is okay for you? Not sure why those specific lines were added in the first place, it seems wrong.

They were there to mirror the existing code I was replacing with the hash maps. I probably got carried away unnecessarily and, as you say, created a bug as a result.

@mtardy mtardy merged commit 68967fa into main Feb 24, 2025
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-backport/1.2 This PR needs backporting to 1.2 needs-backport/1.3 This PR needs backporting to 1.3 release-note/bug This PR fixes an issue in a previous release of Tetragon.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants