From: Ben Hutchings <ben@decadent.org.uk>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: akpm@linux-foundation.org,
Hannes Frederic Sowa <hannes@stressinduktion.org>,
Eric Dumazet <eric.dumazet@gmail.com>,
Jesper Dangaard Brouer <jbrouer@redhat.com>,
Eric Dumazet <edumazet@google.com>,
"David S. Miller" <davem@davemloft.net>
Subject: [ 039/104] inet: limit length of fragment queue hash table bucket lists
Date: Mon, 25 Mar 2013 01:06:03 +0000 [thread overview]
Message-ID: <20130325010528.150797562@decadent.org.uk> (raw)
In-Reply-To: <20130325010524.240972766@decadent.org.uk>
3.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hannes Frederic Sowa <hannes@stressinduktion.org>
[ Upstream commit 5a3da1fe9561828d0ca7eca664b16ec2b9bf0055 ]
This patch introduces a constant limit of the fragment queue hash
table bucket list lengths. Currently the limit 128 is choosen somewhat
arbitrary and just ensures that we can fill up the fragment cache with
empty packets up to the default ip_frag_high_thresh limits. It should
just protect from list iteration eating considerable amounts of cpu.
If we reach the maximum length in one hash bucket a warning is printed.
This is implemented on the caller side of inet_frag_find to distinguish
between the different users of inet_fragment.c.
I dropped the out of memory warning in the ipv4 fragment lookup path,
because we already get a warning by the slab allocator.
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Jesper Dangaard Brouer <jbrouer@redhat.com>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Acked-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
include/net/inet_frag.h | 9 +++++++++
net/ipv4/inet_fragment.c | 20 +++++++++++++++++++-
net/ipv4/ip_fragment.c | 12 ++++++------
net/ipv6/netfilter/nf_conntrack_reasm.c | 11 ++++++-----
net/ipv6/reassembly.c | 8 ++++++--
5 files changed, 46 insertions(+), 14 deletions(-)
diff --git a/include/net/inet_frag.h b/include/net/inet_frag.h
index 16ff29a..b289bd2 100644
--- a/include/net/inet_frag.h
+++ b/include/net/inet_frag.h
@@ -33,6 +33,13 @@ struct inet_frag_queue {
#define INETFRAGS_HASHSZ 64
+/* averaged:
+ * max_depth = default ipfrag_high_thresh / INETFRAGS_HASHSZ /
+ * rounded up (SKB_TRUELEN(0) + sizeof(struct ipq or
+ * struct frag_queue))
+ */
+#define INETFRAGS_MAXDEPTH 128
+
struct inet_frags {
struct hlist_head hash[INETFRAGS_HASHSZ];
rwlock_t lock;
@@ -64,6 +71,8 @@ int inet_frag_evictor(struct netns_frags *nf, struct inet_frags *f);
struct inet_frag_queue *inet_frag_find(struct netns_frags *nf,
struct inet_frags *f, void *key, unsigned int hash)
__releases(&f->lock);
+void inet_frag_maybe_warn_overflow(struct inet_frag_queue *q,
+ const char *prefix);
static inline void inet_frag_put(struct inet_frag_queue *q, struct inet_frags *f)
{
diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c
index 5ff2a51..210b710 100644
--- a/net/ipv4/inet_fragment.c
+++ b/net/ipv4/inet_fragment.c
@@ -21,6 +21,7 @@
#include <linux/rtnetlink.h>
#include <linux/slab.h>
+#include <net/sock.h>
#include <net/inet_frag.h>
static void inet_frag_secret_rebuild(unsigned long dummy)
@@ -271,6 +272,7 @@ struct inet_frag_queue *inet_frag_find(struct netns_frags *nf,
{
struct inet_frag_queue *q;
struct hlist_node *n;
+ int depth = 0;
hlist_for_each_entry(q, n, &f->hash[hash], list) {
if (q->net == nf && f->match(q, key)) {
@@ -278,9 +280,25 @@ struct inet_frag_queue *inet_frag_find(struct netns_frags *nf,
read_unlock(&f->lock);
return q;
}
+ depth++;
}
read_unlock(&f->lock);
- return inet_frag_create(nf, f, key);
+ if (depth <= INETFRAGS_MAXDEPTH)
+ return inet_frag_create(nf, f, key);
+ else
+ return ERR_PTR(-ENOBUFS);
}
EXPORT_SYMBOL(inet_frag_find);
+
+void inet_frag_maybe_warn_overflow(struct inet_frag_queue *q,
+ const char *prefix)
+{
+ static const char msg[] = "inet_frag_find: Fragment hash bucket"
+ " list length grew over limit " __stringify(INETFRAGS_MAXDEPTH)
+ ". Dropping fragment.\n";
+
+ if (PTR_ERR(q) == -ENOBUFS)
+ LIMIT_NETDEBUG(KERN_WARNING "%s%s", prefix, msg);
+}
+EXPORT_SYMBOL(inet_frag_maybe_warn_overflow);
diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
index a4e7131..b2cfe83 100644
--- a/net/ipv4/ip_fragment.c
+++ b/net/ipv4/ip_fragment.c
@@ -20,6 +20,8 @@
* Patrick McHardy : LRU queue of frag heads for evictor.
*/
+#define pr_fmt(fmt) "IPv4: " fmt
+
#include <linux/compiler.h>
#include <linux/module.h>
#include <linux/types.h>
@@ -293,14 +295,12 @@ static inline struct ipq *ip_find(struct net *net, struct iphdr *iph, u32 user)
hash = ipqhashfn(iph->id, iph->saddr, iph->daddr, iph->protocol);
q = inet_frag_find(&net->ipv4.frags, &ip4_frags, &arg, hash);
- if (q == NULL)
- goto out_nomem;
+ if (IS_ERR_OR_NULL(q)) {
+ inet_frag_maybe_warn_overflow(q, pr_fmt());
+ return NULL;
+ }
return container_of(q, struct ipq, q);
-
-out_nomem:
- LIMIT_NETDEBUG(KERN_ERR "ip_frag_create: no memory left !\n");
- return NULL;
}
/* Is the fragment too far ahead to be part of ipq? */
diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
index 38f00b0..52e2f65 100644
--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
@@ -14,6 +14,8 @@
* 2 of the License, or (at your option) any later version.
*/
+#define pr_fmt(fmt) "IPv6-nf: " fmt
+
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/string.h>
@@ -176,13 +178,12 @@ fq_find(__be32 id, u32 user, struct in6_addr *src, struct in6_addr *dst)
q = inet_frag_find(&nf_init_frags, &nf_frags, &arg, hash);
local_bh_enable();
- if (q == NULL)
- goto oom;
+ if (IS_ERR_OR_NULL(q)) {
+ inet_frag_maybe_warn_overflow(q, pr_fmt());
+ return NULL;
+ }
return container_of(q, struct nf_ct_frag6_queue, q);
-
-oom:
- return NULL;
}
diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
index dfb164e..2b0a4ca 100644
--- a/net/ipv6/reassembly.c
+++ b/net/ipv6/reassembly.c
@@ -26,6 +26,9 @@
* YOSHIFUJI,H. @USAGI Always remove fragment header to
* calculate ICV correctly.
*/
+
+#define pr_fmt(fmt) "IPv6: " fmt
+
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/string.h>
@@ -240,9 +243,10 @@ fq_find(struct net *net, __be32 id, const struct in6_addr *src, const struct in6
hash = inet6_hash_frag(id, src, dst, ip6_frags.rnd);
q = inet_frag_find(&net->ipv6.frags, &ip6_frags, &arg, hash);
- if (q == NULL)
+ if (IS_ERR_OR_NULL(q)) {
+ inet_frag_maybe_warn_overflow(q, pr_fmt());
return NULL;
-
+ }
return container_of(q, struct frag_queue, q);
}
next prev parent reply other threads:[~2013-03-25 1:06 UTC|newest]
Thread overview: 110+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-25 0:34 [ 000/104] 3.2.42-stable review Ben Hutchings
2013-03-25 1:05 ` [ 001/104] TTY: do not reset masters packet mode Ben Hutchings
2013-03-25 1:05 ` [ 002/104] perf,x86: fix kernel crash with PEBS/BTS after suspend/resume Ben Hutchings
2013-03-25 1:05 ` [ 003/104] perf,x86: fix wrmsr_on_cpu() warning on suspend/resume Ben Hutchings
2013-03-25 1:05 ` [ 004/104] perf,x86: fix link failure for non-Intel configs Ben Hutchings
2013-03-25 1:05 ` [ 005/104] l2tp: Restore socket refcount when sendmsg succeeds Ben Hutchings
2013-03-25 1:05 ` [ 006/104] rds: limit the size allocated by rds_message_alloc() Ben Hutchings
2013-03-25 1:05 ` [ 007/104] net: ipv6: Dont purge default router if accept_ra=2 Ben Hutchings
2013-03-25 1:05 ` [ 008/104] tcp: fix double-counted receiver RTT when leaving receiver fast path Ben Hutchings
2013-03-25 1:05 ` [ 009/104] tun: add a missing nf_reset() in tun_net_xmit() Ben Hutchings
2013-03-25 1:05 ` [ 010/104] macvlan: Set IFF_UNICAST_FLT flag to prevent unnecessary promisc mode Ben Hutchings
2013-03-25 1:05 ` [ 011/104] netlabel: correctly list all the static label mappings Ben Hutchings
2013-03-25 1:05 ` [ 012/104] bridging: fix rx_handlers return code Ben Hutchings
2013-03-25 1:05 ` [ 013/104] ipv6: stop multicast forwarding to process interface scoped addresses Ben Hutchings
2013-03-25 1:05 ` [ 014/104] rtnl: fix info leak on RTM_GETLINK request for VF devices Ben Hutchings
2013-03-25 1:05 ` [ 015/104] dcbnl: fix various netlink info leaks Ben Hutchings
2013-03-25 1:05 ` [ 016/104] 6lowpan: Fix endianness issue in is_addr_link_local() Ben Hutchings
2013-03-25 1:05 ` [ 017/104] drm/i915: Increase the RC6p threshold Ben Hutchings
2013-03-25 1:05 ` [ 018/104] perf: Revert duplicated commit Ben Hutchings
2013-03-25 1:05 ` [ 019/104] i915: initialize CADL in opregion Ben Hutchings
2013-03-25 1:05 ` [ 020/104] s390/mm: fix flush_tlb_kernel_range() Ben Hutchings
2013-03-25 1:05 ` [ 021/104] mwifiex: fix potential out-of-boundary access to ibss rate table Ben Hutchings
2013-03-25 1:05 ` [ 022/104] rtlwifi: rtl8192cu: Fix schedule while atomic bug splat Ben Hutchings
2013-03-25 1:05 ` [ 023/104] powerpc: Fix cputable entry for 970MP rev 1.0 Ben Hutchings
2013-03-25 1:05 ` [ 024/104] rtlwifi: rtl8192cu: Fix problem that prevents reassociation Ben Hutchings
2013-03-25 1:05 ` [ 025/104] vhost/net: fix heads usage of ubuf_info Ben Hutchings
2013-03-25 1:05 ` [ 026/104] selinux: use GFP_ATOMIC under spin_lock Ben Hutchings
2013-03-25 1:05 ` [ 027/104] tools: hv: Netlink source address validation allows DoS Ben Hutchings
2013-03-25 1:05 ` [ 028/104] udf: avoid info leak on export Ben Hutchings
2013-03-25 1:05 ` [ 029/104] isofs: " Ben Hutchings
2013-03-25 1:05 ` [ 030/104] sunsu: Fix panic in case of nonexistent port at "console=ttySY" cmdline option Ben Hutchings
2013-03-25 1:05 ` [ 031/104] net/ipv4: Ensure that location of timestamp option is stored Ben Hutchings
2013-03-25 1:05 ` [ 032/104] netconsole: dont call __netpoll_cleanup() while atomic Ben Hutchings
2013-03-25 1:05 ` [ 033/104] bonding: dont call update_speed_duplex() under spinlocks Ben Hutchings
2013-03-25 1:05 ` [ 034/104] sctp: Use correct sideffect command in duplicate cookie handling Ben Hutchings
2013-03-25 1:05 ` [ 035/104] sctp: dont break the loop while meeting the active_path so as to find the matched transport Ben Hutchings
2013-03-25 1:06 ` [ 036/104] ipv4: fix definition of FIB_TABLE_HASHSZ Ben Hutchings
2013-03-25 1:06 ` [ 037/104] tcp: fix skb_availroom() Ben Hutchings
2013-03-25 1:06 ` [ 038/104] rtnetlink: Mask the rta_type when range checking Ben Hutchings
2013-03-25 1:06 ` Ben Hutchings [this message]
2013-03-25 1:06 ` [ 040/104] sfc: Do not attempt to flush queues if DMA is disabled Ben Hutchings
2013-03-25 1:06 ` [ 041/104] sfc: Convert firmware subtypes to native byte order in efx_mcdi_get_board_cfg() Ben Hutchings
2013-03-25 1:06 ` [ 042/104] sfc: Fix two causes of flush failure Ben Hutchings
2013-03-25 1:06 ` [ 043/104] sfc: lock TX queues when calling netif_device_detach() Ben Hutchings
2013-03-25 1:06 ` [ 044/104] sfc: Fix timekeeping in efx_mcdi_poll() Ben Hutchings
2013-03-25 1:06 ` [ 045/104] sfc: Properly sync RX DMA buffer when it is not the last in the page Ben Hutchings
2013-03-25 1:06 ` [ 046/104] sfc: Fix efx_rx_buf_offset() in the presence of swiotlb Ben Hutchings
2013-03-25 1:06 ` [ 047/104] sfc: Detach net device when stopping queues for reconfiguration Ben Hutchings
2013-03-25 1:06 ` [ 048/104] sfc: Disable soft interrupt handling during efx_device_detach_sync() Ben Hutchings
2013-03-25 1:06 ` [ 049/104] sfc: Only use TX push if a single descriptor is to be written Ben Hutchings
2013-03-25 1:06 ` [ 050/104] ext4: fix the wrong number of the allocated blocks in Ben Hutchings
2013-03-25 1:06 ` [ 051/104] jbd2: fix use after free in jbd2_journal_dirty_metadata() Ben Hutchings
2013-03-25 1:06 ` [ 052/104] ext4: convert number of blocks to clusters properly Ben Hutchings
2013-03-25 1:06 ` [ 053/104] ext4: use atomic64_t for the per-flexbg free_clusters count Ben Hutchings
2013-03-25 1:06 ` [ 054/104] tracing: Fix race in snapshot swapping Ben Hutchings
2013-03-25 1:06 ` [ 055/104] cifs: delay super block destruction until all cifsFileInfo objects Ben Hutchings
2013-03-25 1:06 ` [ 056/104] drm/i915: restrict kernel address leak in debugfs Ben Hutchings
2013-03-25 1:06 ` [ 057/104] drm/i915: bounds check execbuffer relocation count Ben Hutchings
2013-03-25 1:06 ` [ 058/104] tracing: Fix free of probe entry by calling call_rcu_sched() Ben Hutchings
2013-03-25 1:06 ` [ 059/104] tracing: Protect tracer flags with trace_types_lock Ben Hutchings
2013-03-25 1:06 ` [ 060/104] tracing: Keep overwrite in sync between regular and snapshot buffers Ben Hutchings
2013-03-25 1:06 ` [ 061/104] tracing: Prevent buffer overwrite disabled for latency tracers Ben Hutchings
2013-03-25 1:06 ` [ 062/104] USB: xhci: correctly enable interrupts Ben Hutchings
2013-03-25 1:06 ` [ 063/104] usb-storage: add unusual_devs entry for Samsung YP-Z3 mp3 player Ben Hutchings
2013-03-25 1:06 ` [ 064/104] drm/radeon/benchmark: make sure bo blit copy exists before using it Ben Hutchings
2013-03-25 1:06 ` [ 065/104] ALSA: hda/cirrus - Fix the digital beep registration Ben Hutchings
2013-03-25 1:06 ` [ 066/104] USB: xhci - fix bit definitions for IMAN register Ben Hutchings
2013-03-25 1:06 ` [ 067/104] x86-64: Fix the failure case in copy_user_handle_tail() Ben Hutchings
2013-03-25 1:06 ` [ 068/104] ALSA: snd-usb: mixer: propagate errors up the call chain Ben Hutchings
2013-03-25 1:06 ` [ 069/104] ALSA: snd-usb: mixer: ignore -EINVAL in snd_usb_mixer_controls() Ben Hutchings
2013-03-25 1:06 ` [ 070/104] ext4: fix data=journal fast mount/umount hang Ben Hutchings
2013-03-25 1:06 ` [ 071/104] ALSA: hda - Fix typo in checking IEC958 emphasis bit Ben Hutchings
2013-03-25 1:06 ` [ 072/104] usb: gadget: udc-core: fix a regression during gadget driver Ben Hutchings
2013-03-25 1:06 ` [ 073/104] dm thin: fix discard corruption Ben Hutchings
2013-03-25 1:06 ` [ 074/104] efivars: Allow disabling use as a pstore backend Ben Hutchings
2013-03-25 1:06 ` [ 075/104] efivars: Add module parameter to disable " Ben Hutchings
2013-03-25 1:06 ` [ 076/104] efivars: Fix check for CONFIG_EFI_VARS_PSTORE_DEFAULT_DISABLE Ben Hutchings
2013-03-25 1:06 ` [ 077/104] efi_pstore: Introducing workqueue updating sysfs Ben Hutchings
2013-03-25 1:06 ` [ 078/104] efivars: explicitly calculate length of VariableName Ben Hutchings
2013-03-25 1:06 ` [ 079/104] efivars: Handle duplicate names from get_next_variable() Ben Hutchings
2013-03-25 1:06 ` [ 080/104] cifs: ignore everything in SPNEGO blob after mechTypes Ben Hutchings
2013-03-25 1:06 ` [ 081/104] USB: garmin_gps: fix memory leak on disconnect Ben Hutchings
2013-03-25 1:06 ` [ 082/104] USB: io_ti: fix get_icount for two port adapters Ben Hutchings
2013-03-25 1:06 ` [ 083/104] USB: serial: fix interface refcounting Ben Hutchings
2013-03-25 1:06 ` [ 084/104] USB: serial: add modem-status-change wait queue Ben Hutchings
2013-03-26 15:36 ` Johan Hovold
2013-03-27 2:35 ` Ben Hutchings
2013-03-25 1:06 ` [ 085/104] USB: ark3116: fix use-after-free in TIOCMIWAIT Ben Hutchings
2013-03-25 1:06 ` [ 086/104] USB: ch341: " Ben Hutchings
2013-03-25 1:06 ` [ 087/104] USB: cypress_m8: " Ben Hutchings
2013-03-25 1:06 ` [ 088/104] USB: ftdi_sio: " Ben Hutchings
2013-03-25 1:06 ` [ 089/104] USB: io_edgeport: " Ben Hutchings
2013-03-25 1:06 ` [ 090/104] USB: io_ti: " Ben Hutchings
2013-03-25 1:06 ` [ 091/104] USB: mct_u232: " Ben Hutchings
2013-03-25 1:06 ` [ 092/104] USB: mos7840: fix broken TIOCMIWAIT Ben Hutchings
2013-03-25 1:06 ` [ 093/104] USB: mos7840: fix use-after-free in TIOCMIWAIT Ben Hutchings
2013-03-25 1:06 ` [ 094/104] USB: oti6858: " Ben Hutchings
2013-03-25 1:06 ` [ 095/104] USB: pl2303: " Ben Hutchings
2013-03-25 1:07 ` [ 096/104] USB: spcp8x5: " Ben Hutchings
2013-03-25 1:07 ` [ 097/104] USB: ssu100: " Ben Hutchings
2013-03-25 1:07 ` [ 098/104] USB: ti_usb_3410_5052: " Ben Hutchings
2013-03-25 1:07 ` [ 099/104] i2c: tegra: check the clk_prepare_enable() return value Ben Hutchings
2013-03-25 1:07 ` [ 100/104] vfs,proc: guarantee unique inodes in /proc Ben Hutchings
2013-03-25 1:07 ` [ 101/104] mm/hugetlb: fix total hugetlbfs pages count when using memory Ben Hutchings
2013-03-25 1:07 ` [ 102/104] KMS: fix EDID detailed timing vsync parsing Ben Hutchings
2013-03-25 1:07 ` [ 103/104] KMS: fix EDID detailed timing frame rate Ben Hutchings
2013-03-25 1:07 ` [ 104/104] efivars: pstore: Do not check size when erasing variable Ben Hutchings
2013-03-25 2:06 ` [ 000/104] 3.2.42-stable review Ben Hutchings
2013-03-26 13:01 ` Satoru Takeuchi
2013-03-26 19:03 ` Ben Hutchings
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130325010528.150797562@decadent.org.uk \
--to=ben@decadent.org.uk \
--cc=akpm@linux-foundation.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=eric.dumazet@gmail.com \
--cc=hannes@stressinduktion.org \
--cc=jbrouer@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).