Skip to content

Commit da4241c

Browse files
milantracygvisor-bot
authored andcommitted
Make setting security.capability attribute a no-op in tmpfs.
PiperOrigin-RevId: 742832245
1 parent 6b2bcc4 commit da4241c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

pkg/sentry/fsimpl/tmpfs/tmpfs.go

+5
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,11 @@ func (i *inode) setXattr(creds *auth.Credentials, opts *vfs.SetXattrOptions) err
870870
if err := i.checkXattrPrefix(opts.Name); err != nil {
871871
return err
872872
}
873+
if strings.HasPrefix(opts.Name, linux.XATTR_SECURITY_PREFIX) {
874+
// TODO(b/301323819): support security extended attributes in tmpfs.
875+
// Setting security.capacity extended attributes in tmpfs is a no-op.
876+
return nil
877+
}
873878
mode := linux.FileMode(i.mode.Load())
874879
kuid := auth.KUID(i.uid.Load())
875880
kgid := auth.KGID(i.gid.Load())

test/syscalls/linux/xattr.cc

+7-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,13 @@ TEST_F(XattrTest, SecurityCapacityXattr) {
111111
const char* path = test_file_name_.c_str();
112112
const char name[] = "security.capacity";
113113
const std::string val = "";
114-
EXPECT_THAT(lsetxattr(path, name, &val, val.size(), 0),
115-
SyscallFailsWithErrno(EOPNOTSUPP));
114+
if (ASSERT_NO_ERRNO_AND_VALUE(IsTmpfs(test_file_name_))) {
115+
EXPECT_THAT(lsetxattr(path, name, &val, val.size(), 0), SyscallSucceeds());
116+
} else {
117+
EXPECT_THAT(lsetxattr(path, name, &val, val.size(), 0),
118+
SyscallFailsWithErrno(EOPNOTSUPP));
119+
}
120+
116121
int buf = 0;
117122
EXPECT_THAT(lgetxattr(path, name, &buf, /*size=*/128),
118123
SyscallFailsWithErrno(AnyOf(ENODATA, EOPNOTSUPP)));

0 commit comments

Comments
 (0)