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

[v1.3] bpf: fix path truncation in cwd and copying path arguments #3434

Merged
merged 6 commits into from
Feb 27, 2025

Conversation

mtardy
Copy link
Member

@mtardy mtardy commented Feb 24, 2025

Backport of #3427

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 24, 2025
@mtardy mtardy force-pushed the pr/mtardy/v1.3-truncate-fix branch from 789ecae to 52f41f2 Compare February 27, 2025 08:55
@mtardy mtardy marked this pull request as ready for review February 27, 2025 10:38
@mtardy mtardy requested a review from a team as a code owner February 27, 2025 10:38
@mtardy mtardy requested review from tixxdz and removed request for a team February 27, 2025 10:38
@olsajiri
Copy link
Contributor

heya,
should you include something like below to each commit?
[upstream commit xxx]

@mtardy
Copy link
Member Author

mtardy commented Feb 27, 2025

heya, should you include something like below to each commit? [upstream commit xxx]

oups thanks I forgot and in v1.2 as well, let me do that!

[ upstream commit fd10bed ]

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]>
[ upstream commit c688c15 ]

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]>
[ upstream commit 2f074f7 ]

The asm was maybe no longer necessary and was restricting the maximum
size to be 1188.

Signed-off-by: Mahe Tardy <[email protected]>
[ upstream commit 9e6737c ]

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]>
[ upstream commit 9330292 ]

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]>
[ upstream commit 68967fa ]

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/v1.3-truncate-fix branch from 52f41f2 to 8dff40a Compare February 27, 2025 13:58
@mtardy mtardy merged commit aa04216 into v1.3 Feb 27, 2025
40 checks passed
@mtardy mtardy deleted the pr/mtardy/v1.3-truncate-fix branch February 27, 2025 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

3 participants