From d87d053dd89347e0114da1ff5d6b6b594393387e Mon Sep 17 00:00:00 2001 From: zhijian Date: Thu, 28 Nov 2024 18:15:51 +0800 Subject: [PATCH] vfs/setxattr: ignore all unsupported xattr flags on the MacOS platform (#5329) --- pkg/meta/utils_darwin.go | 1 - pkg/meta/utils_linux.go | 1 - pkg/meta/utils_windows.go | 1 - pkg/vfs/vfs.go | 8 +++++--- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/meta/utils_darwin.go b/pkg/meta/utils_darwin.go index fea6806da62c..30b1ccb89fd4 100644 --- a/pkg/meta/utils_darwin.go +++ b/pkg/meta/utils_darwin.go @@ -17,5 +17,4 @@ const ( XattrCreateOrReplace = 0 XattrCreate = sys.XATTR_CREATE XattrReplace = sys.XATTR_REPLACE - XattrNoSecurity = sys.XATTR_NOSECURITY ) diff --git a/pkg/meta/utils_linux.go b/pkg/meta/utils_linux.go index bc4ca9d460b8..39d26708c246 100644 --- a/pkg/meta/utils_linux.go +++ b/pkg/meta/utils_linux.go @@ -17,5 +17,4 @@ const ( XattrCreateOrReplace = 0 XattrCreate = sys.XATTR_CREATE XattrReplace = sys.XATTR_REPLACE - XattrNoSecurity = 8 ) diff --git a/pkg/meta/utils_windows.go b/pkg/meta/utils_windows.go index be0fade5711a..5157b99e33d8 100644 --- a/pkg/meta/utils_windows.go +++ b/pkg/meta/utils_windows.go @@ -30,5 +30,4 @@ const ( XattrCreateOrReplace = 0 XattrCreate = 1 XattrReplace = 2 - XattrNoSecurity = 8 ) diff --git a/pkg/vfs/vfs.go b/pkg/vfs/vfs.go index 222a89f33152..6f741c67c470 100644 --- a/pkg/vfs/vfs.go +++ b/pkg/vfs/vfs.go @@ -1021,6 +1021,8 @@ const ( xattrMaxSize = 65536 ) +var macSupportFlags = meta.XattrCreateOrReplace | meta.XattrCreate | meta.XattrReplace + func (v *VFS) SetXattr(ctx Context, ino Ino, name string, value []byte, flags uint32) (err syscall.Errno) { defer func() { logit(ctx, "setxattr", err, "(%d,%s,%d,%d)", ino, name, len(value), flags) }() if IsSpecialNode(ino) { @@ -1063,9 +1065,9 @@ func (v *VFS) SetXattr(ctx Context, ino Ino, name string, value []byte, flags ui err = v.Meta.SetFacl(ctx, ino, aclType, rule) v.invalidateAttr(ino) } else { - // ignore NoSecurity flag - if runtime.GOOS == "darwin" && (flags&meta.XattrNoSecurity) != 0 { - flags &= ^uint32(meta.XattrNoSecurity) + // only retain supported flags + if runtime.GOOS == "darwin" { + flags &= uint32(macSupportFlags) } err = v.Meta.SetXattr(ctx, ino, name, value, flags) }