Skip to content

Commit 1dffeba

Browse files
committed
fix: mount throws EPERM on virtiofs with SELinux
Fixes #13245 Signed-off-by: Mateusz Urbanek <mateusz.urbanek@siderolabs.com>
1 parent 48a481c commit 1dffeba

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

internal/pkg/mount/v3/point.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ func (p *Point) Mount(opts Options) error {
9494
// FilterSelinuxLabelErrors filters out certain errors when setting the SELinux label on the mount point.
9595
// - ENOTSUP is ignored for all filesystems, as it indicates that the filesystem does not support extended attributes.
9696
// - EROFS is ignored for virtiofs, as it indicates that the underlying filesystem is read-only and does not support setting labels.
97+
// - EPERM is ignored for virtiofs, as setting security.selinux xattrs may be blocked by the host or virtiofsd
98+
// even though the mount is otherwise functional.
9799
func FilterSelinuxLabelErrors(target, fstype string, err error) error {
98100
if err == nil {
99101
return nil
@@ -103,8 +105,14 @@ func FilterSelinuxLabelErrors(target, fstype string, err error) error {
103105
return nil
104106
}
105107

106-
if fstype == "virtiofs" && errors.Is(err, unix.EROFS) {
107-
return nil
108+
if fstype == "virtiofs" {
109+
switch {
110+
case errors.Is(err, unix.EROFS):
111+
return nil
112+
case errors.Is(err, unix.EPERM):
113+
return nil
114+
default:
115+
}
108116
}
109117

110118
return fmt.Errorf("error setting selinux label on %q: %w", target, err)

pkg/provision/providers/vm/virtiofsd.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ func (p *Provisioner) FindVirtiofsd() (string, error) {
2727
return p.findVirtiofsd()
2828
}
2929

30+
// The first rule combines what could be separate client and server rules into
31+
// a single all rule, matching 'security.' in either client arguments or lists
32+
// returned from the host. This prevents the client from seeing and/or setting
33+
// any 'security.' attributes on the server.
34+
//
35+
// More info: https://gitlab.com/virtio-fs/virtiofsd/-/blob/main/doc/xattr-mapping.md
36+
const xattrmap = `/bad/all/security./security.//ok/all///`
37+
3038
// Virtiofsd starts virtiofsd and restarts it if it exits.
3139
// The restart is needed, because the virtiofsd exits when client disconnects.
3240
func Virtiofsd(ctx context.Context, virtiofsdBin, share, socket string) error {
@@ -43,6 +51,8 @@ func Virtiofsd(ctx context.Context, virtiofsdBin, share, socket string) error {
4351
"--socket-path", socket,
4452
"--announce-submounts",
4553
"--inode-file-handles=mandatory",
54+
"--xattr",
55+
"--xattrmap=" + xattrmap,
4656
}
4757

4858
fmt.Printf("Starting virtiofsd with restart loop: %s %s\n",

0 commit comments

Comments
 (0)