From 95adf8345454608f893a1cb20858be01297c8354 Mon Sep 17 00:00:00 2001 From: Vladimir Serbinenko Date: Mon, 21 Aug 2023 02:20:19 +0200 Subject: [PATCH] ufs2: Add missing CheckPermissions This brings us in-line with ext2 Change-Id: I0be7c4b1cbcd5a0a9f501e3e512b5bf6d0b86ffe Reviewed-on: https://review.haiku-os.org/c/haiku/+/6865 Reviewed-by: Adrien Destugues --- .../file_systems/ufs2/kernel_interface.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/add-ons/kernel/file_systems/ufs2/kernel_interface.cpp b/src/add-ons/kernel/file_systems/ufs2/kernel_interface.cpp index 77410be079..7faba15db7 100644 --- a/src/add-ons/kernel/file_systems/ufs2/kernel_interface.cpp +++ b/src/add-ons/kernel/file_systems/ufs2/kernel_interface.cpp @@ -5,6 +5,8 @@ #include +#include + #include "DirectoryIterator.h" #include "Inode.h" #include "system_dependencies.h" @@ -221,8 +223,12 @@ ufs2_lookup(fs_volume *_volume, fs_vnode *_directory, const char *name, Volume* volume = (Volume*)_volume->private_volume; Inode* directory = (Inode*)_directory->private_node; - status_t status = DirectoryIterator(directory).Lookup(name, _vnodeID); + // check access permissions + status_t status = directory->CheckPermissions(X_OK); + if (status < B_OK) + return status; + status = DirectoryIterator(directory).Lookup(name, _vnodeID); if (status != B_OK) return status; @@ -277,6 +283,11 @@ ufs2_open(fs_volume * _volume, fs_vnode *_node, int openMode, if (inode->IsDirectory() && (openMode & O_RWMASK) != 0) return B_IS_A_DIRECTORY; + status_t status = inode->CheckPermissions(open_mode_to_access(openMode) + | (openMode & O_TRUNC ? W_OK : 0)); + if (status != B_OK) + return status; + file_cookie* cookie = new(std::nothrow) file_cookie; if (cookie == NULL) return B_NO_MEMORY; @@ -370,6 +381,10 @@ ufs2_open_dir(fs_volume * /*_volume*/, fs_vnode *_node, void **_cookie) { Inode* inode = (Inode*)_node->private_node; + status_t status = inode->CheckPermissions(R_OK); + if (status < B_OK) + return status; + if (!inode->IsDirectory()) return B_NOT_A_DIRECTORY;