sentry: support NULL mount source

NULL mount sources can be valid, e.g. when mounting "proc".

PiperOrigin-RevId: 653769241
This commit is contained in:
Kevin Krakauer
2024-07-18 15:12:40 -07:00
committed by gVisor bot
parent cd56935ddf
commit e39ed91daa
2 changed files with 28 additions and 3 deletions
+6 -3
View File
@@ -116,9 +116,12 @@ func Mount(t *kernel.Task, sysno uintptr, args arch.SyscallArguments) (uintptr,
}
// Only copy in source, fstype, and data if we are doing a normal mount.
source, err := t.CopyInString(sourceAddr, hostarch.PageSize)
if err != nil {
return 0, nil, err
var source string
if sourceAddr != 0 {
source, err = t.CopyInString(sourceAddr, hostarch.PageSize)
if err != nil {
return 0, nil, err
}
}
fsType, err := t.CopyInString(typeAddr, hostarch.PageSize)
if err != nil {
+22
View File
@@ -2328,6 +2328,28 @@ TEST(MountTest, DetachedMountBindFails) {
SyscallFailsWithErrno(EINVAL));
}
TEST(MountTest, MountProc) {
SKIP_IF(!ASSERT_NO_ERRNO_AND_VALUE(HaveCapability(CAP_SYS_ADMIN)));
// Mount procfs with a NULL source to a temporary directory.
const TempPath dir = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDir());
ASSERT_THAT(mount(NULL, dir.path().c_str(), "proc", 0, NULL),
SyscallSucceeds());
auto cleanup = Cleanup([&dir] {
EXPECT_THAT(umount2(dir.path().c_str(), 0), SyscallSucceeds());
});
// Verify that /proc/self/mountinfo describes the device as "none".
const std::vector<ProcMountInfoEntry> mountinfo =
ASSERT_NO_ERRNO_AND_VALUE(ProcSelfMountInfoEntries());
for (auto const& e : mountinfo) {
if (e.mount_point == dir.path()) {
EXPECT_EQ(e.fstype, "proc");
EXPECT_EQ(e.mount_source, "none");
}
}
}
} // namespace
} // namespace testing