1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:28:11 +00:00

Kernel/ProcFS: Allow a process directory to have a null Process pointer

In case we are about to delete the PID directory, we clear the Process
pointer. If someone still holds a reference to the PID directory (by
opening it), we still need to delete the process, but we can't delete
the directory, so we will keep it alive, but any operation on it will
fail by propogating the error to userspace about that the Process was
deleted and therefore there's no meaning to trying to do operations on
the directory.

Fixes #8576.
This commit is contained in:
Liav A 2021-07-10 00:24:47 +03:00 committed by Andreas Kling
parent d1028f8aed
commit bee75c1f24
4 changed files with 87 additions and 24 deletions

View file

@ -142,19 +142,21 @@ class ProcFSProcessDirectory final
public:
static NonnullRefPtr<ProcFSProcessDirectory> create(const Process&);
NonnullRefPtr<Process> associated_process() { return m_associated_process; }
RefPtr<Process> associated_process() { return m_associated_process; }
virtual uid_t owner_user() const override { return m_associated_process->uid(); }
virtual gid_t owner_group() const override { return m_associated_process->gid(); }
virtual uid_t owner_user() const override { return m_associated_process ? m_associated_process->uid() : 0; }
virtual gid_t owner_group() const override { return m_associated_process ? m_associated_process->gid() : 0; }
virtual KResult refresh_data(FileDescription&) const override;
virtual RefPtr<ProcFSExposedComponent> lookup(StringView name) override;
virtual void prepare_for_deletion() override;
private:
void on_attach();
IntrusiveListNode<ProcFSProcessDirectory, RefPtr<ProcFSProcessDirectory>> m_list_node;
explicit ProcFSProcessDirectory(const Process&);
NonnullRefPtr<Process> m_associated_process;
RefPtr<Process> m_associated_process;
};
class ProcFSBusDirectory : public ProcFSExposedDirectory {
@ -227,8 +229,26 @@ public:
virtual KResultOr<size_t> read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, FileDescription* description) const override;
virtual uid_t owner_user() const override { return m_parent_folder.strong_ref()->m_associated_process->uid(); }
virtual gid_t owner_group() const override { return m_parent_folder.strong_ref()->m_associated_process->gid(); }
virtual uid_t owner_user() const override
{
auto parent_folder = m_parent_folder.strong_ref();
if (!parent_folder)
return false;
auto process = parent_folder->associated_process();
if (!process)
return false;
return process->uid();
}
virtual gid_t owner_group() const override
{
auto parent_folder = m_parent_folder.strong_ref();
if (!parent_folder)
return false;
auto process = parent_folder->associated_process();
if (!process)
return false;
return process->gid();
}
protected:
ProcFSProcessInformation(StringView name, const ProcFSProcessDirectory& process_folder)