mirror of
https://github.com/RGBCube/serenity
synced 2025-05-21 15:35:07 +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:
parent
7e10f76021
commit
db929e0fcf
5 changed files with 47 additions and 7 deletions
|
@ -471,8 +471,8 @@ InodeMetadata Ext2FSInode::metadata() const
|
|||
metadata.inode = identifier();
|
||||
metadata.size = size();
|
||||
metadata.mode = m_raw_inode.i_mode;
|
||||
metadata.uid = m_raw_inode.i_uid;
|
||||
metadata.gid = m_raw_inode.i_gid;
|
||||
metadata.uid = inode_uid(m_raw_inode);
|
||||
metadata.gid = inode_gid(m_raw_inode);
|
||||
metadata.link_count = m_raw_inode.i_links_count;
|
||||
metadata.atime = UnixDateTime::from_seconds_since_epoch(m_raw_inode.i_atime);
|
||||
metadata.ctime = UnixDateTime::from_seconds_since_epoch(m_raw_inode.i_ctime);
|
||||
|
@ -1051,10 +1051,12 @@ ErrorOr<void> Ext2FSInode::chmod(mode_t mode)
|
|||
ErrorOr<void> Ext2FSInode::chown(UserID uid, GroupID gid)
|
||||
{
|
||||
MutexLocker locker(m_inode_lock);
|
||||
if (m_raw_inode.i_uid == uid && m_raw_inode.i_gid == gid)
|
||||
if (inode_uid(m_raw_inode) == uid && inode_gid(m_raw_inode) == gid)
|
||||
return {};
|
||||
m_raw_inode.i_uid = uid.value();
|
||||
m_raw_inode.i_gid = gid.value();
|
||||
m_raw_inode.i_uid = static_cast<u16>(uid.value());
|
||||
ext2fs_set_i_uid_high(m_raw_inode, uid.value() >> 16);
|
||||
m_raw_inode.i_gid = static_cast<u16>(gid.value());
|
||||
ext2fs_set_i_gid_high(m_raw_inode, gid.value() >> 16);
|
||||
set_metadata_dirty(true);
|
||||
return {};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue