Fix socket permission

Closes #6773

PiperOrigin-RevId: 408984647
This commit is contained in:
Fabricio Voznika
2021-11-10 15:00:50 -08:00
committed by gVisor bot
parent bb1ae811f4
commit ffc3a0d840
2 changed files with 11 additions and 1 deletions
+1 -1
View File
@@ -117,7 +117,7 @@ func NewDentry(ctx context.Context, mnt *vfs.Mount) *vfs.Dentry {
fs := mnt.Filesystem().Impl().(*filesystem)
// File mode matches net/socket.c:sock_alloc.
filemode := linux.FileMode(linux.S_IFSOCK | 0600)
filemode := linux.FileMode(linux.S_IFSOCK | 0777)
i := &inode{}
i.InodeAttrs.Init(ctx, auth.CredentialsFromContext(ctx), linux.UNNAMED_MAJOR, fs.devMinor, fs.Filesystem.NextIno(), filemode)
+10
View File
@@ -183,6 +183,16 @@ TEST(SocketTest, UnixSCMRightsOnlyPassedOnce) {
ASSERT_TRUE(WIFEXITED(status) && WEXITSTATUS(status) == 0);
}
TEST(SocketTest, Permission) {
SKIP_IF(IsRunningWithVFS1());
FileDescriptor socket =
ASSERT_NO_ERRNO_AND_VALUE(Socket(AF_UNIX, SOCK_DGRAM, 0));
auto stat = ASSERT_NO_ERRNO_AND_VALUE(Fstat(socket.get()));
EXPECT_EQ(0777, stat.st_mode & ~S_IFMT);
}
using SocketOpenTest = ::testing::TestWithParam<int>;
// UDS cannot be opened.