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
@@ -37,6 +37,7 @@ static void test_invalid_item(const char *str) {
|
||||
|
||||
TEST(valid_items) {
|
||||
test_valid_item("any", AF_UNSPEC, 0, 0, 0);
|
||||
test_valid_item("0-65535", AF_UNSPEC, 0, 0, 0);
|
||||
test_valid_item("ipv4", AF_INET, 0, 0, 0);
|
||||
test_valid_item("ipv6", AF_INET6, 0, 0, 0);
|
||||
test_valid_item("ipv4:any", AF_INET, 0, 0, 0);
|
||||
@@ -45,6 +46,7 @@ TEST(valid_items) {
|
||||
test_valid_item("udp", AF_UNSPEC, IPPROTO_UDP, 0, 0);
|
||||
test_valid_item("tcp:any", AF_UNSPEC, IPPROTO_TCP, 0, 0);
|
||||
test_valid_item("udp:any", AF_UNSPEC, IPPROTO_UDP, 0, 0);
|
||||
test_valid_item("0", AF_UNSPEC, 0, 1, 0);
|
||||
test_valid_item("6666", AF_UNSPEC, 0, 1, 6666);
|
||||
test_valid_item("6666-6667", AF_UNSPEC, 0, 2, 6666);
|
||||
test_valid_item("65535", AF_UNSPEC, 0, 1, 65535);
|
||||
@@ -61,6 +63,7 @@ TEST(valid_items) {
|
||||
test_valid_item("ipv6:tcp:6666", AF_INET6, IPPROTO_TCP, 1, 6666);
|
||||
test_valid_item("ipv6:udp:6666-6667", AF_INET6, IPPROTO_UDP, 2, 6666);
|
||||
test_valid_item("ipv6:tcp:any", AF_INET6, IPPROTO_TCP, 0, 0);
|
||||
test_valid_item("ipv6:tcp:0", AF_INET6, IPPROTO_TCP, 1, 0);
|
||||
}
|
||||
|
||||
TEST(invalid_items) {
|
||||
@@ -77,9 +80,7 @@ TEST(invalid_items) {
|
||||
test_invalid_item("ipv6::");
|
||||
test_invalid_item("ipv6:ipv6");
|
||||
test_invalid_item("ipv6:icmp");
|
||||
test_invalid_item("ipv6:tcp:0");
|
||||
test_invalid_item("65536");
|
||||
test_invalid_item("0-65535");
|
||||
test_invalid_item("ipv6:tcp:6666-6665");
|
||||
test_invalid_item("ipv6:tcp:6666-100000");
|
||||
test_invalid_item("ipv6::6666");
|
||||
|
||||
Reference in New Issue
Block a user