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

@ -511,6 +511,14 @@ KResult VFS::chown(Inode& inode, uid_t a_uid, gid_t a_gid)
}
dbg() << "VFS::chown(): inode " << inode.identifier() << " <- uid:" << new_uid << " gid:" << new_gid;
if (metadata.is_setuid() || metadata.is_setgid()) {
dbg() << "VFS::chown(): Stripping SUID/SGID bits from " << inode.identifier();
auto result = inode.chmod(metadata.mode & ~(04000 | 02000));
if (result.is_error())
return result;
}
return inode.chown(new_uid, new_gid);
}