Kernel: Don't preserve set-uid bit in open() and bind() modes

For some reason we were keeping the bits 04777 in file modes. That
doesn't seem right and I can't think of a reason why the set-uid bit
should be allowed to slip through.
This commit is contained in:
Andreas Kling 2021-01-23 15:35:20 +01:00
parent f2ea6c3d4c
commit c32176db27
2 changed files with 3 additions and 3 deletions

View file

@ -114,7 +114,7 @@ KResult LocalSocket::bind(Userspace<const sockaddr*> user_address, socklen_t add
dbgln<debug_local_socket>("LocalSocket({}) bind({})", this, path);
mode_t mode = S_IFSOCK | (m_prebind_mode & 04777);
mode_t mode = S_IFSOCK | (m_prebind_mode & 0777);
UidAndGid owner { m_prebind_uid, m_prebind_gid };
auto result = VFS::the().open(path, O_CREAT | O_EXCL | O_NOFOLLOW_NOERROR, mode, Process::current()->current_directory(), owner);
if (result.is_error()) {
@ -411,7 +411,7 @@ KResult LocalSocket::chmod(FileDescription&, mode_t mode)
if (m_file)
return m_file->chmod(mode);
m_prebind_mode = mode & 04777;
m_prebind_mode = mode & 0777;
return KSuccess;
}

View file

@ -57,7 +57,7 @@ int Process::sys$open(Userspace<const Syscall::SC_open_params*> user_params)
REQUIRE_PROMISE(cpath);
// Ignore everything except permission bits.
mode &= 04777;
mode &= 0777;
auto path = get_syscall_path_argument(params.path);
if (path.is_error())