mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Slaby <jslaby@suse.cz>
To: stable@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Eric Dumazet <edumazet@google.com>,
	Steffen Klassert <steffen.klassert@secunet.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jiri Slaby <jslaby@suse.cz>
Subject: [PATCH 3.12 39/94] ipv4: irq safe sk_dst_[re]set() and ipv4_sk_update_pmtu() fix
Date: Wed, 30 Jul 2014 14:14:28 +0200	[thread overview]
Message-ID: <8728b0c1932dada25f2d1ccfa1669b5b41fe7937.1406722270.git.jslaby@suse.cz> (raw)
In-Reply-To: <e43bbc2c2b44d8f0bd0b7f65d6fd50ef738c57aa.1406722270.git.jslaby@suse.cz>
In-Reply-To: <cover.1406722269.git.jslaby@suse.cz>

From: Eric Dumazet <edumazet@google.com>

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

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

[ Upstream commit 7f502361531e9eecb396cf99bdc9e9a59f7ebd7f ]

We have two different ways to handle changes to sk->sk_dst

First way (used by TCP) assumes socket lock is owned by caller, and use
no extra lock : __sk_dst_set() & __sk_dst_reset()

Another way (used by UDP) uses sk_dst_lock because socket lock is not
always taken. Note that sk_dst_lock is not softirq safe.

These ways are not inter changeable for a given socket type.

ipv4_sk_update_pmtu(), added in linux-3.8, added a race, as it used
the socket lock as synchronization, but users might be UDP sockets.

