1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Prevent escaping the root filesystem.

This commit is contained in:
Jonas 'Sortie' Termansen 2013-05-29 23:01:46 +02:00
parent 871469d443
commit 6a62446bab

View file

@ -25,6 +25,7 @@
#include <sortix/kernel/platform.h>
#include <sortix/kernel/refcount.h>
#include <sortix/kernel/ioctx.h>
#include <sortix/kernel/descriptor.h>
#include <sortix/kernel/inode.h>
#include <sortix/kernel/vnode.h>
#include <sortix/kernel/mtable.h>
@ -68,9 +69,18 @@ Vnode::~Vnode()
Ref<Vnode> Vnode::open(ioctx_t* ctx, const char* filename, int flags, mode_t mode)
{
bool dotdot = strcmp(filename, "..") == 0;
// Prevent escaping the root filesystem.
if ( dotdot )
{
Ref<Descriptor> root = CurrentProcess()->GetRoot();
if ( root->ino == ino && root->dev == dev )
return Ref<Vnode>(this);
}
// Handle transition across filesystem mount points.
bool isroot = inode->ino == rootino && inode->dev == rootdev;
bool dotdot = strcmp(filename, "..") == 0;
if ( isroot && dotdot && mountedat )
return mountedat;