Skip to content

Replace KILLPRIV with KILLPRIV_V2#532

Merged
slp merged 7 commits intocontainers:mainfrom
slp:virtiofs-killpriv-v2
Feb 17, 2026
Merged

Replace KILLPRIV with KILLPRIV_V2#532
slp merged 7 commits intocontainers:mainfrom
slp:virtiofs-killpriv-v2

Conversation

@slp
Copy link
Collaborator

@slp slp commented Feb 6, 2026

While we were announcing it, we never really supported KILLPRIV, so this was breaking some fs tests. This PR stops announcing KILLPRIV support, and implements support for KILLPRIV_V2.

@slp
Copy link
Collaborator Author

slp commented Feb 6, 2026

Tested with pjdfstest on both Linux and macOS.

slp added 2 commits February 17, 2026 13:35
We never really supported HANDLE_KILLPRIV, so let's be honest about it
and stop announcing it.

Signed-off-by: Sergio Lopez <slp@redhat.com>
We're going to need this library in the next commit libcap-ng-dev.

Signed-off-by: Sergio Lopez <slp@redhat.com>
@slp slp force-pushed the virtiofs-killpriv-v2 branch from 1c23c77 to b01a30c Compare February 17, 2026 12:35
@slp slp requested a review from dorindabassey as a code owner February 17, 2026 12:35
slp added 4 commits February 17, 2026 17:21
KILLPRIV_V2 is a FUSE flag that indicates that the filesystem is
responsible for clearing security.capability xattr and clearing setuid
and setgid bits, following these rules:

- clear "security.capability" on write, truncate and chown unconditionally
- clear suid/sgid if following is true. Note, sgid is cleared only if
  group executable bit is set.
    o setattr has FATTR_SIZE and FATTR_KILL_SUIDGID set.
    o setattr has FATTR_UID or FATTR_GID
    o open has O_TRUNC and FUSE_OPEN_KILL_SUIDGID
    o create has O_TRUNC and FUSE_OPEN_KILL_SUIDGID flag set.

Signed-off-by: Sergio Lopez <slp@redhat.com>
Those structs were mostly redundant, converge on InodeHandle. This also
allows us to simplify and unify many code paths.

Signed-off-by: Sergio Lopez <slp@redhat.com>
Reuse the previously obtained libc::stat with get_xattr_* to avoid an
additional stat syscall.

Signed-off-by: Sergio Lopez <slp@redhat.com>
Enable set_xattr_stat to receive a bindings::stat struct so we it can
be provided in the cases where we've already obtained it, saving an
additional stat syscall.

Signed-off-by: Sergio Lopez <slp@redhat.com>
@slp slp force-pushed the virtiofs-killpriv-v2 branch 2 times, most recently from 0d3a1cb to 2d7b4b2 Compare February 17, 2026 16:32
The methods [set|get]_attr_stat are used to store and read the guest
ownership and permission values as extended attributes on APFS. So far,
they were treated in an all-or-nothing fashion: you either have both
ownership and permission data, or nothing. Also, when those values were
missing, we defaulted to a very conservative root ownership.

There are situations in which we may only have partial information
(only ownership or only permission). For instance, this happens on files
created from the host when the guest attempts to change ownership or
the permission bits.

In this change, we extend the format to of the attribute we store on
APFS to allow having missing fields (signalled with an "x" instead of
a u32). Also, when a field is missing, we use the host's ownership and
permission bits instead of defaulting to root.

This change is backwards compatible, as older versions of libkrun
generate the same format strings for the extended attribute, but
without missing fields.

Signed-off-by: Sergio Lopez <slp@redhat.com>
@slp slp force-pushed the virtiofs-killpriv-v2 branch from 2d7b4b2 to 0c1ddbd Compare February 17, 2026 16:43
Copy link
Collaborator

@mtjhrc mtjhrc left a comment

Choose a reason for hiding this comment

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

Code LGTM, I am not very familiar with the all the semantics at play here, but I didn't find anything obviously wrong. Thanks!

@slp slp merged commit 09cebab into containers:main Feb 17, 2026
12 of 13 checks passed
@slp slp deleted the virtiofs-killpriv-v2 branch February 17, 2026 16:52
fd,
XATTR_KEY.as_ptr() as *const i8,
buf.as_mut_ptr() as *mut libc::c_void,
64,
Copy link
Contributor

Choose a reason for hiding this comment

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

Buffer size passed here is 64, but the actual Vec is only 32 bytes if I read this correctly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I missed this was already merged

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@pftbest Good catch! We should change those hard coded numbers with a constant = 64. Since you found it, do you want to create a PR fixing it or should I do it myself?

Copy link
Contributor

Choose a reason for hiding this comment

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

@slp Please go ahead, I won't have time to fix this today.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ack, thanks anyways!

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.

4 participants