Kernel: Fix OOB write in sys$uname

Since this was only out of bounds of the specific field, not of the
whole struct, and because setting the hostname requires root privileges
this was not actually a security vulnerability.
This commit is contained in:
Idan Horowitz 2022-01-13 00:30:58 +02:00 committed by Brian Gianforcaro
parent 50d6a6a186
commit e72bbca9eb
Notes: sideshowbarker 2024-07-17 21:01:05 +09:00

View file

@ -24,7 +24,9 @@ ErrorOr<FlatPtr> Process::sys$uname(Userspace<utsname*> user_buf)
#endif
hostname().with_shared([&](const auto& name) {
memcpy(buf.nodename, name->characters(), name->length() + 1);
auto length = min(name->length(), UTSNAME_ENTRY_LEN - 1);
memcpy(buf.nodename, name->characters(), length);
buf.nodename[length] = '\0';
});
TRY(copy_to_user(user_buf, &buf));