1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-22 19:35:06 +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

@ -510,8 +510,10 @@ ErrorOr<NonnullRefPtr<Inode>> Ext2FS::create_inode(Ext2FSInode& parent_inode, St
ext2_inode e2inode {};
auto now = kgettimeofday().truncated_seconds_since_epoch();
e2inode.i_mode = mode;
e2inode.i_uid = uid.value();
e2inode.i_gid = gid.value();
e2inode.i_uid = static_cast<u16>(uid.value());
ext2fs_set_i_uid_high(e2inode, uid.value() >> 16);
e2inode.i_gid = static_cast<u16>(gid.value());
ext2fs_set_i_gid_high(e2inode, gid.value() >> 16);
e2inode.i_size = 0;
e2inode.i_atime = now;
e2inode.i_ctime = now;