<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/net/l2tp/l2tp_core.c, branch linux-5.18.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-5.18.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-5.18.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2021-11-29T12:11:25Z</updated>
<entry>
<title>net/l2tp: convert tunnel rwlock_t to rcu</title>
<updated>2021-11-29T12:11:25Z</updated>
<author>
<name>Tom Parkin</name>
</author>
<published>2021-11-26T16:09:03Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=07b8ca3792dec6bc3288b08ff85d80b5330de1d6'/>
<id>urn:sha1:07b8ca3792dec6bc3288b08ff85d80b5330de1d6</id>
<content type='text'>
Previously commit e02d494d2c60 ("l2tp: Convert rwlock to RCU") converted
most, but not all, rwlock instances in the l2tp subsystem to RCU.

The remaining rwlock protects the per-tunnel hashlist of sessions which
is used for session lookups in the UDP-encap data path.

Convert the remaining rwlock to rcu to improve performance of UDP-encap
tunnels.

Note that the tunnel and session, which both live on RCU-protected
lists, use slightly different approaches to incrementing their refcounts
in the various getter functions.

The tunnel has to use refcount_inc_not_zero because the tunnel shutdown
process involves dropping the refcount to zero prior to synchronizing
RCU readers (via. kfree_rcu).

By contrast, the session shutdown removes the session from the list(s)
it is on, synchronizes with readers, and then decrements the session
refcount.  Since the getter functions increment the session refcount
with the RCU read lock held we prevent getters seeing a zero session
refcount, and therefore don't need to use refcount_inc_not_zero.

Signed-off-by: Tom Parkin &lt;tparkin@katalix.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>net/l2tp: Fix reference count leak in l2tp_udp_recv_core</title>
<updated>2021-09-09T10:00:20Z</updated>
<author>
<name>Xiyu Yang</name>
</author>
<published>2021-09-09T04:32:00Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=9b6ff7eb666415e1558f1ba8a742f5db6a9954de'/>
<id>urn:sha1:9b6ff7eb666415e1558f1ba8a742f5db6a9954de</id>
<content type='text'>
The reference count leak issue may take place in an error handling
path. If both conditions of tunnel-&gt;version == L2TP_HDR_VER_3 and the
return value of l2tp_v3_ensure_opt_in_linear is nonzero, the function
would directly jump to label invalid, without decrementing the reference
count of the l2tp_session object session increased earlier by
l2tp_tunnel_get_session(). This may result in refcount leaks.

Fix this issue by decrease the reference count before jumping to the
label invalid.

Fixes: 4522a70db7aa ("l2tp: fix reading optional fields of L2TPv3")
Signed-off-by: Xiyu Yang &lt;xiyuyang19@fudan.edu.cn&gt;
Signed-off-by: Xin Xiong &lt;xiongx18@fudan.edu.cn&gt;
Signed-off-by: Xin Tan &lt;tanxin.ctf@gmail.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>net: fix a concurrency bug in l2tp_tunnel_register()</title>
<updated>2021-04-27T21:23:13Z</updated>
<author>
<name>Gong, Sishuai</name>
</author>
<published>2021-04-27T15:04:24Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=69e16d01d1de4f1249869de342915f608feb55d5'/>
<id>urn:sha1:69e16d01d1de4f1249869de342915f608feb55d5</id>
<content type='text'>
l2tp_tunnel_register() registers a tunnel without fully
initializing its attribute. This can allow another kernel thread
running l2tp_xmit_core() to access the uninitialized data and
then cause a kernel NULL pointer dereference error, as shown below.

Thread 1    Thread 2
//l2tp_tunnel_register()
list_add_rcu(&amp;tunnel-&gt;list, &amp;pn-&gt;l2tp_tunnel_list);
           //pppol2tp_connect()
           tunnel = l2tp_tunnel_get(sock_net(sk), info.tunnel_id);
           // Fetch the new tunnel
           ...
           //l2tp_xmit_core()
           struct sock *sk = tunnel-&gt;sock;
           ...
           bh_lock_sock(sk);
           //Null pointer error happens
