mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Check remaining traversal limit when creating a file through a symlink.
This fixes the case when an app tries to create a file that already exists, and is a symlink to itself. A test was added. PiperOrigin-RevId: 256044811
This commit is contained in:
committed by
gVisor bot
parent
3446f4e29b
commit
06537129a6
@@ -354,6 +354,12 @@ func createAt(t *kernel.Task, dirFD kdefs.FD, addr usermem.Addr, flags uint, mod
|
||||
break
|
||||
}
|
||||
|
||||
// Are we able to resolve further?
|
||||
if remainingTraversals == 0 {
|
||||
found.DecRef()
|
||||
return syscall.ELOOP
|
||||
}
|
||||
|
||||
// Resolve the symlink to a path via Readlink.
|
||||
path, err := found.Inode.Readlink(t)
|
||||
if err != nil {
|
||||
|
||||
@@ -312,6 +312,19 @@ TEST_P(ParamSymlinkTest, OpenLinkCreatesTarget) {
|
||||
ASSERT_THAT(unlink(target.c_str()), SyscallSucceeds());
|
||||
}
|
||||
|
||||
// Test that opening a self-symlink with O_CREAT will fail with ELOOP.
|
||||
TEST_P(ParamSymlinkTest, CreateExistingSelfLink) {
|
||||
ASSERT_THAT(chdir(GetAbsoluteTestTmpdir().c_str()), SyscallSucceeds());
|
||||
|
||||
const std::string linkpath = GetParam();
|
||||
ASSERT_THAT(symlink(linkpath.c_str(), linkpath.c_str()), SyscallSucceeds());
|
||||
|
||||
EXPECT_THAT(open(linkpath.c_str(), O_CREAT, 0666),
|
||||
SyscallFailsWithErrno(ELOOP));
|
||||
|
||||
ASSERT_THAT(unlink(linkpath.c_str()), SyscallSucceeds());
|
||||
}
|
||||
|
||||
// Test that opening an existing symlink with O_CREAT|O_EXCL will fail with
|
||||
// EEXIST.
|
||||
TEST_P(ParamSymlinkTest, OpenLinkExclFails) {
|
||||
|
||||
Reference in New Issue
Block a user