mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
Kernel: Don't allow non-superusers to bind TCP/UDP ports < 1024
This commit is contained in:
parent
41d113713d
commit
c82627aae2
1 changed files with 10 additions and 1 deletions
|
@ -82,8 +82,17 @@ KResult IPv4Socket::bind(const sockaddr* address, socklen_t address_size)
|
|||
return KResult(-EINVAL);
|
||||
|
||||
auto& ia = *(const sockaddr_in*)address;
|
||||
|
||||
auto requested_local_port = ntohs(ia.sin_port);
|
||||
if (!current->process().is_superuser()) {
|
||||
if (requested_local_port < 1024) {
|
||||
dbg() << current->process() << " (uid " << current->process().uid() << ") attempted to bind " << class_name() << " to port " << requested_local_port;
|
||||
return KResult(-EACCES);
|
||||
}
|
||||
}
|
||||
|
||||
m_local_address = IPv4Address((const u8*)&ia.sin_addr.s_addr);
|
||||
m_local_port = ntohs(ia.sin_port);
|
||||
m_local_port = requested_local_port;
|
||||
|
||||
dbgprintf("IPv4Socket::bind %s{%p} to %s:%u\n", class_name(), this, m_local_address.to_string().characters(), m_local_port);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue