Skip to content

Resolve writable shadow_fd destination in sendfile#65

Open
ChuWeiChang wants to merge 1 commit intosysprog21:mainfrom
ChuWeiChang:Fix-incorrect-shadow-fd-destination-in-forward_sendfile
Open

Resolve writable shadow_fd destination in sendfile#65
ChuWeiChang wants to merge 1 commit intosysprog21:mainfrom
ChuWeiChang:Fix-incorrect-shadow-fd-destination-in-forward_sendfile

Conversation

@ChuWeiChang
Copy link
Copy Markdown
Contributor

@ChuWeiChang ChuWeiChang commented Apr 24, 2026

Fixes #64 and also help with test gap 5 in #38

Overview

There is a routing bug in forward_sendfile in seccomp_dispatch.c where destination shadow FDs were bypassing the virtual kernel (shadow_sp) and writing directly to the underlying physical host_fd.

What this PR does

  1. Adds an explicit fd_table_entry lookup for the destination out_fd prior to the emulation loop.
  2. Adds an integration test in test/guest/sendfile-test.c

Summary by cubic

Fixes sendfile routing when the destination fd has a writeback shadow. Writes now go to the shadow_sp instead of the host fd, ensuring correct sync and data visibility.

  • Bug Fixes
    • Look up the destination out_fd via the fd table and, when shadow_writeback is set, write to shadow_sp inside forward_sendfile.
    • Add sendfile-test to verify data is written through the shadow path and enable it in run-tests.sh.

Written for commit 00006c0. Summary will update on new commits.

When intercepting sendfile with out_fd as shadow_fd, forward_sendfile
mistakenly treat it as host_fd instead of shadow_sp.

Fix this by explicitly querying the out_fd's FD table entry. If
shadow_writeback is enabled, extract and write to shadow_sp instead.

Change-Id: Ifbe431c557f8d10cb2f4ab221176da336e35e067
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 3 files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

forward_sendfile bypasses shadow_sp for writable shadow destination FDs

1 participant