Skip to content

Conversation

tianyuzhou95
Copy link
Contributor

Currently, on certain error paths during task creation (e.g., when "runsc exec" fails), we do not properly handle the refcount of the mount namespace, leading to a refcount leak. This patch adds cleanup that would be released before the reference ownership is transferred to callee, ensuring that the refcount is correctly decremented.

Fixes #12054

@tianyuzhou95 tianyuzhou95 changed the title pkg/sentry: add cleanup to avoid mntns refcount leak [WIP] pkg/sentry: add cleanup to avoid mntns refcount leak Aug 17, 2025
@tianyuzhou95 tianyuzhou95 marked this pull request as draft August 17, 2025 03:50
@tianyuzhou95 tianyuzhou95 changed the title [WIP] pkg/sentry: add cleanup to avoid mntns refcount leak pkg/sentry: add cleanup to avoid mntns refcount leak Aug 17, 2025
@tianyuzhou95 tianyuzhou95 marked this pull request as ready for review August 17, 2025 04:57
@milantracy
Copy link
Contributor

thanks!

Copy link
Collaborator

@ayushr2 ayushr2 left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

@tianyuzhou95
Copy link
Contributor Author

Please hold off on this PR — it appears that even with this patch, the filesystem leaks for gofer, overlay, and tmpfs can still be triggered using the method described in the issue. I'm currently investigating the root cause and will include the fix in this PR.

@tianyuzhou95 tianyuzhou95 changed the title pkg/sentry: add cleanup to avoid mntns refcount leak pkg/sentry: add cleanup to avoid mntns/FSContext refcount leak Aug 19, 2025
@tianyuzhou95
Copy link
Contributor Author

tianyuzhou95 commented Aug 19, 2025

Please hold off on this PR — it appears that even with this patch, the filesystem leaks for gofer, overlay, and tmpfs can still be triggered using the method described in the issue. I'm currently investigating the root cause and will include the fix in this PR.

The root cause has been identified: the FSContext leak(created here, and would leak if returns before NewTask() called) caused the filesystem not to be released when the container was destroyed. The corresponding fix has been included in this patch.

cc @ayushr2

Copy link
Collaborator

@ayushr2 ayushr2 left a comment

Choose a reason for hiding this comment

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

LGTM

Currently, on certain error paths during task creation (e.g., when
"runsc exec" fails), we do not properly handle the refcount of the
mntns/FSContext, leading to a refcount leak. This patch adds cleanup
that would be released before the reference ownership is transferred
to callee, ensuring that the refcount is correctly decremented.

Fixes google#12054

Signed-off-by: Tianyu Zhou <albert.zty@antgroup.com>
copybara-service bot pushed a commit that referenced this pull request Aug 20, 2025
Currently, on certain error paths during task creation (e.g., when "runsc exec" fails), we do not properly handle the refcount of the mount namespace, leading to a refcount leak. This patch adds cleanup that would be released before the reference ownership is transferred to callee, ensuring that the refcount is correctly decremented.

Fixes #12054

FUTURE_COPYBARA_INTEGRATE_REVIEW=#12055 from tianyuzhou95:albert/refcount 512b9a4
PiperOrigin-RevId: 797155567
copybara-service bot pushed a commit that referenced this pull request Aug 20, 2025
Currently, on certain error paths during task creation (e.g., when "runsc exec" fails), we do not properly handle the refcount of the mount namespace, leading to a refcount leak. This patch adds cleanup that would be released before the reference ownership is transferred to callee, ensuring that the refcount is correctly decremented.

Fixes #12054

FUTURE_COPYBARA_INTEGRATE_REVIEW=#12055 from tianyuzhou95:albert/refcount 512b9a4
PiperOrigin-RevId: 797155567
copybara-service bot pushed a commit that referenced this pull request Aug 20, 2025
Currently, on certain error paths during task creation (e.g., when "runsc exec" fails), we do not properly handle the refcount of the mount namespace, leading to a refcount leak. This patch adds cleanup that would be released before the reference ownership is transferred to callee, ensuring that the refcount is correctly decremented.

Fixes #12054

FUTURE_COPYBARA_INTEGRATE_REVIEW=#12055 from tianyuzhou95:albert/refcount 512b9a4
PiperOrigin-RevId: 797155567
copybara-service bot pushed a commit that referenced this pull request Aug 20, 2025
Currently, on certain error paths during task creation (e.g., when "runsc exec" fails), we do not properly handle the refcount of the mount namespace, leading to a refcount leak. This patch adds cleanup that would be released before the reference ownership is transferred to callee, ensuring that the refcount is correctly decremented.

Fixes #12054

FUTURE_COPYBARA_INTEGRATE_REVIEW=#12055 from tianyuzhou95:albert/refcount 512b9a4
PiperOrigin-RevId: 797155567
copybara-service bot pushed a commit that referenced this pull request Aug 28, 2025
Currently, on certain error paths during task creation (e.g., when "runsc exec" fails), we do not properly handle the refcount of the mount namespace, leading to a refcount leak. This patch adds cleanup that would be released before the reference ownership is transferred to callee, ensuring that the refcount is correctly decremented.

Fixes #12054

FUTURE_COPYBARA_INTEGRATE_REVIEW=#12055 from tianyuzhou95:albert/refcount 512b9a4
PiperOrigin-RevId: 800615196
copybara-service bot pushed a commit that referenced this pull request Aug 28, 2025
Currently, on certain error paths during task creation (e.g., when "runsc exec" fails), we do not properly handle the refcount of the mount namespace, leading to a refcount leak. This patch adds cleanup that would be released before the reference ownership is transferred to callee, ensuring that the refcount is correctly decremented.

Fixes #12054

FUTURE_COPYBARA_INTEGRATE_REVIEW=#12055 from tianyuzhou95:albert/refcount 512b9a4
PiperOrigin-RevId: 800615196
copybara-service bot pushed a commit that referenced this pull request Aug 28, 2025
Currently, on certain error paths during task creation (e.g., when "runsc exec" fails), we do not properly handle the refcount of the mount namespace, leading to a refcount leak. This patch adds cleanup that would be released before the reference ownership is transferred to callee, ensuring that the refcount is correctly decremented.

Fixes #12054

FUTURE_COPYBARA_INTEGRATE_REVIEW=#12055 from tianyuzhou95:albert/refcount 512b9a4
PiperOrigin-RevId: 800615196
copybara-service bot pushed a commit that referenced this pull request Aug 28, 2025
Currently, on certain error paths during task creation (e.g., when "runsc exec" fails), we do not properly handle the refcount of the mount namespace, leading to a refcount leak. This patch adds cleanup that would be released before the reference ownership is transferred to callee, ensuring that the refcount is correctly decremented.

Fixes #12054

FUTURE_COPYBARA_INTEGRATE_REVIEW=#12055 from tianyuzhou95:albert/refcount 512b9a4
PiperOrigin-RevId: 800615196
@copybara-service copybara-service bot merged commit c91c52f into google:master Aug 29, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Container's MountNamespace refcount leak
3 participants