1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 22:27:42 +00:00

Kernel/Ext2: Avoid overflow when updating UID and GID values

Previously, attempting to update an ext2 inode with a UID or GID
larger than 65535 would overflow. We now write the high bits of UIDs
and GIDs to the same place that Linux does within the `osd2` struct.
This commit is contained in:
Tim Ledbetter 2023-10-01 16:41:12 +01:00 committed by Andreas Kling
parent 7e10f76021
commit db929e0fcf
5 changed files with 47 additions and 7 deletions

View file

@ -0,0 +1,31 @@
/*
* Copyright (c) 2023, Tim Ledbetter <timledbetter@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibTest/TestCase.h>
#include <fcntl.h>
#include <unistd.h>
TEST_CASE(test_uid_and_gid_high_bits_are_set)
{
static constexpr auto TEST_FILE_PATH = "/home/anon/.ext2_test";
auto uid = geteuid();
EXPECT_EQ(uid, 0u);
auto fd = open(TEST_FILE_PATH, O_CREAT);
auto cleanup_guard = ScopeGuard([&] {
close(fd);
unlink(TEST_FILE_PATH);
});
EXPECT_EQ(setuid(0), 0);
EXPECT_EQ(fchown(fd, 65536, 65536), 0);
struct stat st;
EXPECT_EQ(fstat(fd, &st), 0);
EXPECT_EQ(st.st_uid, 65536u);
EXPECT_EQ(st.st_gid, 65536u);
}