file_systems: Add O_DIRECTORY checks to many filesystems that were missing them.

This doesn't get all the filesystems that were missing these checks
(e.g. I didn't adjust the more "WIP" filesystems like XFS and BTRFS)
but it does get most of them.
This commit is contained in:
Augustin Cavalier
2025-03-10 23:30:07 -04:00
parent 992f1401b2
commit ed5c4d8a2d
6 changed files with 20 additions and 2 deletions
@@ -461,6 +461,8 @@ exfat_open(fs_volume* /*_volume*/, fs_vnode* _node, int openMode,
// any data from it. // any data from it.
if (inode->IsDirectory() && (openMode & O_RWMASK) != 0) if (inode->IsDirectory() && (openMode & O_RWMASK) != 0)
return B_IS_A_DIRECTORY; return B_IS_A_DIRECTORY;
if ((openMode & O_DIRECTORY) != 0 && !inode->IsDirectory())
return B_NOT_A_DIRECTORY;
status_t status = inode->CheckPermissions(open_mode_to_access(openMode)); status_t status = inode->CheckPermissions(open_mode_to_access(openMode));
if (status != B_OK) if (status != B_OK)
@@ -1147,6 +1147,8 @@ ext2_open(fs_volume* _volume, fs_vnode* _node, int openMode, void** _cookie)
// any data from it. // any data from it.
if (inode->IsDirectory() && (openMode & O_RWMASK) != 0) if (inode->IsDirectory() && (openMode & O_RWMASK) != 0)
return B_IS_A_DIRECTORY; return B_IS_A_DIRECTORY;
if ((openMode & O_DIRECTORY) != 0 && !inode->IsDirectory())
return B_NOT_A_DIRECTORY;
status_t status = inode->CheckPermissions(open_mode_to_access(openMode)); status_t status = inode->CheckPermissions(open_mode_to_access(openMode));
if (status != B_OK) if (status != B_OK)
@@ -511,11 +511,16 @@ fs_read_stat(fs_volume* _volume, fs_vnode* _node, struct stat* st)
static status_t static status_t
fs_open(fs_volume* /*_volume*/, fs_vnode* _node, int openMode, void** /*cookie*/) fs_open(fs_volume* /*_volume*/, fs_vnode* _node, int openMode, void** /*cookie*/)
{ {
iso9660_inode* node = (iso9660_inode*)_node->private_node;
// Do not allow any of the write-like open modes to get by // Do not allow any of the write-like open modes to get by
if ((openMode & O_RWMASK) == O_WRONLY || (openMode & O_RWMASK) == O_RDWR if ((openMode & O_RWMASK) == O_WRONLY || (openMode & O_RWMASK) == O_RDWR
|| (openMode & O_TRUNC) != 0 || (openMode & O_CREAT) != 0) || (openMode & O_TRUNC) != 0 || (openMode & O_CREAT) != 0)
return EROFS; return EROFS;
if ((openMode & O_DIRECTORY) != 0 && (node->flags & ISO_IS_DIR) == 0)
return B_NOT_A_DIRECTORY;
return B_OK; return B_OK;
} }
@@ -838,6 +838,11 @@ nfs4_open(fs_volume* volume, fs_vnode* vnode, int openMode, void** _cookie)
if (inode == NULL) if (inode == NULL)
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
if (inode->Type() == S_IFDIR && (openMode & O_RWMASK) != O_RDONLY)
return B_IS_A_DIRECTORY;
if ((openMode & O_DIRECTORY) != 0 && inode->Type() != S_IFDIR)
return B_NOT_A_DIRECTORY;
if (inode->Type() == S_IFDIR || inode->Type() == S_IFLNK) { if (inode->Type() == S_IFDIR || inode->Type() == S_IFLNK) {
*_cookie = NULL; *_cookie = NULL;
return B_OK; return B_OK;
@@ -423,6 +423,8 @@ packagefs_open(fs_volume* fsVolume, fs_vnode* fsNode, int openMode,
// check the open mode and permissions // check the open mode and permissions
if (S_ISDIR(node->Mode()) && (openMode & O_RWMASK) != O_RDONLY) if (S_ISDIR(node->Mode()) && (openMode & O_RWMASK) != O_RDONLY)
return B_IS_A_DIRECTORY; return B_IS_A_DIRECTORY;
if ((openMode & O_DIRECTORY) != 0 && !S_ISDIR(node->Mode()))
return B_NOT_A_DIRECTORY;
if ((openMode & O_RWMASK) != O_RDONLY) if ((openMode & O_RWMASK) != O_RDONLY)
return B_NOT_ALLOWED; return B_NOT_ALLOWED;
@@ -263,8 +263,10 @@ ufs2_open(fs_volume * _volume, fs_vnode *_node, int openMode,
// opening a directory read-only is allowed, although you can't read // opening a directory read-only is allowed, although you can't read
// any data from it. // any data from it.
if (inode->IsDirectory() && (openMode & O_RWMASK) != 0) if (inode->IsDirectory() && (openMode & O_RWMASK) != O_RDONLY)
return B_IS_A_DIRECTORY; return B_IS_A_DIRECTORY;
if ((openMode & O_DIRECTORY) != 0 && !inode->IsDirectory())
return B_NOT_A_DIRECTORY;
status_t status = inode->CheckPermissions(open_mode_to_access(openMode) status_t status = inode->CheckPermissions(open_mode_to_access(openMode)
| (openMode & O_TRUNC ? W_OK : 0)); | (openMode & O_TRUNC ? W_OK : 0));