1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:48:14 +00:00

Kernel: Strip SUID+SGID bits from file when written to or chowned

Fixes #1624.
This commit is contained in:
Andreas Kling 2020-04-04 19:46:55 +02:00
parent 040ba77d44
commit 53d0ca2ad8
6 changed files with 36 additions and 0 deletions

View file

@ -217,4 +217,19 @@ void Inode::set_metadata_dirty(bool metadata_dirty)
}
}
KResult Inode::prepare_to_write_data()
{
// FIXME: It's a poor design that filesystems are expected to call this before writing out data.
// We should funnel everything through an interface at the VFS layer so this can happen from a single place.
LOCKER(m_lock);
if (fs().is_readonly())
return KResult(-EROFS);
auto metadata = this->metadata();
if (metadata.is_setuid() || metadata.is_setgid()) {
dbg() << "Inode::prepare_to_write_data(): Stripping SUID/SGID bits from " << identifier();
return chmod(metadata.mode & ~(04000 | 02000));
}
return KSuccess;
}
}