Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1688374

[PATCH 3.16 123/178] l2tp: take reference on sessions being dumped

From Ben Hutchings <ben@decadent.org.uk>
Newsgroups linux.kernel
Subject [PATCH 3.16 123/178] l2tp: take reference on sessions being dumped
Date 2017-07-16 16:40 +0200
Message-ID <u3SSh-fg-67@gated-at.bofh.it> (permalink)
References <u3Sfv-89R-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


3.16.46-rc1 review patch.  If anyone has any objections, please let me know.

------------------

From: Guillaume Nault <g.nault@alphalink.fr>

commit e08293a4ccbcc993ded0fdc46f1e57926b833d63 upstream.

Take a reference on the sessions returned by l2tp_session_find_nth()
(and rename it l2tp_session_get_nth() to reflect this change), so that
caller is assured that the session isn't going to disappear while
processing it.

For procfs and debugfs handlers, the session is held in the .start()
callback and dropped in .show(). Given that pppol2tp_seq_session_show()
dereferences the associated PPPoL2TP socket and that
l2tp_dfs_seq_session_show() might call pppol2tp_show(), we also need to
call the session's .ref() callback to prevent the socket from going
away from under us.

Fixes: fd558d186df2 ("l2tp: Split pppol2tp patch into separate l2tp and ppp parts")
Fixes: 0ad6614048cf ("l2tp: Add debugfs files for dumping l2tp debug info")
Fixes: 309795f4bec2 ("l2tp: Add netlink control API for L2TP")
Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
Signed-off-by: David S. Miller <davem@davemloft.net>
[bwh: Backported to 3.16: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 net/l2tp/l2tp_core.c    |  8 ++++++--
 net/l2tp/l2tp_core.h    |  3 ++-
 net/l2tp/l2tp_debugfs.c | 10 +++++++---
 net/l2tp/l2tp_netlink.c |  7 +++++--
 net/l2tp/l2tp_ppp.c     | 10 +++++++---
 5 files changed, 27 insertions(+), 11 deletions(-)

--- a/net/l2tp/l2tp_core.c
+++ b/net/l2tp/l2tp_core.c
@@ -326,7 +326,8 @@ struct l2tp_session *l2tp_session_get(st
 }
 EXPORT_SYMBOL_GPL(l2tp_session_get);
 
-struct l2tp_session *l2tp_session_find_nth(struct l2tp_tunnel *tunnel, int nth)
+struct l2tp_session *l2tp_session_get_nth(struct l2tp_tunnel *tunnel, int nth,
+					  bool do_ref)
 {
 	int hash;
 	struct l2tp_session *session;
@@ -336,6 +337,9 @@ struct l2tp_session *l2tp_session_find_n
 	for (hash = 0; hash < L2TP_HASH_SIZE; hash++) {
 		hlist_for_each_entry(session, &tunnel->session_hlist[hash], hlist) {
 			if (++count > nth) {
+				l2tp_session_inc_refcount(session);
+				if (do_ref && session->ref)
+					session->ref(session);
 				read_unlock_bh(&tunnel->hlist_lock);
 				return session;
 			}
@@ -346,7 +350,7 @@ struct l2tp_session *l2tp_session_find_n
 
 	return NULL;
 }
-EXPORT_SYMBOL_GPL(l2tp_session_find_nth);
+EXPORT_SYMBOL_GPL(l2tp_session_get_nth);
 
 /* Lookup a session by interface name.
  * This is very inefficient but is only used by management interfaces.
--- a/net/l2tp/l2tp_core.h
+++ b/net/l2tp/l2tp_core.h
@@ -246,7 +246,8 @@ struct l2tp_session *l2tp_session_get(st
 struct l2tp_session *l2tp_session_find(struct net *net,
 				       struct l2tp_tunnel *tunnel,
 				       u32 session_id);
-struct l2tp_session *l2tp_session_find_nth(struct l2tp_tunnel *tunnel, int nth);
+struct l2tp_session *l2tp_session_get_nth(struct l2tp_tunnel *tunnel, int nth,
+					  bool do_ref);
 struct l2tp_session *l2tp_session_get_by_ifname(struct net *net, char *ifname,
 						bool do_ref);
 struct l2tp_tunnel *l2tp_tunnel_find(struct net *net, u32 tunnel_id);
--- a/net/l2tp/l2tp_debugfs.c
+++ b/net/l2tp/l2tp_debugfs.c
@@ -53,7 +53,7 @@ static void l2tp_dfs_next_tunnel(struct
 
 static void l2tp_dfs_next_session(struct l2tp_dfs_seq_data *pd)
 {
-	pd->session = l2tp_session_find_nth(pd->tunnel, pd->session_idx);
+	pd->session = l2tp_session_get_nth(pd->tunnel, pd->session_idx, true);
 	pd->session_idx++;
 
 	if (pd->session == NULL) {
@@ -238,10 +238,14 @@ static int l2tp_dfs_seq_show(struct seq_
 	}
 
 	/* Show the tunnel or session context */
-	if (pd->session == NULL)
+	if (!pd->session) {
 		l2tp_dfs_seq_tunnel_show(m, pd->tunnel);
-	else
+	} else {
 		l2tp_dfs_seq_session_show(m, pd->session);
+		if (pd->session->deref)
+			pd->session->deref(pd->session);
+		l2tp_session_dec_refcount(pd->session);
+	}
 
 out:
 	return 0;
--- a/net/l2tp/l2tp_netlink.c
+++ b/net/l2tp/l2tp_netlink.c
@@ -740,7 +740,7 @@ static int l2tp_nl_cmd_session_dump(stru
 				goto out;
 		}
 
-		session = l2tp_session_find_nth(tunnel, si);
+		session = l2tp_session_get_nth(tunnel, si, false);
 		if (session == NULL) {
 			ti++;
 			tunnel = NULL;
@@ -750,8 +750,11 @@ static int l2tp_nl_cmd_session_dump(stru
 
 		if (l2tp_nl_session_send(skb, NETLINK_CB(cb->skb).portid,
 					 cb->nlh->nlmsg_seq, NLM_F_MULTI,
-					 session) <= 0)
+					 session) <= 0) {
+			l2tp_session_dec_refcount(session);
 			break;
+		}
+		l2tp_session_dec_refcount(session);
 
 		si++;
 	}
--- a/net/l2tp/l2tp_ppp.c
+++ b/net/l2tp/l2tp_ppp.c
@@ -1579,7 +1579,7 @@ static void pppol2tp_next_tunnel(struct
 
 static void pppol2tp_next_session(struct net *net, struct pppol2tp_seq_data *pd)
 {
-	pd->session = l2tp_session_find_nth(pd->tunnel, pd->session_idx);
+	pd->session = l2tp_session_get_nth(pd->tunnel, pd->session_idx, true);
 	pd->session_idx++;
 
 	if (pd->session == NULL) {
@@ -1706,10 +1706,14 @@ static int pppol2tp_seq_show(struct seq_
 
 	/* Show the tunnel or session context.
 	 */
-	if (pd->session == NULL)
+	if (!pd->session) {
 		pppol2tp_seq_tunnel_show(m, pd->tunnel);
-	else
+	} else {
 		pppol2tp_seq_session_show(m, pd->session);
+		if (pd->session->deref)
+			pd->session->deref(pd->session);
+		l2tp_session_dec_refcount(pd->session);
+	}
 
 out:
 	return 0;

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 3.16 000/178] 3.16.46-rc1 review Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:40 +0200
  [PATCH 3.16 077/178] s390/decompressor: fix initrd corruption  caused by bss clear Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:40 +0200
  [PATCH 3.16 132/178] metag/usercopy: Set flags before ADDZ Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:40 +0200
  [PATCH 3.16 024/178] [media] dvb-usb-firmware: don't do DMA on stack Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:40 +0200
  [PATCH 3.16 144/178] x86/vdso: Ensure vdso32_enabled gets set to  valid values only Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:40 +0200
  [PATCH 3.16 168/178] macvlan: Fix device ref leak when purging  bc_queue Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:40 +0200
  [PATCH 3.16 048/178] futex: Add missing error handling to  FUTEX_REQUEUE_PI Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:40 +0200
  [PATCH 3.16 123/178] l2tp: take reference on sessions being dumped Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:40 +0200
  [PATCH 3.16 056/178] Input: iforce - validate number of endpoints  before using them Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:40 +0200
  [PATCH 3.16 073/178] net: unix: properly re-increment inflight  counter of GC discarded candidates Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:40 +0200
  Re: [PATCH 3.16 000/178] 3.16.46-rc1 review Guenter Roeck <linux@roeck-us.net> - 2017-07-16 16:40 +0200
    Re: [PATCH 3.16 000/178] 3.16.46-rc1 review Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 18:40 +0200
  [PATCH 3.16 007/178] batman-adv: Keep fragments equally sized Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:40 +0200
  [PATCH 3.16 107/178] drm/vmwgfx: Remove getparam error message Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:40 +0200
  [PATCH 3.16 072/178] ALSA: seq: Fix racy cell insertions during  snd_seq_pool_done() Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:40 +0200
  [PATCH 3.16 055/178] mmc: ushc: fix NULL-deref at probe Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:40 +0200
  [PATCH 3.16 136/178] Reset TreeId to zero on SMB2 TREE_CONNECT Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:40 +0200
  [PATCH 3.16 175/178] char: lp: fix possible integer overflow in  lp_setup() Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:40 +0200
  [PATCH 3.16 044/178] usb-core: Add LINEAR_FRAME_INTR_BINTERVAL  USB quirk Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:50 +0200
  [PATCH 3.16 070/178] ALSA: ctxfi: Fix the incorrect check of  dma_set_mask() call Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:50 +0200
  [PATCH 3.16 087/178] ALSA: seq: Fix race during FIFO resize Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:50 +0200
  [PATCH 3.16 086/178] hwmon: (asus_atk0110) fix uninitialized data  access Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:50 +0200
  [PATCH 3.16 066/178] usb: hub: Fix crash after failure to read  BOS descriptor Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:50 +0200
  [PATCH 3.16 166/178] net: ipv6: send unsolicited NA if enabled  for all interfaces Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:50 +0200
  [PATCH 3.16 006/178] tracing: Add #undef to fix compile error Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:50 +0200
  [PATCH 3.16 004/178] kprobes/x86: Fix kernel panic when certain  exception-handling addresses are probed Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:50 +0200
  [PATCH 3.16 170/178] ipv6: move stub initialization after ipv6  setup completion Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:50 +0200
  [PATCH 3.16 025/178] USB: iowarrior: fix NULL-deref in write Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:50 +0200
  [PATCH 3.16 150/178] cpupower: Fix turbo frequency reporting for  pre-Sandy Bridge cores Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:50 +0200
  [PATCH 3.16 176/178] fs/exec.c: account for argv/envp pointers Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:50 +0200
  [PATCH 3.16 127/178] ring-buffer: Fix return value check in  test_ringbuffer() Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:50 +0200
  [PATCH 3.16 015/178] Input: i8042 - add noloop quirk for Dell  Embedded Box PC 3000 Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:50 +0200
  [PATCH 3.16 167/178] Input: i8042 - add Clevo P650RS to the i8042  reset list Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:50 +0200
  [PATCH 3.16 050/178] iio: adc: ti_am335x_adc: fix fifo overrun  recovery Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:50 +0200
  [PATCH 3.16 049/178] ext4: mark inode dirty after converting  inline directory Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:50 +0200
  [PATCH 3.16 116/178] include/linux/kernel.h: change abs() macro  so it uses consistent return type Ben Hutchings <ben@decadent.org.uk> - 2017-07-16 16:50 +0200

csiph-web