From a1eceb461039d6f9d6e88006a70920be92b300ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 20 Jul 2017 10:10:20 +0200 Subject: [PATCH] rootfs: directories must not be opened writable. * Also added support for O_DIRECTORY while at it. * This fixes bug #13573. --- src/system/kernel/fs/rootfs.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/system/kernel/fs/rootfs.cpp b/src/system/kernel/fs/rootfs.cpp index 21214fa3f8..61678a6b2f 100644 --- a/src/system/kernel/fs/rootfs.cpp +++ b/src/system/kernel/fs/rootfs.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2002-2017, Axel Dörfler, axeld@pinc-software.de. * Distributed under the terms of the MIT License. * * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. @@ -583,8 +583,15 @@ rootfs_create(fs_volume* _volume, fs_vnode* _dir, const char* name, int omode, static status_t -rootfs_open(fs_volume* _volume, fs_vnode* _v, int oflags, void** _cookie) +rootfs_open(fs_volume* _volume, fs_vnode* _v, int openMode, void** _cookie) { + struct rootfs_vnode* vnode = (rootfs_vnode*)_v->private_node; + + if (S_ISDIR(vnode->stream.type) && (openMode & O_RWMASK) != O_RDONLY) + return B_IS_A_DIRECTORY; + if ((openMode & O_DIRECTORY) != 0 && !S_ISDIR(vnode->stream.type)) + return B_NOT_A_DIRECTORY; + // allow to open the file, but it can't be done anything with it *_cookie = NULL;