virtiofsd: Create new file using O_TMPFILE and set security context
authorVivek Goyal <vgoyal@redhat.com>
Tue, 8 Feb 2022 20:48:12 +0000 (15:48 -0500)
committerDr. David Alan Gilbert <dgilbert@redhat.com>
Thu, 17 Feb 2022 17:22:26 +0000 (17:22 +0000)
commita675c9a600389d210882fd1511edc2be65d53cdc
treee6b157316ae9f9a598d9909ec9388869249c9c34
parent0c3f81e13184ef0dc4b7c1a2afc15cb77fdad99b
virtiofsd: Create new file using O_TMPFILE and set security context

If guest and host policies can't work with each other, then guest security
context (selinux label) needs to be set into an xattr. Say remap guest
security.selinux xattr to trusted.virtiofs.security.selinux.

That means setting "fscreate" is not going to help as that's ony useful
for security.selinux xattr on host.

So we need another method which is atomic. Use O_TMPFILE to create new
file, set xattr and then linkat() to proper place.

But this works only for regular files. So dir, symlinks will continue
to be non-atomic.

Also if host filesystem does not support O_TMPFILE, we fallback to
non-atomic behavior.

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
Message-Id: <20220208204813.682906-10-vgoyal@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
tools/virtiofsd/passthrough_ll.c