1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:07:47 +00:00

Kernel: unlink() should not follow symlinks

This commit is contained in:
Andreas Kling 2020-01-10 12:51:05 +01:00
parent f026f0f4bb
commit b1ffde6199
2 changed files with 16 additions and 1 deletions

View file

@ -518,7 +518,7 @@ KResult VFS::link(StringView old_path, StringView new_path, Custody& base)
KResult VFS::unlink(StringView path, Custody& base) KResult VFS::unlink(StringView path, Custody& base)
{ {
RefPtr<Custody> parent_custody; RefPtr<Custody> parent_custody;
auto custody_or_error = resolve_path(path, base, &parent_custody); auto custody_or_error = resolve_path(path, base, &parent_custody, O_NOFOLLOW_NOERROR);
if (custody_or_error.is_error()) if (custody_or_error.is_error())
return custody_or_error.error(); return custody_or_error.error();
auto& custody = *custody_or_error.value(); auto& custody = *custody_or_error.value();

View file

@ -174,6 +174,20 @@ void test_open_create_device()
close(fd); close(fd);
} }
void test_unlink_symlink()
{
int rc = symlink("/proc/2/foo", "/tmp/linky");
if (rc < 0) {
perror("symlink");
ASSERT_NOT_REACHED();
}
rc = unlink("/tmp/linky");
if (rc < 0) {
perror("unlink");
fprintf(stderr, "Expected unlink() of a symlink into an unreadable directory to succeed!\n");
}
}
int main(int, char**) int main(int, char**)
{ {
int rc; int rc;
@ -196,6 +210,7 @@ int main(int, char**)
test_tmpfs_read_past_end(); test_tmpfs_read_past_end();
test_procfs_read_past_end(); test_procfs_read_past_end();
test_open_create_device(); test_open_create_device();
test_unlink_symlink();
return 0; return 0;
} }