parse-helpers: allow port 0 for socket bind items
This patch adds a new parameter to parse_ip_port_range, giving callers the option to allow ranges to have their min be 0 instead of 1. This is then used by parse_ip_ports_token, intern used by parse_socket_bind_item to allow port 0 when restricting bind system calls with SocketBindDeny / SocketBindAllow. With this, users running server software written using the golang standard library will be able to effectively sandbox their software, albeit with a small loss in security protections by allowing the process to bind on a random port in the /proc/sys/net/ipv4/ip_local_port_range.
This commit is contained in:
committed by
Yu Watanabe
parent
9807ee19b0
commit
dcfac3a3f9
@@ -102,6 +102,8 @@ static int parse_ip_ports_token(
|
||||
uint16_t *nr_ports,
|
||||
uint16_t *port_min) {
|
||||
|
||||
int r;
|
||||
|
||||
assert(token);
|
||||
assert(nr_ports);
|
||||
assert(port_min);
|
||||
@@ -110,7 +112,7 @@ static int parse_ip_ports_token(
|
||||
*nr_ports = *port_min = 0;
|
||||
else {
|
||||
uint16_t mn = 0, mx = 0;
|
||||
int r = parse_ip_port_range(token, &mn, &mx);
|
||||
r = parse_ip_port_range(token, &mn, &mx, /* allow_zero = */ true);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -194,6 +196,7 @@ int parse_socket_bind_item(
|
||||
*ip_protocol = proto;
|
||||
*nr_ports = nr;
|
||||
*port_min = mn;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user