tunnel-&gt;sock = sk;

Fix this bug by initializing tunnel-&gt;sock before adding the
tunnel into l2tp_tunnel_list.

Reviewed-by: Cong Wang &lt;cong.wang@bytedance.com&gt;
Signed-off-by: Sishuai Gong &lt;sishuai@purdue.edu&gt;
Reported-by: Sishuai Gong &lt;sishuai@purdue.edu&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>net: l2tp: Fix a typo</title>
<updated>2021-03-22T20:17:49Z</updated>
<author>
<name>Bhaskar Chowdhury</name>
</author>
<published>2021-03-22T12:21:55Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=aa785f93fcb4e8c66f5d3de88cd7626774f13c1d'/>
<id>urn:sha1:aa785f93fcb4e8c66f5d3de88cd7626774f13c1d</id>
<content type='text'>
s/verifed/verified/

Signed-off-by: Bhaskar Chowdhury &lt;unixbhaskar@gmail.com&gt;
Acked-by: Randy Dunlap &lt;rdunlap@infradead.org&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>net: l2tp: reduce log level of messages in receive path, add counter instead</title>
<updated>2021-03-04T00:55:02Z</updated>
<author>
<name>Matthias Schiffer</name>
</author>
<published>2021-03-03T15:50:49Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=3e59e8856758eb5a2dfe1f831ef53b168fd58105'/>
<id>urn:sha1:3e59e8856758eb5a2dfe1f831ef53b168fd58105</id>
<content type='text'>
Commit 5ee759cda51b ("l2tp: use standard API for warning log messages")
changed a number of warnings about invalid packets in the receive path
so that they are always shown, instead of only when a special L2TP debug
flag is set. Even with rate limiting these warnings can easily cause
significant log spam - potentially triggered by a malicious party
sending invalid packets on purpose.

In addition these warnings were noticed by projects like Tunneldigger [1],
which uses L2TP for its data path, but implements its own control
protocol (which is sufficiently different from L2TP data packets that it
would always be passed up to userspace even with future extensions of
L2TP).

Some of the warnings were already redundant, as l2tp_stats has a counter
for these packets. This commit adds one additional counter for invalid
packets that are passed up to userspace. Packets with unknown session are
not counted as invalid, as there is nothing wrong with the format of
these packets.

With the additional counter, all of these messages are either redundant
or benign, so we reduce them to pr_debug_ratelimited().

[1] https://github.com/wlanslovenija/tunneldigger/issues/160

Fixes: 5ee759cda51b ("l2tp: use standard API for warning log messages")
Signed-off-by: Matthias Schiffer &lt;mschiffer@universe-factory.net&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>l2tp: fix up inconsistent rx/tx statistics</title>
<updated>2020-09-18T21:36:54Z</updated>
<author>
<name>Tom Parkin</name>
</author>
<published>2020-09-18T10:23:21Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=f52e4b27d1ac837caa84973262f7057578f6e316'/>
<id>urn:sha1:f52e4b27d1ac837caa84973262f7057578f6e316</id>
<content type='text'>
Historically L2TP core statistics count the L2TP header in the
per-session and per-tunnel byte counts tracked for transmission and
receipt.

Now that l2tp_xmit_skb updates tx stats, it is necessary for
l2tp_xmit_core to pass out the length of the transmitted packet so that
the statistics can be updated correctly.

Signed-off-by: Tom Parkin &lt;tparkin@katalix.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>l2tp: avoid duplicated code in l2tp_tunnel_closeall</title>
<updated>2020-09-03T19:19:03Z</updated>
<author>
<name>Tom Parkin</name>
</author>
<published>2020-09-03T08:54:52Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=9d319a8e9309d6c2862e2f6721acb5b421af949e'/>
<id>urn:sha1:9d319a8e9309d6c2862e2f6721acb5b421af949e</id>
<content type='text'>
l2tp_tunnel_closeall is called as a part of tunnel shutdown in order to
close all the sessions held by the tunnel.  The code it uses to close a
session duplicates what l2tp_session_delete does.

Rather than duplicating the code, have l2tp_tunnel_closeall call
l2tp_session_delete instead.

