Skip to content

chown-overlay fix ID-space mismatch in set and apply guards#200

Merged
jserv merged 1 commit into
sysprog21:mainfrom
open-sources-port:fix-chown-overlay-id-space
Jul 14, 2026
Merged

chown-overlay fix ID-space mismatch in set and apply guards#200
jserv merged 1 commit into
sysprog21:mainfrom
open-sources-port:fix-chown-overlay-id-space

Conversation

@doanbaotrung

@doanbaotrung doanbaotrung commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

chown-overlay: fix ID-space mismatch in set/apply guards
chown_overlay_set receives cur_uid/cur_gid from chown_result where
they were taken directly from host_st->st_uid/st_gid (the raw macOS
stat values). new_owner/new_group are guest-virtual UIDs/GIDs.
These two live in different ID namespaces, so comparing them:

next_uid = new_owner == -1 ? cur_uid : new_owner;
if (next_uid == cur_uid && next_gid == cur_gid) goto out;

produces wrong answers whenever host UID != GUEST_UID (e.g. host
user has UID 501, guest runs as GUEST_UID 1000), or whenever the
file already has an overlay entry that virtualises its owner to a
different value.

Two complementary fixes:

fs.c - chown_result:
Apply the existing overlay to a temporary stat copy before
extracting cur_uid/cur_gid. This makes the values passed to
chown_overlay_set reflect what the guest currently sees for the
file rather than the physical host owner.

chown-overlay.c - chown_overlay_set / chown_overlay_apply:
Initialise new overlay entries with the sentinel (uint32_t)-1
("no override for this field") instead of cur_uid/cur_gid.
Resolve sentinels to cur before the stale-entry removal check
so both sides of the comparison use guest-virtual IDs.
Skip sentinel fields in chown_overlay_apply so a partial chown
does not corrupt the untouched field with a stale value.

fix #136


Summary by cubic

Fixes ID-space mismatches in the chown overlay by evaluating guards in the guest-visible UID/GID space to avoid false no-ops and stale entries. Corrects ownership updates on macOS and with virtualized owners; fixes #136.

  • Bug Fixes
    • fs.c: Apply the existing overlay to a temp stat to get guest-visible uid/gid before calling chown_overlay_set; return ENOMEM if overlay allocation fails to avoid reporting a state the guest can’t observe.
    • chown-overlay.c: Initialize new entries with sentinel (uint32_t)-1, resolve sentinels before no-op/stale-removal checks, and skip sentinel fields in apply so partial chown doesn’t overwrite untouched values.

Written for commit a124c8d. Summary will update on new commits.

Review in cubic

@doanbaotrung doanbaotrung force-pushed the fix-chown-overlay-id-space branch from 765032f to 94d8558 Compare July 13, 2026 09:11
@doanbaotrung doanbaotrung changed the title chown-overlay: fix ID-space mismatch in set/apply guards chown-overlay fix ID-space mismatch in set and apply guards Jul 13, 2026

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/syscall/chown-overlay.c
@doanbaotrung doanbaotrung force-pushed the fix-chown-overlay-id-space branch from 94d8558 to 04a4d54 Compare July 13, 2026 09:35

@jserv jserv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rebase latest main and resolve conflicts.

chown_overlay_set receives cur_uid/cur_gid from chown_result where
they were taken directly from host_st->st_uid/st_gid (the raw macOS
stat values).  new_owner/new_group are guest-virtual UIDs/GIDs.
These two live in different ID namespaces, so comparing them:

  next_uid = new_owner == -1 ? cur_uid : new_owner;
  if (next_uid == cur_uid && next_gid == cur_gid) goto out;

produces wrong answers whenever host UID != GUEST_UID (e.g. host
user has UID 501, guest runs as GUEST_UID 1000), or whenever the
file already has an overlay entry that virtualises its owner to a
different value.

Two complementary fixes:

fs.c - chown_result:
  Apply the existing overlay to a temporary stat copy before
  extracting cur_uid/cur_gid.  This makes the values passed to
  chown_overlay_set reflect what the guest currently sees for the
  file rather than the physical host owner.

chown-overlay.c - chown_overlay_set / chown_overlay_apply:
  Initialise new overlay entries with the sentinel (uint32_t)-1
  ("no override for this field") instead of cur_uid/cur_gid.
  Resolve sentinels to cur before the stale-entry removal check
  so both sides of the comparison use guest-virtual IDs.
  Skip sentinel fields in chown_overlay_apply so a partial chown
  does not corrupt the untouched field with a stale value.

fix sysprog21#136
@doanbaotrung doanbaotrung force-pushed the fix-chown-overlay-id-space branch from 04a4d54 to a124c8d Compare July 14, 2026 11:09
@doanbaotrung

Copy link
Copy Markdown
Collaborator Author

Rebased and fix conflicted

@jserv jserv merged commit 4ebc610 into sysprog21:main Jul 14, 2026
9 checks passed
@doanbaotrung doanbaotrung deleted the fix-chown-overlay-id-space branch July 14, 2026 13:47
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.

Guest User Cannot Own Files when Host UID Equals Guest UID (GUEST_UID = 1000)

3 participants