Kernel: Use the resolved parent path when testing create veil (#5231)

This commit is contained in:
William Bowling 2021-02-07 05:11:44 +11:00 committed by GitHub
parent 1dad63824b
commit b97d23a71f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
Notes: sideshowbarker 2024-07-19 01:59:31 +09:00
2 changed files with 102 additions and 2 deletions

View file

@ -383,7 +383,8 @@ KResult VFS::mknod(StringView path, mode_t mode, dev_t dev, Custody& base)
KResultOr<NonnullRefPtr<FileDescription>> VFS::create(StringView path, int options, mode_t mode, Custody& parent_custody, Optional<UidAndGid> owner)
{
auto result = validate_path_against_process_veil(path, options);
LexicalPath p(path);
auto result = validate_path_against_process_veil(String::formatted("{}/{}", parent_custody.absolute_path(), p.basename()), options);
if (result.is_error())
return result;
@ -399,7 +400,6 @@ KResultOr<NonnullRefPtr<FileDescription>> VFS::create(StringView path, int optio
if (parent_custody.is_readonly())
return EROFS;
LexicalPath p(path);
dbgln<VFS_DEBUG>("VFS::create: '{}' in {}", p.basename(), parent_inode.identifier());
uid_t uid = owner.has_value() ? owner.value().uid : current_process->euid();
gid_t gid = owner.has_value() ? owner.value().gid : current_process->egid();
@ -1031,6 +1031,10 @@ KResultOr<NonnullRefPtr<Custody>> VFS::resolve_path_without_veil(StringView path
if (!safe_to_follow_symlink(*child_inode, parent_metadata))
return EACCES;
auto result = validate_path_against_process_veil(custody->absolute_path(), options);
if (result.is_error())
return result;
auto symlink_target = child_inode->resolve_as_link(parent, out_parent, options, symlink_recursion_level + 1);
if (symlink_target.is_error() || !have_more_parts)
return symlink_target;