Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3e67f106 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller
Browse files

inet: frags: break the 2GB limit for frags storage



Some users are willing to provision huge amounts of memory to be able
to perform reassembly reasonnably well under pressure.

Current memory tracking is using one atomic_t and integers.

Switch to atomic_long_t so that 64bit arches can use more than 2GB,
without any cost for 32bit arches.

Note that this patch avoids an overflow error, if high_thresh was set
to ~2GB, since this test in inet_frag_alloc() was never true :

if (... || frag_mem_limit(nf) > nf->high_thresh)

Tested:

$ echo 16000000000 >/proc/sys/net/ipv4/ipfrag_high_thresh

<frag DDOS>

$ grep FRAG /proc/net/sockstat
FRAG: inuse 14705885 memory 16000002880

$ nstat -n ; sleep 1 ; nstat | grep Reas
IpReasmReqds                    3317150            0.0
IpReasmFails                    3317112            0.0

Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 2d44ed22
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -133,10 +133,10 @@ min_adv_mss - INTEGER

IP Fragmentation:

ipfrag_high_thresh - INTEGER
ipfrag_high_thresh - LONG INTEGER
	Maximum memory used to reassemble IP fragments.

ipfrag_low_thresh - INTEGER
ipfrag_low_thresh - LONG INTEGER
	(Obsolete since linux-4.17)
	Maximum memory used to reassemble IP fragments before the kernel
	begins to remove incomplete fragment queues to free up resources.
+10 −10
Original line number Diff line number Diff line
@@ -8,11 +8,11 @@ struct netns_frags {
	struct rhashtable       rhashtable ____cacheline_aligned_in_smp;

	/* Keep atomic mem on separate cachelines in structs that include it */
	atomic_t		mem ____cacheline_aligned_in_smp;
	atomic_long_t		mem ____cacheline_aligned_in_smp;
	/* sysctls */
	long			high_thresh;
	long			low_thresh;
	int			timeout;
	int			high_thresh;
	int			low_thresh;
	int			max_dist;
	struct inet_frags	*f;
};
@@ -102,7 +102,7 @@ void inet_frags_fini(struct inet_frags *);

static inline int inet_frags_init_net(struct netns_frags *nf)
{
	atomic_set(&nf->mem, 0);
	atomic_long_set(&nf->mem, 0);
	return rhashtable_init(&nf->rhashtable, &nf->f->rhash_params);
}
void inet_frags_exit_net(struct netns_frags *nf);
@@ -119,19 +119,19 @@ static inline void inet_frag_put(struct inet_frag_queue *q)

/* Memory Tracking Functions. */

static inline int frag_mem_limit(struct netns_frags *nf)
static inline long frag_mem_limit(const struct netns_frags *nf)
{
	return atomic_read(&nf->mem);
	return atomic_long_read(&nf->mem);
}

static inline void sub_frag_mem_limit(struct netns_frags *nf, int i)
static inline void sub_frag_mem_limit(struct netns_frags *nf, long val)
{
	atomic_sub(i, &nf->mem);
	atomic_long_sub(val, &nf->mem);
}

static inline void add_frag_mem_limit(struct netns_frags *nf, int i)
static inline void add_frag_mem_limit(struct netns_frags *nf, long val)
{
	atomic_add(i, &nf->mem);
	atomic_long_add(val, &nf->mem);
}

/* RFC 3168 support :
+5 −5
Original line number Diff line number Diff line
@@ -411,23 +411,23 @@ int lowpan_frag_rcv(struct sk_buff *skb, u8 frag_type)
}

#ifdef CONFIG_SYSCTL
static int zero;
static long zero;

static struct ctl_table lowpan_frags_ns_ctl_table[] = {
	{
		.procname	= "6lowpanfrag_high_thresh",
		.data		= &init_net.ieee802154_lowpan.frags.high_thresh,
		.maxlen		= sizeof(int),
		.maxlen		= sizeof(unsigned long),
		.mode		= 0644,
		.proc_handler	= proc_dointvec_minmax,
		.proc_handler	= proc_doulongvec_minmax,
		.extra1		= &init_net.ieee802154_lowpan.frags.low_thresh
	},
	{
		.procname	= "6lowpanfrag_low_thresh",
		.data		= &init_net.ieee802154_lowpan.frags.low_thresh,
		.maxlen		= sizeof(int),
		.maxlen		= sizeof(unsigned long),
		.mode		= 0644,
		.proc_handler	= proc_dointvec_minmax,
		.proc_handler	= proc_doulongvec_minmax,
		.extra1		= &zero,
		.extra2		= &init_net.ieee802154_lowpan.frags.high_thresh
	},
+5 −5
Original line number Diff line number Diff line
@@ -678,23 +678,23 @@ struct sk_buff *ip_check_defrag(struct net *net, struct sk_buff *skb, u32 user)
EXPORT_SYMBOL(ip_check_defrag);

#ifdef CONFIG_SYSCTL
static int zero;
static long zero;

static struct ctl_table ip4_frags_ns_ctl_table[] = {
	{
		.procname	= "ipfrag_high_thresh",
		.data		= &init_net.ipv4.frags.high_thresh,
		.maxlen		= sizeof(int),
		.maxlen		= sizeof(unsigned long),
		.mode		= 0644,
		.proc_handler	= proc_dointvec_minmax,
		.proc_handler	= proc_doulongvec_minmax,
		.extra1		= &init_net.ipv4.frags.low_thresh
	},
	{
		.procname	= "ipfrag_low_thresh",
		.data		= &init_net.ipv4.frags.low_thresh,
		.maxlen		= sizeof(int),
		.maxlen		= sizeof(unsigned long),
		.mode		= 0644,
		.proc_handler	= proc_dointvec_minmax,
		.proc_handler	= proc_doulongvec_minmax,
		.extra1		= &zero,
		.extra2		= &init_net.ipv4.frags.high_thresh
	},
+1 −1
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ static int sockstat_seq_show(struct seq_file *seq, void *v)
		   sock_prot_inuse_get(net, &udplite_prot));
	seq_printf(seq, "RAW: inuse %d\n",
		   sock_prot_inuse_get(net, &raw_prot));
	seq_printf(seq,  "FRAG: inuse %u memory %u\n",
	seq_printf(seq,  "FRAG: inuse %u memory %lu\n",
		   atomic_read(&net->ipv4.frags.rhashtable.nelems),
		   frag_mem_limit(&net->ipv4.frags));
	return 0;
Loading