summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-09-19 16:39:52 +0200
committerAndreas Kling <kling@serenityos.org>2020-09-19 16:39:52 +0200
commit2cb32f83569579720c927fc43a8bc413755bd946 (patch)
treee2cc3b266e3925b1c8b8e5f96e8755f483a5daab /Kernel/FileSystem
parent55dd13ccac56144cbf437584fed9b2d21be1665f (diff)
downloadserenity-2cb32f83569579720c927fc43a8bc413755bd946.zip
Kernel: Let InodeWatcher track child inode numbers instead of names
First of all, this fixes a dumb info leak where we'd write kernel heap addresses (StringImpl*) into userspace memory when reading a watcher. Instead of trying to pass names to userspace, we now simply pass the child inode index. Nothing in userspace makes use of this yet anyway, so it's not like we're breaking anything. We'll see how this evolves.
Diffstat (limited to 'Kernel/FileSystem')
-rw-r--r--Kernel/FileSystem/Ext2FileSystem.cpp4
-rw-r--r--Kernel/FileSystem/Inode.cpp8
-rw-r--r--Kernel/FileSystem/Inode.h4
-rw-r--r--Kernel/FileSystem/InodeWatcher.cpp10
-rw-r--r--Kernel/FileSystem/InodeWatcher.h6
-rw-r--r--Kernel/FileSystem/TmpFS.cpp5
6 files changed, 19 insertions, 18 deletions
diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp
index f250e8cd4c..2f76b063a5 100644
--- a/Kernel/FileSystem/Ext2FileSystem.cpp
+++ b/Kernel/FileSystem/Ext2FileSystem.cpp
@@ -1027,7 +1027,7 @@ KResult Ext2FSInode::add_child(Inode& child, const StringView& name, mode_t mode
if (success)
m_lookup_cache.set(name, child.index());
- did_add_child(name);
+ did_add_child(child.identifier());
return KSuccess;
}
@@ -1072,7 +1072,7 @@ KResult Ext2FSInode::remove_child(const StringView& name)
if (result.is_error())
return result;
- did_remove_child(name);
+ did_remove_child(child_id);
return KSuccess;
}
diff --git a/Kernel/FileSystem/Inode.cpp b/Kernel/FileSystem/Inode.cpp
index b0e91bafc5..62e425dccb 100644
--- a/Kernel/FileSystem/Inode.cpp
+++ b/Kernel/FileSystem/Inode.cpp
@@ -229,19 +229,19 @@ void Inode::set_metadata_dirty(bool metadata_dirty)
}
}
-void Inode::did_add_child(const String& name)
+void Inode::did_add_child(const InodeIdentifier& child_id)
{
LOCKER(m_lock);
for (auto& watcher : m_watchers) {
- watcher->notify_child_added({}, name);
+ watcher->notify_child_added({}, child_id);
}
}
-void Inode::did_remove_child(const String& name)
+void Inode::did_remove_child(const InodeIdentifier& child_id)
{
LOCKER(m_lock);
for (auto& watcher : m_watchers) {
- watcher->notify_child_removed({}, name);
+ watcher->notify_child_removed({}, child_id);
}
}
diff --git a/Kernel/FileSystem/Inode.h b/Kernel/FileSystem/Inode.h
index d506ab0d18..62962bedf5 100644
--- a/Kernel/FileSystem/Inode.h
+++ b/Kernel/FileSystem/Inode.h
@@ -126,8 +126,8 @@ protected:
void inode_size_changed(size_t old_size, size_t new_size);
KResult prepare_to_write_data();
- void did_add_child(const String& name);
- void did_remove_child(const String& name);
+ void did_add_child(const InodeIdentifier&);
+ void did_remove_child(const InodeIdentifier&);
mutable Lock m_lock { "Inode" };
diff --git a/Kernel/FileSystem/InodeWatcher.cpp b/Kernel/FileSystem/InodeWatcher.cpp
index 50cb5db065..193095de4d 100644
--- a/Kernel/FileSystem/InodeWatcher.cpp
+++ b/Kernel/FileSystem/InodeWatcher.cpp
@@ -96,19 +96,19 @@ String InodeWatcher::absolute_path(const FileDescription&) const
void InodeWatcher::notify_inode_event(Badge<Inode>, Event::Type event_type)
{
LOCKER(m_lock);
- m_queue.enqueue({ event_type, {} });
+ m_queue.enqueue({ event_type });
}
-void InodeWatcher::notify_child_added(Badge<Inode>, const String& child_name)
+void InodeWatcher::notify_child_added(Badge<Inode>, const InodeIdentifier& child_id)
{
LOCKER(m_lock);
- m_queue.enqueue({ Event::Type::ChildAdded, child_name });
+ m_queue.enqueue({ Event::Type::ChildAdded, child_id.index() });
}
-void InodeWatcher::notify_child_removed(Badge<Inode>, const String& child_name)
+void InodeWatcher::notify_child_removed(Badge<Inode>, const InodeIdentifier& child_id)
{
LOCKER(m_lock);
- m_queue.enqueue({ Event::Type::ChildRemoved, child_name });
+ m_queue.enqueue({ Event::Type::ChildRemoved, child_id.index() });
}
}
diff --git a/Kernel/FileSystem/InodeWatcher.h b/Kernel/FileSystem/InodeWatcher.h
index cd371e2f1a..3396159064 100644
--- a/Kernel/FileSystem/InodeWatcher.h
+++ b/Kernel/FileSystem/InodeWatcher.h
@@ -50,7 +50,7 @@ public:
};
Type type { Type::Invalid };
- String string;
+ unsigned inode_index { 0 };
};
virtual bool can_read(const FileDescription&, size_t) const override;
@@ -61,8 +61,8 @@ public:
virtual const char* class_name() const override { return "InodeWatcher"; };
void notify_inode_event(Badge<Inode>, Event::Type);
- void notify_child_added(Badge<Inode>, const String& child_name);
- void notify_child_removed(Badge<Inode>, const String& child_name);
+ void notify_child_added(Badge<Inode>, const InodeIdentifier& child_id);
+ void notify_child_removed(Badge<Inode>, const InodeIdentifier& child_id);
private:
explicit InodeWatcher(Inode&);
diff --git a/Kernel/FileSystem/TmpFS.cpp b/Kernel/FileSystem/TmpFS.cpp
index 31222d6e87..24b7acc638 100644
--- a/Kernel/FileSystem/TmpFS.cpp
+++ b/Kernel/FileSystem/TmpFS.cpp
@@ -298,7 +298,7 @@ KResult TmpFSInode::add_child(Inode& child, const StringView& name, mode_t)
ASSERT(child.fsid() == fsid());
m_children.set(name, { name, static_cast<TmpFSInode&>(child) });
- did_add_child(name);
+ did_add_child(child.identifier());
return KSuccess;
}
@@ -313,8 +313,9 @@ KResult TmpFSInode::remove_child(const StringView& name)
auto it = m_children.find(name);
if (it == m_children.end())
return KResult(-ENOENT);
+ auto child_id = it->value.inode->identifier();
m_children.remove(it);
- did_remove_child(name);
+ did_remove_child(child_id);
return KSuccess;
}