All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Slaby <jslaby@suse.cz>
To: stable@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
	"David S. Miller" <davem@davemloft.net>,
	Jiri Slaby <jslaby@suse.cz>
Subject: [PATCH 3.12 03/98] ipv4: Don't do expensive useless work during inetdev destroy.
Date: Mon, 11 Apr 2016 15:22:05 +0200	[thread overview]
Message-ID: <5cc4ff312ac06ee4c49801f5b288c1118c3e5785.1460380917.git.jslaby@suse.cz> (raw)
In-Reply-To: <def91dea48a3acb14c2379b9461ae659d95616a2.1460380917.git.jslaby@suse.cz>
In-Reply-To: <cover.1460380917.git.jslaby@suse.cz>

From: "David S. Miller" <davem@davemloft.net>

3.12-stable review patch.  If anyone has any objections, please let me know.

===============

commit fbd40ea0180a2d328c5adc61414dc8bab9335ce2 upstream.

When an inetdev is destroyed, every address assigned to the interface
is removed.  And in this scenerio we do two pointless things which can
be very expensive if the number of assigned interfaces is large:

1) Address promotion.  We are deleting all addresses, so there is no
   point in doing this.

2) A full nf conntrack table purge for every address.  We only need to
   do this once, as is already caught by the existing
   masq_dev_notifier so masq_inet_event() can skip this.

[mk] 3.12.*: The change in masq_inet_event() needs to be duplicated in
both IPv4 and IPv6 version of the function, these two were merged in
3.18.

Reported-by: Solar Designer <solar@openwall.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Tested-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Michal Kubecek <mkubecek@suse.cz>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 net/ipv4/devinet.c                   |  4 ++++
 net/ipv4/fib_frontend.c              |  4 ++++
 net/ipv4/netfilter/ipt_MASQUERADE.c  | 12 ++++++++++--
 net/ipv6/netfilter/ip6t_MASQUERADE.c | 12 ++++++++++--
 4 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 68447109000f..6678bebb82c8 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -328,6 +328,9 @@ static void __inet_del_ifa(struct in_device *in_dev, struct in_ifaddr **ifap,
 
 	ASSERT_RTNL();
 
+	if (in_dev->dead)
+		goto no_promotions;
+
 	/* 1. Deleting primary ifaddr forces deletion all secondaries
 	 * unless alias promotion is set
 	 **/
@@ -374,6 +377,7 @@ static void __inet_del_ifa(struct in_device *in_dev, struct in_ifaddr **ifap,
 			fib_del_ifaddr(ifa, ifa1);
 	}
 
+no_promotions:
 	/* 2. Unlink it */
 
 	*ifap = ifa1->ifa_next;
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index f7f8cff67344..25a0946f7074 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -812,6 +812,9 @@ void fib_del_ifaddr(struct in_ifaddr *ifa, struct in_ifaddr *iprim)
 		subnet = 1;
 	}
 
+	if (in_dev->dead)
+		goto no_promotions;
+
 	/* Deletion is more complicated than add.
 	 * We should take care of not to delete too much :-)
 	 *
@@ -887,6 +890,7 @@ void fib_del_ifaddr(struct in_ifaddr *ifa, struct in_ifaddr *iprim)
 		}
 	}
 
+no_promotions:
 	if (!(ok & BRD_OK))
 		fib_magic(RTM_DELROUTE, RTN_BROADCAST, ifa->ifa_broadcast, 32, prim);
 	if (subnet && ifa->ifa_prefixlen < 31) {
diff --git a/net/ipv4/netfilter/ipt_MASQUERADE.c b/net/ipv4/netfilter/ipt_MASQUERADE.c
index 00352ce0f0de..3bc1c98aa2f0 100644
--- a/net/ipv4/netfilter/ipt_MASQUERADE.c
+++ b/net/ipv4/netfilter/ipt_MASQUERADE.c
@@ -128,10 +128,18 @@ static int masq_inet_event(struct notifier_block *this,
 			   unsigned long event,
 			   void *ptr)
 {
-	struct net_device *dev = ((struct in_ifaddr *)ptr)->ifa_dev->dev;
+	struct in_device *idev = ((struct in_ifaddr *)ptr)->ifa_dev;
 	struct netdev_notifier_info info;
 
-	netdev_notifier_info_init(&info, dev);
+	/* The masq_dev_notifier will catch the case of the device going
+	 * down.  So if the inetdev is dead and being destroyed we have
+	 * no work to do.  Otherwise this is an individual address removal
+	 * and we have to perform the flush.
+	 */
+	if (idev->dead)
+		return NOTIFY_DONE;
+
+	netdev_notifier_info_init(&info, idev->dev);
 	return masq_device_event(this, event, &info);
 }
 
