1
0
Fork 0
alistair23-linux/net/netfilter/ipvs
Julian Anastasov 762c400766 ipvs: drop conn templates under attack
Before now, connection templates were ignored by the random
dropentry procedure. But Michal Koutný suggests that we
should add exception for connections under SYN attack.
He provided patch that implements it for TCP:

<quote>

IPVS includes protection against filling the ip_vs_conn_tab by
dropping 1/32 of feasible entries every second. The template
entries (for persistent services) are never directly deleted by
this mechanism but when a picked TCP connection entry is being
dropped (1), the respective template entry is dropped too (realized
by expiring 60 seconds after the connection entry being dropped).

There is another mechanism that removes connection entries when they
time out (2), in this case the associated template entry is not deleted.
Under SYN flood template entries would accumulate (due to their entry
longer timeout).

The accumulation takes place also with drop_entry being enabled. Roughly
15% ((31/32)^60) of SYN_RECV connections survive the dropping mechanism
(1) and are removed by the timeout mechanism (2)(defaults to 60 seconds
for SYN_RECV), thus template entries would still accumulate.

The patch ensures that when a connection entry times out, we also remove
the template entry from the table. To prevent breaking persistent
services (since the connection may time out in already established state)
we add a new entry flag to protect templates what spawned at least one
established TCP connection.

</quote>

We already added ASSURED flag for the templates in previous patch, so
that we can use it now to decide which connection templates should be
dropped under attack. But we also have some cases that need special
handling.

We modify the dropentry procedure as follows:

- Linux timers currently use LIFO ordering but we can not rely on
this to drop controlling connections. So, set cp->timeout to 0
to indicate that connection was dropped and that on expiration we
should try to drop our controlling connections. As result, we can
now avoid the ip_vs_conn_expire_now call.

- move the cp->n_control check above, so that it avoids restarting
the timer for controlling connections when not needed.

- drop unassured connection templates here if they are not referred
by any connections.

On connection expiration: if connection was dropped (cp->timeout=0)
try to drop our controlling connection except if it is a template
in assured state.

In ip_vs_conn_flush change order of ip_vs_conn_expire_now calls
according to the LIFO timer expiration order. It should work
faster for controlling connections with single controlled one.

Suggested-by: Michal Koutný <mkoutny@suse.com>
Signed-off-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2018-07-18 11:26:41 +02:00
..
Kconfig netfilter: ipvs: Add configurations of Maglev hashing 2018-04-09 10:11:18 +03:00
Makefile netfilter: ipvs: Add configurations of Maglev hashing 2018-04-09 10:11:18 +03:00
ip_vs_app.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2018-06-06 18:39:49 -07:00
ip_vs_conn.c ipvs: drop conn templates under attack 2018-07-18 11:26:41 +02:00
ip_vs_core.c ipvs: fix stats update from local clients 2018-05-08 14:15:21 +02:00
ip_vs_ctl.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf 2018-06-11 14:24:32 -07:00
ip_vs_dh.c ipvs: fix multiplicative hashing in sh/dh/lblc/lblcr algorithms 2018-04-09 10:15:27 +03:00
ip_vs_est.c netfilter: ipvs: Convert timers to use timer_setup() 2017-11-08 15:53:58 -08:00
ip_vs_fo.c ipvs: use correct address family in scheduler logs 2014-09-18 08:59:23 +09:00
ip_vs_ftp.c ipvs: add ipv6 support to ftp 2018-06-01 14:01:54 +02:00
ip_vs_lblc.c ipvs: initialize tbl->entries in ip_vs_lblc_init_svc() 2018-04-27 00:20:33 +02:00
ip_vs_lblcr.c ipvs: initialize tbl->entries after allocation 2018-04-27 00:20:33 +02:00
ip_vs_lc.c ipvs: use correct address family in scheduler logs 2014-09-18 08:59:23 +09:00
ip_vs_mh.c netfilter: ipvs: Add Maglev hashing scheduler 2018-04-09 10:10:57 +03:00
ip_vs_nfct.c ipvs: add full ipv6 support to nfct 2018-06-01 14:01:54 +02:00
ip_vs_nq.c netfilter: refcounter conversions 2017-03-17 12:49:43 +01:00
ip_vs_ovf.c ipvs: Add ovf scheduler 2015-08-21 09:08:39 -07:00
ip_vs_pe.c netfilter: Deletion of unnecessary checks before two function calls 2014-11-20 13:08:43 +01:00
ip_vs_pe_sip.c ipvs: handle connections started by real-servers 2016-04-20 12:34:17 +10:00
ip_vs_proto.c ipvs: add assured state for conn templates 2018-07-18 11:26:40 +02:00
ip_vs_proto_ah_esp.c ipvs: Pass ipvs into .conn_schedule and ip_vs_try_to_schedule 2015-09-24 09:34:41 +09:00
ip_vs_proto_sctp.c ipvs: add assured state for conn templates 2018-07-18 11:26:40 +02:00
ip_vs_proto_tcp.c ipvs: add assured state for conn templates 2018-07-18 11:26:40 +02:00
ip_vs_proto_udp.c ipvs: add assured state for conn templates 2018-07-18 11:26:40 +02:00
ip_vs_rr.c netfilter: refcounter conversions 2017-03-17 12:49:43 +01:00
ip_vs_sched.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next 2015-08-04 23:57:45 -07:00
ip_vs_sed.c netfilter: refcounter conversions 2017-03-17 12:49:43 +01:00
ip_vs_sh.c ipvs: fix multiplicative hashing in sh/dh/lblc/lblcr algorithms 2018-04-09 10:15:27 +03:00
ip_vs_sync.c ipvs: add assured state for conn templates 2018-07-18 11:26:40 +02:00
ip_vs_wlc.c netfilter: refcounter conversions 2017-03-17 12:49:43 +01:00
ip_vs_wrr.c netfilter: refcounter conversions 2017-03-17 12:49:43 +01:00
ip_vs_xmit.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf 2018-06-11 14:24:32 -07:00