diff --git a/Kernel/Devices/Device.h b/Kernel/Devices/Device.h index 371e6ac0413..43fffb39ff6 100644 --- a/Kernel/Devices/Device.h +++ b/Kernel/Devices/Device.h @@ -45,9 +45,6 @@ public: virtual ErrorOr> pseudo_path(OpenFileDescription const&) const override; virtual ErrorOr> open(int options) override; - UserID uid() const { return m_uid; } - GroupID gid() const { return m_gid; } - virtual bool is_device() const override { return true; } virtual void will_be_destroyed() override; virtual ErrorOr after_inserting(); @@ -68,8 +65,6 @@ public: protected: Device(MajorNumber major, MinorNumber minor); - void set_uid(UserID uid) { m_uid = uid; } - void set_gid(GroupID gid) { m_gid = gid; } void after_inserting_add_to_device_management(); void before_will_be_destroyed_remove_from_device_management(); @@ -85,8 +80,6 @@ protected: private: MajorNumber const m_major { 0 }; MinorNumber const m_minor { 0 }; - UserID m_uid { 0 }; - GroupID m_gid { 0 }; State m_state { State::Normal }; diff --git a/Kernel/FileSystem/DevPtsFS/FileSystem.cpp b/Kernel/FileSystem/DevPtsFS/FileSystem.cpp index b33f969500f..e6a5cd6382e 100644 --- a/Kernel/FileSystem/DevPtsFS/FileSystem.cpp +++ b/Kernel/FileSystem/DevPtsFS/FileSystem.cpp @@ -53,11 +53,12 @@ ErrorOr> DevPtsFS::get_inode(InodeIdentifier inode_id) cons auto* device = DeviceManagement::the().get_device(201, pty_index); VERIFY(device); - auto inode = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) DevPtsFSInode(const_cast(*this), inode_id.index(), static_cast(device)))); + auto* pts_device = static_cast(device); + auto inode = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) DevPtsFSInode(const_cast(*this), inode_id.index(), pts_device))); inode->m_metadata.inode = inode_id; inode->m_metadata.size = 0; - inode->m_metadata.uid = device->uid(); - inode->m_metadata.gid = device->gid(); + inode->m_metadata.uid = pts_device->uid(); + inode->m_metadata.gid = pts_device->gid(); inode->m_metadata.mode = 0020600; inode->m_metadata.major_device = device->major(); inode->m_metadata.minor_device = device->minor(); diff --git a/Kernel/TTY/MasterPTY.cpp b/Kernel/TTY/MasterPTY.cpp index 6385f0f40a8..b900e8b6764 100644 --- a/Kernel/TTY/MasterPTY.cpp +++ b/Kernel/TTY/MasterPTY.cpp @@ -20,7 +20,8 @@ ErrorOr> MasterPTY::try_create(unsigned int index) { auto buffer = TRY(DoubleBuffer::try_create("MasterPTY: Buffer"sv)); auto master_pty = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) MasterPTY(index, move(buffer)))); - auto slave_pty = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) SlavePTY(*master_pty, index))); + auto credentials = Process::current().credentials(); + auto slave_pty = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) SlavePTY(*master_pty, credentials->uid(), credentials->gid(), index))); master_pty->m_slave = slave_pty; TRY(master_pty->after_inserting()); TRY(slave_pty->after_inserting()); @@ -32,11 +33,6 @@ MasterPTY::MasterPTY(unsigned index, NonnullOwnPtr buffer) , m_index(index) , m_buffer(move(buffer)) { - auto& process = Process::current(); - auto credentials = process.credentials(); - set_uid(credentials->uid()); - set_gid(credentials->gid()); - m_buffer->set_unblock_callback([this]() { if (m_slave) evaluate_block_conditions(); diff --git a/Kernel/TTY/SlavePTY.cpp b/Kernel/TTY/SlavePTY.cpp index 55c3108217a..c185c0571cb 100644 --- a/Kernel/TTY/SlavePTY.cpp +++ b/Kernel/TTY/SlavePTY.cpp @@ -35,17 +35,14 @@ bool SlavePTY::unref() const return did_hit_zero; } -SlavePTY::SlavePTY(NonnullRefPtr master, unsigned index) +SlavePTY::SlavePTY(NonnullRefPtr master, UserID uid, GroupID gid, unsigned index) : TTY(201, index) , m_master(move(master)) , m_index(index) + , m_uid(uid) + , m_gid(gid) { - auto& process = Process::current(); - auto credentials = process.credentials(); - set_uid(credentials->uid()); - set_gid(credentials->gid()); set_size(80, 25); - SlavePTY::all_instances().with([&](auto& list) { list.append(*this); }); } diff --git a/Kernel/TTY/SlavePTY.h b/Kernel/TTY/SlavePTY.h index 548a0d893f1..7a7e0e6a33c 100644 --- a/Kernel/TTY/SlavePTY.h +++ b/Kernel/TTY/SlavePTY.h @@ -25,6 +25,9 @@ public: virtual FileBlockerSet& blocker_set() override; + UserID uid() const { return m_uid; } + GroupID gid() const { return m_gid; } + private: // ^Device virtual bool is_openable_by_jailed_processes() const override { return true; } @@ -42,12 +45,15 @@ private: virtual ErrorOr close() override; friend class MasterPTY; - SlavePTY(NonnullRefPtr, unsigned index); + SlavePTY(NonnullRefPtr, UserID, GroupID, unsigned index); NonnullRefPtr const m_master; UnixDateTime m_time_of_last_write {}; unsigned m_index { 0 }; + UserID const m_uid { 0 }; + GroupID const m_gid { 0 }; + mutable IntrusiveListNode m_list_node; public: