diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-02-22 02:39:13 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-02-22 02:39:13 +0100 |
commit | f98dcbf1d652958cf4aa323d556bed5906206cac (patch) | |
tree | e7d7481c148bfdc111e73b65dd7f8514fc55ca07 | |
parent | 6d3e12899b8b0a3ddc6062fc43b18cba0c788920 (diff) | |
download | serenity-f98dcbf1d652958cf4aa323d556bed5906206cac.zip |
Kernel: Respect the process umask in open() and mkdir().
-rw-r--r-- | Kernel/Process.cpp | 12 | ||||
-rw-r--r-- | Kernel/Process.h | 2 |
2 files changed, 11 insertions, 3 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index b2ab82d6e3..66b393fc2b 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -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; } + 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. m_tss.ss2 = m_pid; 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) return -EMFILE; 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) return error; if (options & O_DIRECTORY && !descriptor->is_directory()) @@ -1487,7 +1493,7 @@ pid_t Process::sys$getppid() mode_t Process::sys$umask(mode_t mask) { auto old_mask = m_umask; - m_umask = mask; + m_umask = mask & 0777; return old_mask; } @@ -1927,7 +1933,7 @@ int Process::sys$mkdir(const char* pathname, mode_t mode) if (pathname_length >= 255) return -ENAMETOOLONG; 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 0; } diff --git a/Kernel/Process.h b/Kernel/Process.h index c6d2bbb03f..e63e0929f6 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -120,6 +120,8 @@ public: gid_t egid() const { return m_egid; } pid_t ppid() const { return m_ppid; } + mode_t umask() const { return m_umask; } + const FarPtr& far_ptr() const { return m_far_ptr; } FileDescriptor* file_descriptor(int fd); |