diff --git a/net/ipv6/netfilter/ip6t_MASQUERADE.c b/net/ipv6/netfilter/ip6t_MASQUERADE.c
index 3e4e92d5e157..bee09e9050c3 100644
--- a/net/ipv6/netfilter/ip6t_MASQUERADE.c
+++ b/net/ipv6/netfilter/ip6t_MASQUERADE.c
@@ -88,10 +88,18 @@ static struct notifier_block masq_dev_notifier = {
 static int masq_inet_event(struct notifier_block *this,
 			   unsigned long event, void *ptr)
 {
-	struct inet6_ifaddr *ifa = ptr;
+	struct inet6_dev *idev = ((struct inet6_ifaddr *)ptr)->idev;
 	struct netdev_notifier_info info;
 
-	netdev_notifier_info_init(&info, ifa->idev->dev);
+	/* The masq_dev_notifier will catch the case of the device going
+	 * down.  So if the inetdev is dead and being destroyed we have
+	 * no work to do.  Otherwise this is an individual address removal
+	 * and we have to perform the flush.
+	 */
+	if (idev->dead)
+		return NOTIFY_DONE;
+
+	netdev_notifier_info_init(&info, idev->dev);
 	return masq_device_event(this, event, &info);
 }
 
-- 
2.8.1

  parent reply	other threads:[~2016-04-11 14:06 UTC|newest]

Thread overview: 103+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-11 13:23 [PATCH 3.12 00/98] 3.12.58-stable review Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 01/98] ipr: Fix out-of-bounds null overwrite Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 02/98] ipr: Fix regression when loading firmware Jiri Slaby
2016-04-11 13:22 ` Jiri Slaby [this message]
2016-04-11 13:22 ` [PATCH 3.12 04/98] umount: Do not allow unmounting rootfs Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 05/98] kernel: Provide READ_ONCE and ASSIGN_ONCE Jiri Slaby
2016-04-11 14:13   ` Christian Borntraeger
2016-04-11 13:22 ` [PATCH 3.12 06/98] xen: Add RING_COPY_REQUEST() Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 07/98] xen-netback: don't use last request to determine minimum Tx credit Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 08/98] xen-netback: use RING_COPY_REQUEST() throughout Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 09/98] xen-blkback: only read request operation from shared ring once Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 10/98] xen-blkback: read from indirect descriptors only once Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 11/98] xen/pciback: Save xen_pci_op commands before processing it Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 12/98] xen/pciback: Save the number of MSI-X entries to be copied later Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 13/98] xfs: allow inode allocations in post-growfs disk space Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 14/98] sched: Fix race between task_group and sched_task_group Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 15/98] Btrfs: skip locking when searching commit root Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 16/98] bnx2x: Add new device ids under the Qlogic vendor Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 17/98] drivers/base/memory.c: fix kernel warning during memory hotplug on ppc64 Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 18/98] ALSA: rawmidi: Make snd_rawmidi_transmit() race-free Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 19/98] ALSA: seq: Fix leak of pool buffer at concurrent writes Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 20/98] memcg: do not hang on OOM when killed by userspace OOM access to memory reserves Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 21/98] USB: fix invalid memory access in hub_activate() Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 22/98] intel_pstate: Use del_timer_sync in intel_pstate_cpu_stop Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 23/98] KVM: SVM: add rdmsr support for AMD event registers Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 24/98] USB: visor: fix null-deref at probe Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 25/98] s390/mm: four page table levels vs. fork Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 26/98] hwmon: (coretemp) Increase limit of maximum core ID from 32 to 128 Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 27/98] perf, nmi: Fix unknown NMI warning Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 28/98] Fix kmalloc overflow in LPFC driver at large core count Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 29/98] nfs: fix high load average due to callback thread sleeping Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 30/98] net/ipv6: fix DEVCONF_ constants Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 31/98] ipv6: mld: fix add_grhead skb_over_panic for devs with large MTUs Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 32/98] mld, igmp: Fix reserved tailroom calculation Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 33/98] ahci: Add Device ID for Intel Sunrise Point PCH Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 34/98] x86/iopl/64: Properly context-switch IOPL on Xen PV Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 35/98] KVM: i8254: change PIT discard tick policy Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 36/98] KVM: fix spin_lock_init order on x86 Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 37/98] KVM: VMX: avoid guest hang on invalid invept instruction Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 38/98] EDAC, amd64_edac: Shift wrapping issue in f1x_get_norm_dct_addr() Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 39/98] PCI: Disable IO/MEM decoding for devices with non-compliant BARs Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 40/98] x86/apic: Fix suspicious RCU usage in smp_trace_call_function_interrupt() Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 41/98] x86/iopl: Fix iopl capability check on Xen PV Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 42/98] sg: fix dxferp in from_to case Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 43/98] aacraid: Fix memory leak in aac_fib_map_free Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 44/98] be2iscsi: set the boot_kset pointer to NULL in case of failure Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 45/98] usb: retry reset if a device times out Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 46/98] usb: hub: fix a typo in hub_port_init() leading to wrong logic Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 47/98] USB: cdc-acm: more sanity checking Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 48/98] USB: iowarrior: fix oops with malicious USB descriptors Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 49/98] USB: usb_driver_claim_interface: add sanity checking Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 50/98] USB: mct_u232: add sanity checking in probe Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 51/98] USB: digi_acceleport: do sanity checking for the number of ports Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 52/98] USB: cypress_m8: add endpoint sanity check Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 53/98] USB: serial: cp210x: Adding GE Healthcare Device ID Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 54/98] USB: serial: ftdi_sio: Add support for ICP DAS I-756xU devices Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 55/98] USB: option: add "D-Link DWM-221 B1" device id Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 56/98] pwc: Add USB id for Philips Spc880nc webcam Jiri Slaby
2016-04-11 13:22 ` [PATCH 3.12 57/98] Input: powermate - fix oops with malicious USB descriptors Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 58/98] ALSA: usb-audio: Fix NULL dereference in create_fixed_stream_quirk() Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 59/98] ALSA: usb-audio: Add sanity checks for endpoint accesses Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 60/98] ALSA: usb-audio: Minor code cleanup in create_fixed_stream_quirk() Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 61/98] ALSA: usb-audio: Fix double-free in error paths after snd_usb_add_audio_stream() call Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 62/98] Bluetooth: btusb: Add new AR3012 ID 13d3:3395 Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 63/98] Bluetooth: btusb: Add a new AR3012 ID 04ca:3014 Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 64/98] Bluetooth: btusb: Add a new AR3012 ID 13d3:3472 Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 65/98] net: irda: Fix use-after-free in irtty_open() Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 66/98] 8250: use callbacks to access UART_DLL/UART_DLM Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 67/98] saa7134: Fix bytesperline not being set correctly for planar formats Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 68/98] adv7511: TX_EDID_PRESENT is still 1 after a disconnect Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 69/98] bttv: Width must be a multiple of 16 when capturing planar formats Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 70/98] media: v4l2-compat-ioctl32: fix missing length copy in put_v4l2_buffer32 Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 71/98] ALSA: intel8x0: Add clock quirk entry for AD1981B on IBM ThinkPad X41 Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 72/98] ALSA: hda - Fix unconditional GPIO toggle via automute Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 73/98] jbd2: fix FS corruption possibility in jbd2_journal_destroy() on umount path Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 74/98] bcache: fix cache_set_flush() NULL pointer dereference on OOM Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 75/98] watchdog: rc32434_wdt: fix ioctl error handling Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 76/98] Bluetooth: Add new AR3012 ID 0489:e095 Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 77/98] splice: handle zero nr_pages in splice_to_pipe() Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 78/98] xtensa: ISS: don't hang if stdin EOF is reached Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 79/98] xtensa: clear all DBREAKC registers on start Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 80/98] xfs: fix two memory leaks in xfs_attr_list.c error paths Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 81/98] md/raid5: Compare apples to apples (or sectors to sectors) Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 82/98] fs/coredump: prevent fsuid=0 dumps into user-controlled directories Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 83/98] rapidio/rionet: fix deadlock on SMP Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 84/98] drm/radeon: Don't drop DP 2.7 Ghz link setup on some cards Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 85/98] tracing: Have preempt(irqs)off trace preempt disabled functions Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 86/98] tracing: Fix crash from reading trace_pipe with sendfile Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 87/98] tracing: Fix trace_printk() to print when not using bprintk() Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 88/98] scripts/coccinelle: modernize & Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 89/98] kbuild/mkspec: fix grub2 installkernel issue Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 90/98] target: Fix target_release_cmd_kref shutdown comp leak Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 91/98] Input: ims-pcu - sanity check against missing interfaces Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 92/98] Input: ati_remote2 - fix crashes on detecting device with invalid descriptor Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 93/98] ocfs2/dlm: fix race between convert and recovery Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 94/98] ocfs2/dlm: fix BUG in dlm_move_lockres_to_recovery_list Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 95/98] mtd: onenand: fix deadlock in onenand_block_markbad Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 96/98] sched/cputime: Fix steal time accounting vs. CPU hotplug Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 97/98] perf/x86/intel: Use PAGE_SIZE for PEBS buffer size on Core2 Jiri Slaby
2016-04-11 13:23 ` [PATCH 3.12 98/98] perf/x86/intel: Fix PEBS data source interpretation on Nehalem/Westmere Jiri Slaby
2016-04-11 13:37 ` [PATCH 3.12 00/98] 3.12.58-stable review Guenter Roeck
2016-04-14  8:24   ` Jiri Slaby
2016-04-11 17:28 ` shuahkh

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=5cc4ff312ac06ee4c49801f5b288c1118c3e5785.1460380917.git.jslaby@suse.cz \
    --to=jslaby@suse.cz \
    --cc=davem@davemloft.net \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.