This involves a very minor change to locking in l2tp_tunnel_closeall.
Previously, l2tp_tunnel_closeall checked the session "dead" flag while
holding tunnel-&gt;hlist_lock.  This allowed for the code to step to the
next session in the list without releasing the lock if the current
session happened to be in the process of closing already.

By calling l2tp_session_delete instead, l2tp_tunnel_closeall must now
drop and regain the hlist lock for each session in the tunnel list.
Given that the likelihood of a session being in the process of closing
when the tunnel is closed, it seems worth this very minor potential
loss of efficiency to avoid duplication of the session delete code.

Signed-off-by: Tom Parkin &lt;tparkin@katalix.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>l2tp: make magic feather checks more useful</title>
<updated>2020-09-03T19:19:03Z</updated>
<author>
<name>Tom Parkin</name>
</author>
<published>2020-09-03T08:54:51Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=45faeff11b48b9390ee946668119472b8941de90'/>
<id>urn:sha1:45faeff11b48b9390ee946668119472b8941de90</id>
<content type='text'>
The l2tp tunnel and session structures contain a "magic feather" field
which was originally intended to help trace lifetime bugs in the code.

Since the introduction of the shared kernel refcount code in refcount.h,
and l2tp's porting to those APIs, we are covered by the refcount code's
checks and warnings.  Duplicating those checks in the l2tp code isn't
useful.

However, magic feather checks are still useful to help to detect bugs
stemming from misuse/trampling of the sk_user_data pointer in struct
sock.  The l2tp code makes extensive use of sk_user_data to stash
pointers to the tunnel and session structures, and if another subsystem
overwrites sk_user_data it's important to detect this.

As such, rework l2tp's magic feather checks to focus on validating the
tunnel and session data structures when they're extracted from
sk_user_data.

 * Add a new accessor function l2tp_sk_to_tunnel which contains a magic
   feather check, and is used by l2tp_core and l2tp_ip[6]
 * Comment l2tp_udp_encap_recv which doesn't use this new accessor function
   because of the specific nature of the codepath it is called in
 * Drop l2tp_session_queue_purge's check on the session magic feather:
   it is called from code which is walking the tunnel session list, and
   hence doesn't need validation
 * Drop l2tp_session_free's check on the tunnel magic feather: the
   intention of this check is covered by refcount.h's reference count
   sanity checking
 * Add session magic validation in pppol2tp_ioctl.  On failure return
   -EBADF, which mirrors the approach in pppol2tp_[sg]etsockopt.

Signed-off-by: Tom Parkin &lt;tparkin@katalix.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>l2tp: capture more tx errors in data plane stats</title>
<updated>2020-09-03T19:19:03Z</updated>
<author>
<name>Tom Parkin</name>
</author>
<published>2020-09-03T08:54:50Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=de68b039e970c1e55850818fb1bcd49f52dc02e8'/>
<id>urn:sha1:de68b039e970c1e55850818fb1bcd49f52dc02e8</id>
<content type='text'>
l2tp_xmit_skb has a number of failure paths which are not reflected in
the tunnel and session statistics because the stats are updated by
l2tp_xmit_core.  Hence any errors occurring before l2tp_xmit_core is
called are missed from the statistics.

Refactor the transmit path slightly to capture all error paths.

l2tp_xmit_skb now leaves all the actual work of transmission to
l2tp_xmit_core, and updates the statistics based on l2tp_xmit_core's
return code.

Signed-off-by: Tom Parkin &lt;tparkin@katalix.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>l2tp: drop net argument from l2tp_tunnel_create</title>
<updated>2020-09-03T19:19:03Z</updated>
<author>
<name>Tom Parkin</name>
</author>
<published>2020-09-03T08:54:49Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=c9ccd4c63c40fa03a9d5850c4a8847192b640524'/>
<id>urn:sha1:c9ccd4c63c40fa03a9d5850c4a8847192b640524</id>
<content type='text'>
The argument is unused, so remove it.

Signed-off-by: Tom Parkin &lt;tparkin@katalix.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
</feed>
