1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 19:37:35 +00:00

Kernel: Respect the process umask in open() and mkdir().

This commit is contained in:
Andreas Kling 2019-02-22 02:39:13 +01:00
parent 6d3e12899b
commit f98dcbf1d6
2 changed files with 11 additions and 3 deletions

View file

@ -688,6 +688,12 @@ Process::Process(String&& name, uid_t uid, gid_t gid, pid_t ppid, RingLevel ring
m_tss.esp0 = m_stack_top0; m_tss.esp0 = m_stack_top0;
} }
if (fork_parent) {
m_sid = fork_parent->m_sid;
m_pgid = fork_parent->m_pgid;
m_umask = fork_parent->m_umask;
}
// HACK: Ring2 SS in the TSS is the current PID. // HACK: Ring2 SS in the TSS is the current PID.
m_tss.ss2 = m_pid; m_tss.ss2 = m_pid;
m_far_ptr.offset = 0x98765432; m_far_ptr.offset = 0x98765432;
@ -1291,7 +1297,7 @@ int Process::sys$open(const char* path, int options, mode_t mode)
if (number_of_open_file_descriptors() >= m_max_open_file_descriptors) if (number_of_open_file_descriptors() >= m_max_open_file_descriptors)
return -EMFILE; return -EMFILE;
int error = -EWHYTHO; int error = -EWHYTHO;
auto descriptor = VFS::the().open(path, error, options, mode, cwd_inode()); auto descriptor = VFS::the().open(path, error, options, mode & ~umask(), cwd_inode());
if (!descriptor) if (!descriptor)
return error; return error;
if (options & O_DIRECTORY && !descriptor->is_directory()) if (options & O_DIRECTORY && !descriptor->is_directory())
@ -1487,7 +1493,7 @@ pid_t Process::sys$getppid()
mode_t Process::sys$umask(mode_t mask) mode_t Process::sys$umask(mode_t mask)
{ {
auto old_mask = m_umask; auto old_mask = m_umask;
m_umask = mask; m_umask = mask & 0777;
return old_mask; return old_mask;
} }
@ -1927,7 +1933,7 @@ int Process::sys$mkdir(const char* pathname, mode_t mode)
if (pathname_length >= 255) if (pathname_length >= 255)
return -ENAMETOOLONG; return -ENAMETOOLONG;
int error; int error;
if (!VFS::the().mkdir(String(pathname, pathname_length), mode, cwd_inode(), error)) if (!VFS::the().mkdir(String(pathname, pathname_length), mode & ~umask(), cwd_inode(), error))
return error; return error;
return 0; return 0;
} }

View file

@ -120,6 +120,8 @@ public:
gid_t egid() const { return m_egid; } gid_t egid() const { return m_egid; }
pid_t ppid() const { return m_ppid; } pid_t ppid() const { return m_ppid; }
mode_t umask() const { return m_umask; }
const FarPtr& far_ptr() const { return m_far_ptr; } const FarPtr& far_ptr() const { return m_far_ptr; }
FileDescriptor* file_descriptor(int fd); FileDescriptor* file_descriptor(int fd);