Instead of converting sk_dst_lock to a softirq safe version, use xchg()
as we did for sk_rx_dst in commit e47eb5dfb296b ("udp: ipv4: do not use
sk_dst_lock from softirq context")

In a follow up patch, we probably can remove sk_dst_lock, as it is
only used in IPv6.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Steffen Klassert <steffen.klassert@secunet.com>
Fixes: 9cb3a50c5f63e ("ipv4: Invalidate the socket cached route on pmtu events if possible")
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 include/net/sock.h | 12 ++++++------
 net/ipv4/route.c   | 15 ++++++++-------
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/include/net/sock.h b/include/net/sock.h
index dc84ec518ff5..def541a583de 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1789,9 +1789,11 @@ __sk_dst_set(struct sock *sk, struct dst_entry *dst)
 static inline void
 sk_dst_set(struct sock *sk, struct dst_entry *dst)
 {
-	spin_lock(&sk->sk_dst_lock);
-	__sk_dst_set(sk, dst);
-	spin_unlock(&sk->sk_dst_lock);
+	struct dst_entry *old_dst;
+
+	sk_tx_queue_clear(sk);
+	old_dst = xchg(&sk->sk_dst_cache, dst);
+	dst_release(old_dst);
 }
 
 static inline void
@@ -1803,9 +1805,7 @@ __sk_dst_reset(struct sock *sk)
 static inline void
 sk_dst_reset(struct sock *sk)
 {
-	spin_lock(&sk->sk_dst_lock);
-	__sk_dst_reset(sk);
-	spin_unlock(&sk->sk_dst_lock);
+	sk_dst_set(sk, NULL);
 }
 
 extern struct dst_entry *__sk_dst_check(struct sock *sk, u32 cookie);
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 2b681867164d..310963d7c028 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1032,20 +1032,21 @@ void ipv4_sk_update_pmtu(struct sk_buff *skb, struct sock *sk, u32 mtu)
 	const struct iphdr *iph = (const struct iphdr *) skb->data;
 	struct flowi4 fl4;
 	struct rtable *rt;
-	struct dst_entry *dst;
+	struct dst_entry *odst = NULL;
 	bool new = false;
 
 	bh_lock_sock(sk);
-	rt = (struct rtable *) __sk_dst_get(sk);
+	odst = sk_dst_get(sk);
 
-	if (sock_owned_by_user(sk) || !rt) {
+	if (sock_owned_by_user(sk) || !odst) {
 		__ipv4_sk_update_pmtu(skb, sk, mtu);
 		goto out;
 	}
 
 	__build_flow_key(&fl4, sk, iph, 0, 0, 0, 0, 0);
 
-	if (!__sk_dst_check(sk, 0)) {
+	rt = (struct rtable *)odst;
+	if (odst->obsolete && odst->ops->check(odst, 0) == NULL) {
 		rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
 		if (IS_ERR(rt))
 			goto out;
@@ -1055,8 +1056,7 @@ void ipv4_sk_update_pmtu(struct sk_buff *skb, struct sock *sk, u32 mtu)
 
 	__ip_rt_update_pmtu((struct rtable *) rt->dst.path, &fl4, mtu);
 
-	dst = dst_check(&rt->dst, 0);
-	if (!dst) {
+	if (!dst_check(&rt->dst, 0)) {
 		if (new)
 			dst_release(&rt->dst);
 
@@ -1068,10 +1068,11 @@ void ipv4_sk_update_pmtu(struct sk_buff *skb, struct sock *sk, u32 mtu)
 	}
 
 	if (new)
-		__sk_dst_set(sk, &rt->dst);
+		sk_dst_set(sk, &rt->dst);
 
 out:
 	bh_unlock_sock(sk);
+	dst_release(odst);
 }
 EXPORT_SYMBOL_GPL(ipv4_sk_update_pmtu);
 
-- 
2.0.1


  parent reply	other threads:[~2014-07-30 12:34 UTC|newest]

Thread overview: 98+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-30 12:15 [PATCH 3.12 00/94] 3.12.26-stable review Jiri Slaby
2014-07-30 12:13 ` [PATCH 3.12 01/94] Don't trigger congestion wait on dirty-but-not-writeout pages Jiri Slaby
2014-07-30 12:13 ` [PATCH 3.12 02/94] can: c_can: Remove EOB exit Jiri Slaby
2014-07-30 12:13 ` [PATCH 3.12 03/94] serial: sirf: fix spinlock deadlock issue Jiri Slaby
2014-07-30 12:13 ` [PATCH 3.12 04/94] serial: sirf: Fix compilation failure Jiri Slaby
2014-07-30 12:13 ` [PATCH 3.12 05/94] ACPI / resources: only reject zero length resources based at address zero Jiri Slaby
2014-07-30 12:13 ` [PATCH 3.12 06/94] slip: Fix deadlock in write_wakeup Jiri Slaby
2014-07-30 12:13 ` [PATCH 3.12 07/94] shmem: fix faulting into a hole while it's punched Jiri Slaby
2014-07-30 12:13 ` [PATCH 3.12 08/94] shmem: fix faulting into a hole, not taking i_mutex Jiri Slaby
2014-07-30 12:13 ` [PATCH 3.12 09/94] shmem: fix splicing from a hole while it's punched Jiri Slaby
2014-07-30 12:13 ` [PATCH 3.12 10/94] mm: kmemleak: avoid false negatives on vmalloc'ed objects Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 11/94] usb: Check if port status is equal to RxDetect Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 12/94] usb: chipidea: udc: Disable auto ZLP generation on ep0 Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 13/94] media: gspca_pac7302: Add new usb-id for Genius i-Look 317 Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 14/94] ALSA: hda - Fix broken PM due to incomplete i915 initialization Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 15/94] Drivers: hv: util: Fix a bug in the KVP code Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 16/94] Bluetooth: Ignore H5 non-link packets in non-active state Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 17/94] fuse: timeout comparison fix Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 18/94] fuse: handle large user and group ID Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 19/94] fuse: ignore entry-timeout on LOOKUP_REVAL Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 20/94] tracing: Fix graph tracer with stack tracer on other archs Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 21/94] tracing: Add ftrace_trace_stack into __trace_puts/__trace_bputs Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 22/94] tracing: Add TRACE_ITER_PRINTK flag check in __trace_puts/__trace_bputs Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 23/94] hwmon: (da9055) Don't use dash in the name attribute Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 24/94] hwmon: (da9052) " Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 25/94] hwmon: (adt7470) Fix writes to temperature limit registers Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 26/94] igb: Workaround for i210 Errata 25: Slow System Clock Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 27/94] igb: do a reset on SR-IOV re-init if device is down Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 28/94] quota: missing lock in dqcache_shrink_scan() Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 29/94] iwlwifi: dvm: don't enable CTS to self Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 30/94] e1000e: Fix SHRA register access for 82579 Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 31/94] ip_tunnel: fix ip_tunnel_lookup Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 32/94] slcan: Port write_wakeup deadlock fix from slip Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 33/94] net: sctp: propagate sysctl errors from proc_do* properly Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 34/94] tcp: fix tcp_match_skb_to_sack() for unaligned SACK at end of an skb Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 35/94] net: sctp: check proc_dointvec result in proc_sctp_do_auth Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 36/94] 8021q: fix a potential memory leak Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 37/94] net: fix UDP tunnel GSO of frag_list GRO packets Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 38/94] ipv4: fix dst race in sk_dst_get() Jiri Slaby
2014-07-30 12:14 ` Jiri Slaby [this message]
2014-07-30 12:14 ` [PATCH 3.12 40/94] bnx2x: fix possible panic under memory stress Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 41/94] tcp: Fix divide by zero when pushing during tcp-repair Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 42/94] ipv4: icmp: Fix pMTU handling for rare case Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 43/94] net: qmi_wwan: Add ID for Telewell TW-LTE 4G v2 Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 44/94] net: qmi_wwan: add two Sierra Wireless/Netgear devices Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 45/94] net: Fix NETDEV_CHANGE notifier usage causing spurious arp flush Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 46/94] igmp: fix the problem when mc leave group Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 47/94] tcp: fix false undo corner cases Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 48/94] appletalk: Fix socket referencing in skb Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 49/94] net: mvneta: fix operation in 10 Mbit/s mode Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 50/94] netlink: Fix handling of error from netlink_dump() Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 51/94] be2net: set EQ DB clear-intr bit in be_open() Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 52/94] tipc: clear 'next'-pointer of message fragments before reassembly Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 53/94] net: sctp: fix information leaks in ulpevent layer Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 54/94] net: pppoe: use correct channel MTU when using Multilink PPP Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 55/94] sunvnet: clean up objects created in vnet_new() on vnet_exit() Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 56/94] dns_resolver: assure that dns_query() result is null-terminated Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 57/94] ipv4: fix buffer overflow in ip_options_compile() Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 58/94] perf/x86/intel: ignore CondChgd bit to avoid false NMI handling Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 59/94] mwifiex: fix Tx timeout issue Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 60/94] ring-buffer: Fix polling on trace_pipe Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 61/94] irqchip: gic: Add support for cortex a7 compatible string Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 62/94] irqchip: gic: Fix core ID calculation when topology is read from DT Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 63/94] drm/radeon: set default bl level to something reasonable Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 64/94] drm/qxl: return IRQ_NONE if it was not our irq Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 65/94] drm/radeon: avoid leaking edid data Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 66/94] alarmtimer: Fix bug where relative alarm timers were treated as absolute Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 67/94] mtd: devices: elm: fix elm_context_save() and elm_context_restore() functions Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 68/94] dm thin metadata: do not allow the data block size to change Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 69/94] dm cache " Jiri Slaby
2014-07-30 12:14 ` [PATCH 3.12 70/94] PM / sleep: Fix request_firmware() error at resume Jiri Slaby
2014-07-30 12:15 ` [PATCH 3.12 71/94] locking/mutex: Disable optimistic spinning on some architectures Jiri Slaby
2014-07-30 12:15 ` [PATCH 3.12 72/94] sched: Fix possible divide by zero in avg_atom() calculation Jiri Slaby
2014-07-30 12:15 ` [PATCH 3.12 73/94] aio: protect reqs_available updates from changes in interrupt handlers Jiri Slaby
2014-07-30 12:15 ` [PATCH 3.12 74/94] ARM: dts: imx: Add alias for ethernet controller Jiri Slaby
2014-07-30 12:15 ` [PATCH 3.12 75/94] ARC: Implement ptrace(PTRACE_GET_THREAD_AREA) Jiri Slaby
2014-07-30 12:15 ` [PATCH 3.12 76/94] media: media: v4l2-core: v4l2-dv-timings.c: Cleaning up code wrong value used in aspect ratio Jiri Slaby
2014-07-30 12:15 ` [PATCH 3.12 77/94] media: hdpvr: fix two audio bugs Jiri Slaby
2014-07-30 12:15 ` [PATCH 3.12 78/94] media: tda10071: force modulation to QPSK on DVB-S Jiri Slaby
2014-07-30 12:15 ` [PATCH 3.12 79/94] block: provide compat ioctl for BLKZEROOUT Jiri Slaby
2014-07-30 12:15 ` [PATCH 3.12 80/94] block: don't assume last put of shared tags is for the host Jiri Slaby
2014-07-30 12:15 ` [PATCH 3.12 81/94] libata: support the ata host which implements a queue depth less than 32 Jiri Slaby
2014-07-30 14:37   ` Thomas Backlund
2014-07-30 12:15 ` [PATCH 3.12 82/94] ahci: add support for the Promise FastTrak TX8660 SATA HBA (ahci mode) Jiri Slaby
2014-07-30 12:15 ` [PATCH 3.12 83/94] blkcg: don't call into policy draining if root_blkg is already gone Jiri Slaby
2014-07-30 12:15 ` [PATCH 3.12 84/94] tracing: Fix wraparound problems in "uptime" trace clock Jiri Slaby
2014-07-30 12:15 ` [PATCH 3.12 85/94] slab_common: fix the check for duplicate slab names Jiri Slaby
2014-07-30 12:15 ` [PATCH 3.12 86/94] Input: fix defuzzing logic Jiri Slaby
2014-07-30 12:15 ` [PATCH 3.12 87/94] coredump: fix the setting of PF_DUMPCORE Jiri Slaby
2014-07-30 12:15 ` [PATCH 3.12 88/94] parisc: Remove SA_RESTORER define Jiri Slaby
2014-07-30 12:15 ` [PATCH 3.12 89/94] hwmon: (smsc47m192) Fix temperature limit and vrm write operations Jiri Slaby
2014-07-30 12:15 ` [PATCH 3.12 90/94] fs: umount on symlink leaks mnt count Jiri Slaby
2014-07-30 12:15 ` [PATCH 3.12 91/94] x86_32, entry: Store badsys error code in %eax Jiri Slaby
2014-07-30 12:15 ` [PATCH 3.12 92/94] drm/radeon: fix irq ring buffer overflow handling Jiri Slaby
2014-07-30 12:15 ` [PATCH 3.12 93/94] Fix gcc-4.9.0 miscompilation of load_balance() in scheduler Jiri Slaby
2014-07-30 12:15 ` [PATCH 3.12 94/94] x86/efi: Include a .bss section within the PE/COFF headers Jiri Slaby
2014-07-30 19:22 ` [PATCH 3.12 00/94] 3.12.26-stable review Guenter Roeck
2014-07-30 22:42   ` Satoru Takeuchi

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=8728b0c1932dada25f2d1ccfa1669b5b41fe7937.1406722270.git.jslaby@suse.cz \
    --to=jslaby@suse.cz \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=steffen.klassert@secunet.com \
    /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

all inboxes | Powered by JetHome®