[INET]: local port range robustness
Expansion of original idea from Denis V. Lunev <den@openvz.org> Add robustness and locking to the local_port_range sysctl. 1. Enforce that low < high when setting. 2. Use seqlock to ensure atomic update. The locking might seem like overkill, but there are cases where sysadmin might want to change value in the middle of a DoS attack. Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
0639300900
commit
227b60f510
@@ -279,19 +279,18 @@ int inet_hash_connect(struct inet_timewait_death_row *death_row,
|
||||
int ret;
|
||||
|
||||
if (!snum) {
|
||||
int low = sysctl_local_port_range[0];
|
||||
int high = sysctl_local_port_range[1];
|
||||
int range = high - low;
|
||||
int i;
|
||||
int port;
|
||||
int i, remaining, low, high, port;
|
||||
static u32 hint;
|
||||
u32 offset = hint + inet_sk_port_offset(sk);
|
||||
struct hlist_node *node;
|
||||
struct inet_timewait_sock *tw = NULL;
|
||||
|
||||
inet_get_local_port_range(&low, &high);
|
||||
remaining = high - low;
|
||||
|
||||
local_bh_disable();
|
||||
for (i = 1; i <= range; i++) {
|
||||
port = low + (i + offset) % range;
|
||||
for (i = 1; i <= remaining; i++) {
|
||||
port = low + (i + offset) % remaining;
|
||||
head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)];
|
||||
spin_lock(&head->lock);
|
||||
|
||||
|
Reference in New Issue
Block a user