Skip to content

Commit 386642f

Browse files
James Bellamyawesomekling
authored andcommitted
Kernel: Use credentials object in VirtualFileSystem
Use credentials object in mknod, create, mkdir, and symlink
1 parent 8ef5dbe commit 386642f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Kernel/FileSystem/VirtualFileSystem.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,14 +347,15 @@ ErrorOr<void> VirtualFileSystem::mknod(StringView path, mode_t mode, dev_t dev,
347347
return existing_file_or_error.release_error();
348348
auto& parent_inode = parent_custody->inode();
349349
auto& current_process = Process::current();
350+
auto current_process_credentials = current_process.credentials();
350351
if (!parent_inode.metadata().may_write(current_process))
351352
return EACCES;
352353
if (parent_custody->is_readonly())
353354
return EROFS;
354355

355356
auto basename = KLexicalPath::basename(path);
356357
dbgln_if(VFS_DEBUG, "VirtualFileSystem::mknod: '{}' mode={} dev={} in {}", basename, mode, dev, parent_inode.identifier());
357-
(void)TRY(parent_inode.create_child(basename, mode, dev, current_process.euid(), current_process.egid()));
358+
(void)TRY(parent_inode.create_child(basename, mode, dev, current_process_credentials->euid(), current_process_credentials->egid()));
358359
return {};
359360
}
360361

@@ -372,14 +373,15 @@ ErrorOr<NonnullLockRefPtr<OpenFileDescription>> VirtualFileSystem::create(String
372373

373374
auto& parent_inode = parent_custody.inode();
374375
auto& current_process = Process::current();
376+
auto current_process_credentials = current_process.credentials();
375377
if (!parent_inode.metadata().may_write(current_process))
376378
return EACCES;
377379
if (parent_custody.is_readonly())
378380
return EROFS;
379381

380382
dbgln_if(VFS_DEBUG, "VirtualFileSystem::create: '{}' in {}", basename, parent_inode.identifier());
381-
auto uid = owner.has_value() ? owner.value().uid : current_process.euid();
382-
auto gid = owner.has_value() ? owner.value().gid : current_process.egid();
383+
auto uid = owner.has_value() ? owner.value().uid : current_process_credentials->euid();
384+
auto gid = owner.has_value() ? owner.value().gid : current_process_credentials->egid();
383385

384386
auto inode = TRY(parent_inode.create_child(basename, mode, 0, uid, gid));
385387
auto custody = TRY(Custody::try_create(&parent_custody, basename, inode, parent_custody.mount_flags()));
@@ -416,14 +418,15 @@ ErrorOr<void> VirtualFileSystem::mkdir(StringView path, mode_t mode, Custody& ba
416418
TRY(validate_path_against_process_veil(*parent_custody, O_CREAT));
417419
auto& parent_inode = parent_custody->inode();
418420
auto& current_process = Process::current();
421+
auto current_process_credentials = current_process.credentials();
419422
if (!parent_inode.metadata().may_write(current_process))
420423
return EACCES;
421424
if (parent_custody->is_readonly())
422425
return EROFS;
423426

424427
auto basename = KLexicalPath::basename(path);
425428
dbgln_if(VFS_DEBUG, "VirtualFileSystem::mkdir: '{}' in {}", basename, parent_inode.identifier());
426-
(void)TRY(parent_inode.create_child(basename, S_IFDIR | mode, 0, current_process.euid(), current_process.egid()));
429+
(void)TRY(parent_inode.create_child(basename, S_IFDIR | mode, 0, current_process_credentials->euid(), current_process_credentials->egid()));
427430
return {};
428431
}
429432

@@ -705,6 +708,7 @@ ErrorOr<void> VirtualFileSystem::symlink(StringView target, StringView linkpath,
705708
return existing_custody_or_error.release_error();
706709
auto& parent_inode = parent_custody->inode();
707710
auto& current_process = Process::current();
711+
auto current_process_credentials = current_process.credentials();
708712
if (!parent_inode.metadata().may_write(current_process))
709713
return EACCES;
710714
if (parent_custody->is_readonly())
@@ -713,7 +717,7 @@ ErrorOr<void> VirtualFileSystem::symlink(StringView target, StringView linkpath,
713717
auto basename = KLexicalPath::basename(linkpath);
714718
dbgln_if(VFS_DEBUG, "VirtualFileSystem::symlink: '{}' (-> '{}') in {}", basename, target, parent_inode.identifier());
715719

716-
auto inode = TRY(parent_inode.create_child(basename, S_IFLNK | 0644, 0, current_process.euid(), current_process.egid()));
720+
auto inode = TRY(parent_inode.create_child(basename, S_IFLNK | 0644, 0, current_process_credentials->euid(), current_process_credentials->egid()));
717721

718722
auto target_buffer = UserOrKernelBuffer::for_kernel_buffer(const_cast<u8*>((u8 const*)target.characters_without_null_termination()));
719723
MutexLocker locker(inode->m_inode_lock);

0 commit comments

Comments
 (0)