2019-05-27 14:55:01 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright (C) Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
|
|
|
|
* Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
|
|
|
|
* Copyright (C) Darryl Miles G7LED (dlm@g7led.demon.co.uk)
|
|
|
|
* Copyright (C) Steven Whitehouse GW7RRM (stevew@acm.org)
|
|
|
|
* Copyright (C) Joerg Reuter DL1BKE (jreuter@yaina.de)
|
|
|
|
* Copyright (C) Hans-Joachim Hetscher DD8NE (dd8ne@bnv-bamberg.de)
|
|
|
|
* Copyright (C) Hans Alblas PE1AYX (hans@esrac.ele.tue.nl)
|
|
|
|
* Copyright (C) Frederic Rible F1OAT (frible@teaser.fr)
|
|
|
|
*/
|
2006-01-12 04:17:47 +08:00
|
|
|
#include <linux/capability.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/socket.h>
|
|
|
|
#include <linux/in.h>
|
|
|
|
#include <linux/kernel.h>
|
2017-02-09 01:51:30 +08:00
|
|
|
#include <linux/sched/signal.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/sockios.h>
|
|
|
|
#include <linux/net.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <net/ax25.h>
|
|
|
|
#include <linux/inet.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/if_arp.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <net/sock.h>
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/fcntl.h>
|
|
|
|
#include <linux/termios.h> /* For TIOCINQ/OUTQ */
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/notifier.h>
|
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include <linux/stat.h>
|
|
|
|
#include <linux/sysctl.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/spinlock.h>
|
2007-09-12 18:01:34 +08:00
|
|
|
#include <net/net_namespace.h>
|
2005-08-10 11:08:28 +08:00
|
|
|
#include <net/tcp_states.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <net/ip.h>
|
|
|
|
#include <net/arp.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HLIST_HEAD(ax25_list);
|
|
|
|
DEFINE_SPINLOCK(ax25_list_lock);
|
|
|
|
|
2005-12-23 04:49:22 +08:00
|
|
|
static const struct proto_ops ax25_proto_ops;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static void ax25_free_sock(struct sock *sk)
|
|
|
|
{
|
2015-06-25 21:19:07 +08:00
|
|
|
ax25_cb_put(sk_to_ax25(sk));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Socket removal during an interrupt is now safe.
|
|
|
|
*/
|
|
|
|
static void ax25_cb_del(ax25_cb *ax25)
|
|
|
|
{
|
ax25: Fix ax25 session cleanup problems
There are session cleanup problems in ax25_release() and
ax25_disconnect(). If we setup a session and then disconnect,
the disconnected session is still in "LISTENING" state that
is shown below.
Active AX.25 sockets
Dest Source Device State Vr/Vs Send-Q Recv-Q
DL9SAU-4 DL9SAU-3 ??? LISTENING 000/000 0 0
DL9SAU-3 DL9SAU-4 ??? LISTENING 000/000 0 0
The first reason is caused by del_timer_sync() in ax25_release().
The timers of ax25 are used for correct session cleanup. If we use
ax25_release() to close ax25 sessions and ax25_dev is not null,
the del_timer_sync() functions in ax25_release() will execute.
As a result, the sessions could not be cleaned up correctly,
because the timers have stopped.
In order to solve this problem, this patch adds a device_up flag
in ax25_dev in order to judge whether the device is up. If there
are sessions to be cleaned up, the del_timer_sync() in
ax25_release() will not execute. What's more, we add ax25_cb_del()
in ax25_kill_by_device(), because the timers have been stopped
and there are no functions that could delete ax25_cb if we do not
call ax25_release(). Finally, we reorder the position of
ax25_list_lock in ax25_cb_del() in order to synchronize among
different functions that call ax25_cb_del().
The second reason is caused by improper check in ax25_disconnect().
The incoming ax25 sessions which ax25->sk is null will close
heartbeat timer, because the check "if(!ax25->sk || ..)" is
satisfied. As a result, the session could not be cleaned up properly.
In order to solve this problem, this patch changes the improper
check to "if(ax25->sk && ..)" in ax25_disconnect().
What`s more, the ax25_disconnect() may be called twice, which is
not necessary. For example, ax25_kill_by_device() calls
ax25_disconnect() and sets ax25->state to AX25_STATE_0, but
ax25_release() calls ax25_disconnect() again.
In order to solve this problem, this patch add a check in
ax25_release(). If the flag of ax25->sk equals to SOCK_DEAD,
the ax25_disconnect() in ax25_release() should not be executed.
Fixes: 82e31755e55f ("ax25: Fix UAF bugs in ax25 timers")
Fixes: 8a367e74c012 ("ax25: Fix segfault after sock connection timeout")
Reported-and-tested-by: Thomas Osterried <thomas@osterried.de>
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Link: https://lore.kernel.org/r/20220530152158.108619-1-duoming@zju.edu.cn
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2022-05-30 23:21:58 +08:00
|
|
|
spin_lock_bh(&ax25_list_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!hlist_unhashed(&ax25->ax25_node)) {
|
|
|
|
hlist_del_init(&ax25->ax25_node);
|
|
|
|
ax25_cb_put(ax25);
|
|
|
|
}
|
ax25: Fix ax25 session cleanup problems
There are session cleanup problems in ax25_release() and
ax25_disconnect(). If we setup a session and then disconnect,
the disconnected session is still in "LISTENING" state that
is shown below.
Active AX.25 sockets
Dest Source Device State Vr/Vs Send-Q Recv-Q
DL9SAU-4 DL9SAU-3 ??? LISTENING 000/000 0 0
DL9SAU-3 DL9SAU-4 ??? LISTENING 000/000 0 0
The first reason is caused by del_timer_sync() in ax25_release().
The timers of ax25 are used for correct session cleanup. If we use
ax25_release() to close ax25 sessions and ax25_dev is not null,
the del_timer_sync() functions in ax25_release() will execute.
As a result, the sessions could not be cleaned up correctly,
because the timers have stopped.
In order to solve this problem, this patch adds a device_up flag
in ax25_dev in order to judge whether the device is up. If there
are sessions to be cleaned up, the del_timer_sync() in
ax25_release() will not execute. What's more, we add ax25_cb_del()
in ax25_kill_by_device(), because the timers have been stopped
and there are no functions that could delete ax25_cb if we do not
call ax25_release(). Finally, we reorder the position of
ax25_list_lock in ax25_cb_del() in order to synchronize among
different functions that call ax25_cb_del().
The second reason is caused by improper check in ax25_disconnect().
The incoming ax25 sessions which ax25->sk is null will close
heartbeat timer, because the check "if(!ax25->sk || ..)" is
satisfied. As a result, the session could not be cleaned up properly.
In order to solve this problem, this patch changes the improper
check to "if(ax25->sk && ..)" in ax25_disconnect().
What`s more, the ax25_disconnect() may be called twice, which is
not necessary. For example, ax25_kill_by_device() calls
ax25_disconnect() and sets ax25->state to AX25_STATE_0, but
ax25_release() calls ax25_disconnect() again.
In order to solve this problem, this patch add a check in
ax25_release(). If the flag of ax25->sk equals to SOCK_DEAD,
the ax25_disconnect() in ax25_release() should not be executed.
Fixes: 82e31755e55f ("ax25: Fix UAF bugs in ax25 timers")
Fixes: 8a367e74c012 ("ax25: Fix segfault after sock connection timeout")
Reported-and-tested-by: Thomas Osterried <thomas@osterried.de>
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Link: https://lore.kernel.org/r/20220530152158.108619-1-duoming@zju.edu.cn
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2022-05-30 23:21:58 +08:00
|
|
|
spin_unlock_bh(&ax25_list_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Kill all bound sockets on a dropped device.
|
|
|
|
*/
|
|
|
|
static void ax25_kill_by_device(struct net_device *dev)
|
|
|
|
{
|
|
|
|
ax25_dev *ax25_dev;
|
|
|
|
ax25_cb *s;
|
2022-01-28 12:47:15 +08:00
|
|
|
struct sock *sk;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if ((ax25_dev = ax25_dev_ax25dev(dev)) == NULL)
|
|
|
|
return;
|
ax25: Fix ax25 session cleanup problems
There are session cleanup problems in ax25_release() and
ax25_disconnect(). If we setup a session and then disconnect,
the disconnected session is still in "LISTENING" state that
is shown below.
Active AX.25 sockets
Dest Source Device State Vr/Vs Send-Q Recv-Q
DL9SAU-4 DL9SAU-3 ??? LISTENING 000/000 0 0
DL9SAU-3 DL9SAU-4 ??? LISTENING 000/000 0 0
The first reason is caused by del_timer_sync() in ax25_release().
The timers of ax25 are used for correct session cleanup. If we use
ax25_release() to close ax25 sessions and ax25_dev is not null,
the del_timer_sync() functions in ax25_release() will execute.
As a result, the sessions could not be cleaned up correctly,
because the timers have stopped.
In order to solve this problem, this patch adds a device_up flag
in ax25_dev in order to judge whether the device is up. If there
are sessions to be cleaned up, the del_timer_sync() in
ax25_release() will not execute. What's more, we add ax25_cb_del()
in ax25_kill_by_device(), because the timers have been stopped
and there are no functions that could delete ax25_cb if we do not
call ax25_release(). Finally, we reorder the position of
ax25_list_lock in ax25_cb_del() in order to synchronize among
different functions that call ax25_cb_del().
The second reason is caused by improper check in ax25_disconnect().
The incoming ax25 sessions which ax25->sk is null will close
heartbeat timer, because the check "if(!ax25->sk || ..)" is
satisfied. As a result, the session could not be cleaned up properly.
In order to solve this problem, this patch changes the improper
check to "if(ax25->sk && ..)" in ax25_disconnect().
What`s more, the ax25_disconnect() may be called twice, which is
not necessary. For example, ax25_kill_by_device() calls
ax25_disconnect() and sets ax25->state to AX25_STATE_0, but
ax25_release() calls ax25_disconnect() again.
In order to solve this problem, this patch add a check in
ax25_release(). If the flag of ax25->sk equals to SOCK_DEAD,
the ax25_disconnect() in ax25_release() should not be executed.
Fixes: 82e31755e55f ("ax25: Fix UAF bugs in ax25 timers")
Fixes: 8a367e74c012 ("ax25: Fix segfault after sock connection timeout")
Reported-and-tested-by: Thomas Osterried <thomas@osterried.de>
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Link: https://lore.kernel.org/r/20220530152158.108619-1-duoming@zju.edu.cn
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2022-05-30 23:21:58 +08:00
|
|
|
ax25_dev->device_up = false;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_lock_bh(&ax25_list_lock);
|
2008-01-11 13:21:20 +08:00
|
|
|
again:
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 09:06:00 +08:00
|
|
|
ax25_for_each(s, &ax25_list) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (s->ax25_dev == ax25_dev) {
|
2022-01-28 12:47:15 +08:00
|
|
|
sk = s->sk;
|
2022-03-08 16:12:23 +08:00
|
|
|
if (!sk) {
|
|
|
|
spin_unlock_bh(&ax25_list_lock);
|
|
|
|
ax25_disconnect(s, ENETUNREACH);
|
2022-03-18 08:54:05 +08:00
|
|
|
s->ax25_dev = NULL;
|
ax25: Fix ax25 session cleanup problems
There are session cleanup problems in ax25_release() and
ax25_disconnect(). If we setup a session and then disconnect,
the disconnected session is still in "LISTENING" state that
is shown below.
Active AX.25 sockets
Dest Source Device State Vr/Vs Send-Q Recv-Q
DL9SAU-4 DL9SAU-3 ??? LISTENING 000/000 0 0
DL9SAU-3 DL9SAU-4 ??? LISTENING 000/000 0 0
The first reason is caused by del_timer_sync() in ax25_release().
The timers of ax25 are used for correct session cleanup. If we use
ax25_release() to close ax25 sessions and ax25_dev is not null,
the del_timer_sync() functions in ax25_release() will execute.
As a result, the sessions could not be cleaned up correctly,
because the timers have stopped.
In order to solve this problem, this patch adds a device_up flag
in ax25_dev in order to judge whether the device is up. If there
are sessions to be cleaned up, the del_timer_sync() in
ax25_release() will not execute. What's more, we add ax25_cb_del()
in ax25_kill_by_device(), because the timers have been stopped
and there are no functions that could delete ax25_cb if we do not
call ax25_release(). Finally, we reorder the position of
ax25_list_lock in ax25_cb_del() in order to synchronize among
different functions that call ax25_cb_del().
The second reason is caused by improper check in ax25_disconnect().
The incoming ax25 sessions which ax25->sk is null will close
heartbeat timer, because the check "if(!ax25->sk || ..)" is
satisfied. As a result, the session could not be cleaned up properly.
In order to solve this problem, this patch changes the improper
check to "if(ax25->sk && ..)" in ax25_disconnect().
What`s more, the ax25_disconnect() may be called twice, which is
not necessary. For example, ax25_kill_by_device() calls
ax25_disconnect() and sets ax25->state to AX25_STATE_0, but
ax25_release() calls ax25_disconnect() again.
In order to solve this problem, this patch add a check in
ax25_release(). If the flag of ax25->sk equals to SOCK_DEAD,
the ax25_disconnect() in ax25_release() should not be executed.
Fixes: 82e31755e55f ("ax25: Fix UAF bugs in ax25 timers")
Fixes: 8a367e74c012 ("ax25: Fix segfault after sock connection timeout")
Reported-and-tested-by: Thomas Osterried <thomas@osterried.de>
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Link: https://lore.kernel.org/r/20220530152158.108619-1-duoming@zju.edu.cn
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2022-05-30 23:21:58 +08:00
|
|
|
ax25_cb_del(s);
|
2022-03-08 16:12:23 +08:00
|
|
|
spin_lock_bh(&ax25_list_lock);
|
|
|
|
goto again;
|
|
|
|
}
|
2022-01-28 12:47:15 +08:00
|
|
|
sock_hold(sk);
|
2008-01-11 13:21:20 +08:00
|
|
|
spin_unlock_bh(&ax25_list_lock);
|
2022-01-28 12:47:15 +08:00
|
|
|
lock_sock(sk);
|
2022-03-18 08:54:05 +08:00
|
|
|
ax25_disconnect(s, ENETUNREACH);
|
2021-12-17 10:29:41 +08:00
|
|
|
s->ax25_dev = NULL;
|
2022-03-18 08:54:04 +08:00
|
|
|
if (sk->sk_socket) {
|
2022-06-08 12:39:55 +08:00
|
|
|
netdev_put(ax25_dev->dev,
|
|
|
|
&ax25_dev->dev_tracker);
|
2022-03-18 08:54:04 +08:00
|
|
|
ax25_dev_put(ax25_dev);
|
|
|
|
}
|
ax25: Fix ax25 session cleanup problems
There are session cleanup problems in ax25_release() and
ax25_disconnect(). If we setup a session and then disconnect,
the disconnected session is still in "LISTENING" state that
is shown below.
Active AX.25 sockets
Dest Source Device State Vr/Vs Send-Q Recv-Q
DL9SAU-4 DL9SAU-3 ??? LISTENING 000/000 0 0
DL9SAU-3 DL9SAU-4 ??? LISTENING 000/000 0 0
The first reason is caused by del_timer_sync() in ax25_release().
The timers of ax25 are used for correct session cleanup. If we use
ax25_release() to close ax25 sessions and ax25_dev is not null,
the del_timer_sync() functions in ax25_release() will execute.
As a result, the sessions could not be cleaned up correctly,
because the timers have stopped.
In order to solve this problem, this patch adds a device_up flag
in ax25_dev in order to judge whether the device is up. If there
are sessions to be cleaned up, the del_timer_sync() in
ax25_release() will not execute. What's more, we add ax25_cb_del()
in ax25_kill_by_device(), because the timers have been stopped
and there are no functions that could delete ax25_cb if we do not
call ax25_release(). Finally, we reorder the position of
ax25_list_lock in ax25_cb_del() in order to synchronize among
different functions that call ax25_cb_del().
The second reason is caused by improper check in ax25_disconnect().
The incoming ax25 sessions which ax25->sk is null will close
heartbeat timer, because the check "if(!ax25->sk || ..)" is
satisfied. As a result, the session could not be cleaned up properly.
In order to solve this problem, this patch changes the improper
check to "if(ax25->sk && ..)" in ax25_disconnect().
What`s more, the ax25_disconnect() may be called twice, which is
not necessary. For example, ax25_kill_by_device() calls
ax25_disconnect() and sets ax25->state to AX25_STATE_0, but
ax25_release() calls ax25_disconnect() again.
In order to solve this problem, this patch add a check in
ax25_release(). If the flag of ax25->sk equals to SOCK_DEAD,
the ax25_disconnect() in ax25_release() should not be executed.
Fixes: 82e31755e55f ("ax25: Fix UAF bugs in ax25 timers")
Fixes: 8a367e74c012 ("ax25: Fix segfault after sock connection timeout")
Reported-and-tested-by: Thomas Osterried <thomas@osterried.de>
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Link: https://lore.kernel.org/r/20220530152158.108619-1-duoming@zju.edu.cn
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2022-05-30 23:21:58 +08:00
|
|
|
ax25_cb_del(s);
|
2022-02-08 23:40:00 +08:00
|
|
|
release_sock(sk);
|
2008-01-11 13:21:20 +08:00
|
|
|
spin_lock_bh(&ax25_list_lock);
|
2022-01-28 12:47:15 +08:00
|
|
|
sock_put(sk);
|
2008-01-11 13:21:20 +08:00
|
|
|
/* The entry could have been deleted from the
|
|
|
|
* list meanwhile and thus the next pointer is
|
|
|
|
* no longer valid. Play it safe and restart
|
|
|
|
* the scan. Forward progress is ensured
|
|
|
|
* because we set s->ax25_dev to NULL and we
|
|
|
|
* are never passed a NULL 'dev' argument.
|
|
|
|
*/
|
|
|
|
goto again;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock_bh(&ax25_list_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle device status changes.
|
|
|
|
*/
|
|
|
|
static int ax25_device_event(struct notifier_block *this, unsigned long event,
|
2013-05-28 09:30:21 +08:00
|
|
|
void *ptr)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2013-05-28 09:30:21 +08:00
|
|
|
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-07-20 13:34:43 +08:00
|
|
|
if (!net_eq(dev_net(dev), &init_net))
|
2007-09-12 19:02:17 +08:00
|
|
|
return NOTIFY_DONE;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Reject non AX.25 devices */
|
|
|
|
if (dev->type != ARPHRD_AX25)
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case NETDEV_UP:
|
|
|
|
ax25_dev_device_up(dev);
|
|
|
|
break;
|
|
|
|
case NETDEV_DOWN:
|
|
|
|
ax25_kill_by_device(dev);
|
|
|
|
ax25_rt_device_down(dev);
|
|
|
|
ax25_dev_device_down(dev);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a socket to the bound sockets list.
|
|
|
|
*/
|
|
|
|
void ax25_cb_add(ax25_cb *ax25)
|
|
|
|
{
|
|
|
|
spin_lock_bh(&ax25_list_lock);
|
|
|
|
ax25_cb_hold(ax25);
|
|
|
|
hlist_add_head(&ax25->ax25_node, &ax25_list);
|
|
|
|
spin_unlock_bh(&ax25_list_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find a socket that wants to accept the SABM we have just
|
|
|
|
* received.
|
|
|
|
*/
|
|
|
|
struct sock *ax25_find_listener(ax25_address *addr, int digi,
|
|
|
|
struct net_device *dev, int type)
|
|
|
|
{
|
|
|
|
ax25_cb *s;
|
|
|
|
|
2006-07-13 04:25:23 +08:00
|
|
|
spin_lock(&ax25_list_lock);
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 09:06:00 +08:00
|
|
|
ax25_for_each(s, &ax25_list) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if ((s->iamdigi && !digi) || (!s->iamdigi && digi))
|
|
|
|
continue;
|
|
|
|
if (s->sk && !ax25cmp(&s->source_addr, addr) &&
|
|
|
|
s->sk->sk_type == type && s->sk->sk_state == TCP_LISTEN) {
|
|
|
|
/* If device is null we match any device */
|
|
|
|
if (s->ax25_dev == NULL || s->ax25_dev->dev == dev) {
|
|
|
|
sock_hold(s->sk);
|
2006-07-13 04:25:23 +08:00
|
|
|
spin_unlock(&ax25_list_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
return s->sk;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-07-13 04:25:23 +08:00
|
|
|
spin_unlock(&ax25_list_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find an AX.25 socket given both ends.
|
|
|
|
*/
|
|
|
|
struct sock *ax25_get_socket(ax25_address *my_addr, ax25_address *dest_addr,
|
|
|
|
int type)
|
|
|
|
{
|
|
|
|
struct sock *sk = NULL;
|
|
|
|
ax25_cb *s;
|
|
|
|
|
2006-07-13 04:25:23 +08:00
|
|
|
spin_lock(&ax25_list_lock);
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 09:06:00 +08:00
|
|
|
ax25_for_each(s, &ax25_list) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (s->sk && !ax25cmp(&s->source_addr, my_addr) &&
|
|
|
|
!ax25cmp(&s->dest_addr, dest_addr) &&
|
|
|
|
s->sk->sk_type == type) {
|
|
|
|
sk = s->sk;
|
|
|
|
sock_hold(sk);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-13 04:25:23 +08:00
|
|
|
spin_unlock(&ax25_list_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return sk;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find an AX.25 control block given both ends. It will only pick up
|
|
|
|
* floating AX.25 control blocks or non Raw socket bound control blocks.
|
|
|
|
*/
|
2021-10-12 23:58:35 +08:00
|
|
|
ax25_cb *ax25_find_cb(const ax25_address *src_addr, ax25_address *dest_addr,
|
2005-04-17 06:20:36 +08:00
|
|
|
ax25_digi *digi, struct net_device *dev)
|
|
|
|
{
|
|
|
|
ax25_cb *s;
|
|
|
|
|
|
|
|
spin_lock_bh(&ax25_list_lock);
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 09:06:00 +08:00
|
|
|
ax25_for_each(s, &ax25_list) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (s->sk && s->sk->sk_type != SOCK_SEQPACKET)
|
|
|
|
continue;
|
|
|
|
if (s->ax25_dev == NULL)
|
|
|
|
continue;
|
|
|
|
if (ax25cmp(&s->source_addr, src_addr) == 0 && ax25cmp(&s->dest_addr, dest_addr) == 0 && s->ax25_dev->dev == dev) {
|
|
|
|
if (digi != NULL && digi->ndigi != 0) {
|
|
|
|
if (s->digipeat == NULL)
|
|
|
|
continue;
|
|
|
|
if (ax25digicmp(s->digipeat, digi) != 0)
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
if (s->digipeat != NULL && s->digipeat->ndigi != 0)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ax25_cb_hold(s);
|
|
|
|
spin_unlock_bh(&ax25_list_lock);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock_bh(&ax25_list_lock);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-05-04 14:25:17 +08:00
|
|
|
EXPORT_SYMBOL(ax25_find_cb);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
void ax25_send_to_raw(ax25_address *addr, struct sk_buff *skb, int proto)
|
|
|
|
{
|
|
|
|
ax25_cb *s;
|
|
|
|
struct sk_buff *copy;
|
|
|
|
|
2006-07-13 04:25:23 +08:00
|
|
|
spin_lock(&ax25_list_lock);
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 09:06:00 +08:00
|
|
|
ax25_for_each(s, &ax25_list) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (s->sk != NULL && ax25cmp(&s->source_addr, addr) == 0 &&
|
|
|
|
s->sk->sk_type == SOCK_RAW &&
|
|
|
|
s->sk->sk_protocol == proto &&
|
|
|
|
s->ax25_dev->dev == skb->dev &&
|
|
|
|
atomic_read(&s->sk->sk_rmem_alloc) <= s->sk->sk_rcvbuf) {
|
|
|
|
if ((copy = skb_clone(skb, GFP_ATOMIC)) == NULL)
|
|
|
|
continue;
|
|
|
|
if (sock_queue_rcv_skb(s->sk, copy) != 0)
|
|
|
|
kfree_skb(copy);
|
|
|
|
}
|
|
|
|
}
|
2006-07-13 04:25:23 +08:00
|
|
|
spin_unlock(&ax25_list_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Deferred destroy.
|
|
|
|
*/
|
|
|
|
void ax25_destroy_socket(ax25_cb *);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handler for deferred kills.
|
|
|
|
*/
|
2017-10-24 16:45:39 +08:00
|
|
|
static void ax25_destroy_timer(struct timer_list *t)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2017-10-24 16:45:39 +08:00
|
|
|
ax25_cb *ax25 = from_timer(ax25, t, dtimer);
|
2005-04-17 06:20:36 +08:00
|
|
|
struct sock *sk;
|
2007-02-09 22:24:31 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
sk=ax25->sk;
|
2007-02-09 22:24:31 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
bh_lock_sock(sk);
|
|
|
|
sock_hold(sk);
|
|
|
|
ax25_destroy_socket(ax25);
|
|
|
|
bh_unlock_sock(sk);
|
|
|
|
sock_put(sk);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is called from user mode and the timers. Thus it protects itself
|
|
|
|
* against interrupt users but doesn't worry about being called during
|
|
|
|
* work. Once it is removed from the queue no interrupt or bottom half
|
|
|
|
* will touch it and we are (fairly 8-) ) safe.
|
|
|
|
*/
|
|
|
|
void ax25_destroy_socket(ax25_cb *ax25)
|
|
|
|
{
|
|
|
|
struct sk_buff *skb;
|
|
|
|
|
|
|
|
ax25_cb_del(ax25);
|
|
|
|
|
|
|
|
ax25_stop_heartbeat(ax25);
|
|
|
|
ax25_stop_t1timer(ax25);
|
|
|
|
ax25_stop_t2timer(ax25);
|
|
|
|
ax25_stop_t3timer(ax25);
|
|
|
|
ax25_stop_idletimer(ax25);
|
|
|
|
|
|
|
|
ax25_clear_queues(ax25); /* Flush the queues */
|
|
|
|
|
|
|
|
if (ax25->sk != NULL) {
|
|
|
|
while ((skb = skb_dequeue(&ax25->sk->sk_receive_queue)) != NULL) {
|
|
|
|
if (skb->sk != ax25->sk) {
|
|
|
|
/* A pending connection */
|
2015-06-25 21:19:07 +08:00
|
|
|
ax25_cb *sax25 = sk_to_ax25(skb->sk);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Queue the unaccepted socket for death */
|
|
|
|
sock_orphan(skb->sk);
|
|
|
|
|
2008-10-07 03:53:50 +08:00
|
|
|
/* 9A4GL: hack to release unaccepted sockets */
|
|
|
|
skb->sk->sk_state = TCP_LISTEN;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
ax25_start_heartbeat(sax25);
|
|
|
|
sax25->state = AX25_STATE_0;
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree_skb(skb);
|
|
|
|
}
|
|
|
|
skb_queue_purge(&ax25->sk->sk_write_queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ax25->sk != NULL) {
|
2009-06-16 18:12:03 +08:00
|
|
|
if (sk_has_allocations(ax25->sk)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Defer: outstanding buffers */
|
2017-10-24 16:45:39 +08:00
|
|
|
timer_setup(&ax25->dtimer, ax25_destroy_timer, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
ax25->dtimer.expires = jiffies + 2 * HZ;
|
|
|
|
add_timer(&ax25->dtimer);
|
|
|
|
} else {
|
|
|
|
struct sock *sk=ax25->sk;
|
|
|
|
ax25->sk=NULL;
|
|
|
|
sock_put(sk);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ax25_cb_put(ax25);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dl1bke 960311: set parameters for existing AX.25 connections,
|
|
|
|
* includes a KILL command to abort any connection.
|
|
|
|
* VERY useful for debugging ;-)
|
|
|
|
*/
|
|
|
|
static int ax25_ctl_ioctl(const unsigned int cmd, void __user *arg)
|
|
|
|
{
|
|
|
|
struct ax25_ctl_struct ax25_ctl;
|
|
|
|
ax25_digi digi;
|
|
|
|
ax25_dev *ax25_dev;
|
|
|
|
ax25_cb *ax25;
|
|
|
|
unsigned int k;
|
2009-09-25 11:10:38 +08:00
|
|
|
int ret = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (copy_from_user(&ax25_ctl, arg, sizeof(ax25_ctl)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
if (ax25_ctl.digi_count > AX25_MAX_DIGIS)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2009-10-14 13:26:30 +08:00
|
|
|
if (ax25_ctl.arg > ULONG_MAX / HZ && ax25_ctl.cmd != AX25_KILL)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2022-02-03 23:08:11 +08:00
|
|
|
ax25_dev = ax25_addr_ax25dev(&ax25_ctl.port_addr);
|
|
|
|
if (!ax25_dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
digi.ndigi = ax25_ctl.digi_count;
|
|
|
|
for (k = 0; k < digi.ndigi; k++)
|
|
|
|
digi.calls[k] = ax25_ctl.digi_addr[k];
|
|
|
|
|
2022-02-03 23:08:11 +08:00
|
|
|
ax25 = ax25_find_cb(&ax25_ctl.source_addr, &ax25_ctl.dest_addr, &digi, ax25_dev->dev);
|
|
|
|
if (!ax25) {
|
|
|
|
ax25_dev_put(ax25_dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENOTCONN;
|
2022-02-03 23:08:11 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
switch (ax25_ctl.cmd) {
|
|
|
|
case AX25_KILL:
|
|
|
|
ax25_send_control(ax25, AX25_DISC, AX25_POLLON, AX25_COMMAND);
|
|
|
|
#ifdef CONFIG_AX25_DAMA_SLAVE
|
|
|
|
if (ax25_dev->dama.slave && ax25->ax25_dev->values[AX25_VALUES_PROTOCOL] == AX25_PROTO_DAMA_SLAVE)
|
|
|
|
ax25_dama_off(ax25);
|
|
|
|
#endif
|
|
|
|
ax25_disconnect(ax25, ENETRESET);
|
|
|
|
break;
|
|
|
|
|
2007-02-09 22:24:31 +08:00
|
|
|
case AX25_WINDOW:
|
|
|
|
if (ax25->modulus == AX25_MODULUS) {
|
|
|
|
if (ax25_ctl.arg < 1 || ax25_ctl.arg > 7)
|
2009-09-25 11:10:38 +08:00
|
|
|
goto einval_put;
|
2007-02-09 22:24:31 +08:00
|
|
|
} else {
|
|
|
|
if (ax25_ctl.arg < 1 || ax25_ctl.arg > 63)
|
2009-09-25 11:10:38 +08:00
|
|
|
goto einval_put;
|
2007-02-09 22:24:31 +08:00
|
|
|
}
|
|
|
|
ax25->window = ax25_ctl.arg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_T1:
|
2011-11-24 14:12:59 +08:00
|
|
|
if (ax25_ctl.arg < 1 || ax25_ctl.arg > ULONG_MAX / HZ)
|
2009-09-25 11:10:38 +08:00
|
|
|
goto einval_put;
|
2007-02-09 22:24:31 +08:00
|
|
|
ax25->rtt = (ax25_ctl.arg * HZ) / 2;
|
|
|
|
ax25->t1 = ax25_ctl.arg * HZ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_T2:
|
2011-11-24 14:12:59 +08:00
|
|
|
if (ax25_ctl.arg < 1 || ax25_ctl.arg > ULONG_MAX / HZ)
|
2009-09-25 11:10:38 +08:00
|
|
|
goto einval_put;
|
2007-02-09 22:24:31 +08:00
|
|
|
ax25->t2 = ax25_ctl.arg * HZ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_N2:
|
|
|
|
if (ax25_ctl.arg < 1 || ax25_ctl.arg > 31)
|
2009-09-25 11:10:38 +08:00
|
|
|
goto einval_put;
|
2007-02-09 22:24:31 +08:00
|
|
|
ax25->n2count = 0;
|
|
|
|
ax25->n2 = ax25_ctl.arg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_T3:
|
2011-11-24 14:12:59 +08:00
|
|
|
if (ax25_ctl.arg > ULONG_MAX / HZ)
|
|
|
|
goto einval_put;
|
2007-02-09 22:24:31 +08:00
|
|
|
ax25->t3 = ax25_ctl.arg * HZ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_IDLE:
|
2011-11-24 14:12:59 +08:00
|
|
|
if (ax25_ctl.arg > ULONG_MAX / (60 * HZ))
|
|
|
|
goto einval_put;
|
|
|
|
|
2007-02-09 22:24:31 +08:00
|
|
|
ax25->idle = ax25_ctl.arg * 60 * HZ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_PACLEN:
|
|
|
|
if (ax25_ctl.arg < 16 || ax25_ctl.arg > 65535)
|
2009-09-25 11:10:38 +08:00
|
|
|
goto einval_put;
|
2007-02-09 22:24:31 +08:00
|
|
|
ax25->paclen = ax25_ctl.arg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-09-25 11:10:38 +08:00
|
|
|
goto einval_put;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-09-25 11:10:38 +08:00
|
|
|
out_put:
|
ax25: add refcount in ax25_dev to avoid UAF bugs
If we dereference ax25_dev after we call kfree(ax25_dev) in
ax25_dev_device_down(), it will lead to concurrency UAF bugs.
There are eight syscall functions suffer from UAF bugs, include
ax25_bind(), ax25_release(), ax25_connect(), ax25_ioctl(),
ax25_getname(), ax25_sendmsg(), ax25_getsockopt() and
ax25_info_show().
One of the concurrency UAF can be shown as below:
(USE) | (FREE)
| ax25_device_event
| ax25_dev_device_down
ax25_bind | ...
... | kfree(ax25_dev)
ax25_fillin_cb() | ...
ax25_fillin_cb_from_dev() |
... |
The root cause of UAF bugs is that kfree(ax25_dev) in
ax25_dev_device_down() is not protected by any locks.
When ax25_dev, which there are still pointers point to,
is released, the concurrency UAF bug will happen.
This patch introduces refcount into ax25_dev in order to
guarantee that there are no pointers point to it when ax25_dev
is released.
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-01-28 12:47:16 +08:00
|
|
|
ax25_dev_put(ax25_dev);
|
2009-09-25 11:10:38 +08:00
|
|
|
ax25_cb_put(ax25);
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
einval_put:
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out_put;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-05-04 14:27:16 +08:00
|
|
|
static void ax25_fillin_cb_from_dev(ax25_cb *ax25, ax25_dev *ax25_dev)
|
|
|
|
{
|
|
|
|
ax25->rtt = msecs_to_jiffies(ax25_dev->values[AX25_VALUES_T1]) / 2;
|
|
|
|
ax25->t1 = msecs_to_jiffies(ax25_dev->values[AX25_VALUES_T1]);
|
|
|
|
ax25->t2 = msecs_to_jiffies(ax25_dev->values[AX25_VALUES_T2]);
|
|
|
|
ax25->t3 = msecs_to_jiffies(ax25_dev->values[AX25_VALUES_T3]);
|
|
|
|
ax25->n2 = ax25_dev->values[AX25_VALUES_N2];
|
|
|
|
ax25->paclen = ax25_dev->values[AX25_VALUES_PACLEN];
|
|
|
|
ax25->idle = msecs_to_jiffies(ax25_dev->values[AX25_VALUES_IDLE]);
|
|
|
|
ax25->backoff = ax25_dev->values[AX25_VALUES_BACKOFF];
|
|
|
|
|
|
|
|
if (ax25_dev->values[AX25_VALUES_AXDEFMODE]) {
|
|
|
|
ax25->modulus = AX25_EMODULUS;
|
|
|
|
ax25->window = ax25_dev->values[AX25_VALUES_EWINDOW];
|
|
|
|
} else {
|
|
|
|
ax25->modulus = AX25_MODULUS;
|
|
|
|
ax25->window = ax25_dev->values[AX25_VALUES_WINDOW];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Fill in a created AX.25 created control block with the default
|
|
|
|
* values for a particular device.
|
|
|
|
*/
|
|
|
|
void ax25_fillin_cb(ax25_cb *ax25, ax25_dev *ax25_dev)
|
|
|
|
{
|
|
|
|
ax25->ax25_dev = ax25_dev;
|
|
|
|
|
|
|
|
if (ax25->ax25_dev != NULL) {
|
2006-05-04 14:27:16 +08:00
|
|
|
ax25_fillin_cb_from_dev(ax25, ax25_dev);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* No device, use kernel / AX.25 spec default values
|
|
|
|
*/
|
|
|
|
ax25->rtt = msecs_to_jiffies(AX25_DEF_T1) / 2;
|
|
|
|
ax25->t1 = msecs_to_jiffies(AX25_DEF_T1);
|
|
|
|
ax25->t2 = msecs_to_jiffies(AX25_DEF_T2);
|
|
|
|
ax25->t3 = msecs_to_jiffies(AX25_DEF_T3);
|
|
|
|
ax25->n2 = AX25_DEF_N2;
|
|
|
|
ax25->paclen = AX25_DEF_PACLEN;
|
|
|
|
ax25->idle = msecs_to_jiffies(AX25_DEF_IDLE);
|
|
|
|
ax25->backoff = AX25_DEF_BACKOFF;
|
|
|
|
|
|
|
|
if (AX25_DEF_AXDEFMODE) {
|
|
|
|
ax25->modulus = AX25_EMODULUS;
|
|
|
|
ax25->window = AX25_DEF_EWINDOW;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
2006-05-04 14:27:16 +08:00
|
|
|
ax25->modulus = AX25_MODULUS;
|
|
|
|
ax25->window = AX25_DEF_WINDOW;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create an empty AX.25 control block.
|
|
|
|
*/
|
|
|
|
ax25_cb *ax25_create_cb(void)
|
|
|
|
{
|
|
|
|
ax25_cb *ax25;
|
|
|
|
|
2006-07-10 03:14:22 +08:00
|
|
|
if ((ax25 = kzalloc(sizeof(*ax25), GFP_ATOMIC)) == NULL)
|
2005-04-17 06:20:36 +08:00
|
|
|
return NULL;
|
|
|
|
|
2017-07-04 20:53:31 +08:00
|
|
|
refcount_set(&ax25->refcount, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
skb_queue_head_init(&ax25->write_queue);
|
|
|
|
skb_queue_head_init(&ax25->frag_queue);
|
|
|
|
skb_queue_head_init(&ax25->ack_queue);
|
|
|
|
skb_queue_head_init(&ax25->reseq_queue);
|
|
|
|
|
2008-02-12 13:36:39 +08:00
|
|
|
ax25_setup_timers(ax25);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ax25_fillin_cb(ax25, NULL);
|
|
|
|
|
|
|
|
ax25->state = AX25_STATE_0;
|
|
|
|
|
|
|
|
return ax25;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handling for system calls applied via the various interfaces to an
|
|
|
|
* AX25 socket object
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int ax25_setsockopt(struct socket *sock, int level, int optname,
|
2020-07-23 14:09:07 +08:00
|
|
|
sockptr_t optval, unsigned int optlen)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
ax25_cb *ax25;
|
|
|
|
struct net_device *dev;
|
|
|
|
char devname[IFNAMSIZ];
|
2022-01-07 15:13:12 +08:00
|
|
|
unsigned int opt;
|
2011-12-27 17:43:19 +08:00
|
|
|
int res = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (level != SOL_AX25)
|
|
|
|
return -ENOPROTOOPT;
|
|
|
|
|
2011-12-27 17:43:19 +08:00
|
|
|
if (optlen < sizeof(unsigned int))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2020-07-23 14:09:07 +08:00
|
|
|
if (copy_from_sockptr(&opt, optval, sizeof(unsigned int)))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
lock_sock(sk);
|
2015-06-25 21:19:07 +08:00
|
|
|
ax25 = sk_to_ax25(sk);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
switch (optname) {
|
|
|
|
case AX25_WINDOW:
|
|
|
|
if (ax25->modulus == AX25_MODULUS) {
|
|
|
|
if (opt < 1 || opt > 7) {
|
|
|
|
res = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (opt < 1 || opt > 63) {
|
|
|
|
res = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ax25->window = opt;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_T1:
|
2022-01-07 15:13:12 +08:00
|
|
|
if (opt < 1 || opt > UINT_MAX / HZ) {
|
2005-04-17 06:20:36 +08:00
|
|
|
res = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2008-01-14 14:29:41 +08:00
|
|
|
ax25->rtt = (opt * HZ) >> 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
ax25->t1 = opt * HZ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_T2:
|
2022-01-07 15:13:12 +08:00
|
|
|
if (opt < 1 || opt > UINT_MAX / HZ) {
|
2005-04-17 06:20:36 +08:00
|
|
|
res = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ax25->t2 = opt * HZ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_N2:
|
|
|
|
if (opt < 1 || opt > 31) {
|
|
|
|
res = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ax25->n2 = opt;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_T3:
|
2022-01-07 15:13:12 +08:00
|
|
|
if (opt < 1 || opt > UINT_MAX / HZ) {
|
2005-04-17 06:20:36 +08:00
|
|
|
res = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ax25->t3 = opt * HZ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_IDLE:
|
2022-01-07 15:13:12 +08:00
|
|
|
if (opt > UINT_MAX / (60 * HZ)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
res = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ax25->idle = opt * 60 * HZ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_BACKOFF:
|
2011-12-27 17:43:19 +08:00
|
|
|
if (opt > 2) {
|
2005-04-17 06:20:36 +08:00
|
|
|
res = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ax25->backoff = opt;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_EXTSEQ:
|
|
|
|
ax25->modulus = opt ? AX25_EMODULUS : AX25_MODULUS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_PIDINCL:
|
|
|
|
ax25->pidincl = opt ? 1 : 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_IAMDIGI:
|
|
|
|
ax25->iamdigi = opt ? 1 : 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_PACLEN:
|
|
|
|
if (opt < 16 || opt > 65535) {
|
|
|
|
res = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ax25->paclen = opt;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SO_BINDTODEVICE:
|
2020-05-20 09:24:43 +08:00
|
|
|
if (optlen > IFNAMSIZ - 1)
|
|
|
|
optlen = IFNAMSIZ - 1;
|
|
|
|
|
|
|
|
memset(devname, 0, sizeof(devname));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2020-07-23 14:09:07 +08:00
|
|
|
if (copy_from_sockptr(devname, optval, optlen)) {
|
2009-09-29 03:26:28 +08:00
|
|
|
res = -EFAULT;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sk->sk_type == SOCK_SEQPACKET &&
|
|
|
|
(sock->state != SS_UNCONNECTED ||
|
|
|
|
sk->sk_state == TCP_LISTEN)) {
|
|
|
|
res = -EADDRNOTAVAIL;
|
2009-09-29 03:26:28 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-12-30 05:56:36 +08:00
|
|
|
rtnl_lock();
|
|
|
|
dev = __dev_get_by_name(&init_net, devname);
|
2009-09-29 03:26:28 +08:00
|
|
|
if (!dev) {
|
2018-12-30 05:56:36 +08:00
|
|
|
rtnl_unlock();
|
2009-09-29 03:26:28 +08:00
|
|
|
res = -ENODEV;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ax25->ax25_dev = ax25_dev_ax25dev(dev);
|
2018-12-30 05:56:36 +08:00
|
|
|
if (!ax25->ax25_dev) {
|
|
|
|
rtnl_unlock();
|
|
|
|
res = -ENODEV;
|
|
|
|
break;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
ax25_fillin_cb(ax25, ax25->ax25_dev);
|
2018-12-30 05:56:36 +08:00
|
|
|
rtnl_unlock();
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
res = -ENOPROTOOPT;
|
|
|
|
}
|
|
|
|
release_sock(sk);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ax25_getsockopt(struct socket *sock, int level, int optname,
|
|
|
|
char __user *optval, int __user *optlen)
|
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
ax25_cb *ax25;
|
|
|
|
struct ax25_dev *ax25_dev;
|
|
|
|
char devname[IFNAMSIZ];
|
|
|
|
void *valptr;
|
|
|
|
int val = 0;
|
|
|
|
int maxlen, length;
|
|
|
|
|
|
|
|
if (level != SOL_AX25)
|
|
|
|
return -ENOPROTOOPT;
|
|
|
|
|
|
|
|
if (get_user(maxlen, optlen))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
if (maxlen < 1)
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
valptr = (void *) &val;
|
|
|
|
length = min_t(unsigned int, maxlen, sizeof(int));
|
|
|
|
|
|
|
|
lock_sock(sk);
|
2015-06-25 21:19:07 +08:00
|
|
|
ax25 = sk_to_ax25(sk);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
switch (optname) {
|
|
|
|
case AX25_WINDOW:
|
|
|
|
val = ax25->window;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_T1:
|
|
|
|
val = ax25->t1 / HZ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_T2:
|
|
|
|
val = ax25->t2 / HZ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_N2:
|
|
|
|
val = ax25->n2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_T3:
|
|
|
|
val = ax25->t3 / HZ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_IDLE:
|
|
|
|
val = ax25->idle / (60 * HZ);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_BACKOFF:
|
|
|
|
val = ax25->backoff;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_EXTSEQ:
|
|
|
|
val = (ax25->modulus == AX25_EMODULUS);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_PIDINCL:
|
|
|
|
val = ax25->pidincl;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_IAMDIGI:
|
|
|
|
val = ax25->iamdigi;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_PACLEN:
|
|
|
|
val = ax25->paclen;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SO_BINDTODEVICE:
|
|
|
|
ax25_dev = ax25->ax25_dev;
|
|
|
|
|
|
|
|
if (ax25_dev != NULL && ax25_dev->dev != NULL) {
|
|
|
|
strlcpy(devname, ax25_dev->dev->name, sizeof(devname));
|
|
|
|
length = strlen(devname) + 1;
|
|
|
|
} else {
|
|
|
|
*devname = '\0';
|
|
|
|
length = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
valptr = (void *) devname;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
release_sock(sk);
|
|
|
|
return -ENOPROTOOPT;
|
|
|
|
}
|
|
|
|
release_sock(sk);
|
|
|
|
|
|
|
|
if (put_user(length, optlen))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return copy_to_user(optval, valptr, length) ? -EFAULT : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ax25_listen(struct socket *sock, int backlog)
|
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
lock_sock(sk);
|
|
|
|
if (sk->sk_type == SOCK_SEQPACKET && sk->sk_state != TCP_LISTEN) {
|
|
|
|
sk->sk_max_ack_backlog = backlog;
|
|
|
|
sk->sk_state = TCP_LISTEN;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
res = -EOPNOTSUPP;
|
|
|
|
|
|
|
|
out:
|
|
|
|
release_sock(sk);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: when creating ax25_sock we should update the .obj_size setting
|
|
|
|
* below.
|
|
|
|
*/
|
|
|
|
static struct proto ax25_proto = {
|
|
|
|
.name = "AX25",
|
|
|
|
.owner = THIS_MODULE,
|
2015-06-25 21:19:07 +08:00
|
|
|
.obj_size = sizeof(struct ax25_sock),
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2009-11-06 14:18:14 +08:00
|
|
|
static int ax25_create(struct net *net, struct socket *sock, int protocol,
|
|
|
|
int kern)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct sock *sk;
|
|
|
|
ax25_cb *ax25;
|
|
|
|
|
2020-01-09 23:59:14 +08:00
|
|
|
if (protocol < 0 || protocol > U8_MAX)
|
2015-12-15 05:03:39 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2009-11-26 07:14:13 +08:00
|
|
|
if (!net_eq(net, &init_net))
|
2007-10-09 14:24:22 +08:00
|
|
|
return -EAFNOSUPPORT;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
switch (sock->type) {
|
|
|
|
case SOCK_DGRAM:
|
|
|
|
if (protocol == 0 || protocol == PF_AX25)
|
|
|
|
protocol = AX25_P_TEXT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOCK_SEQPACKET:
|
|
|
|
switch (protocol) {
|
|
|
|
case 0:
|
|
|
|
case PF_AX25: /* For CLX */
|
|
|
|
protocol = AX25_P_TEXT;
|
|
|
|
break;
|
|
|
|
case AX25_P_SEGMENT:
|
|
|
|
#ifdef CONFIG_INET
|
|
|
|
case AX25_P_ARP:
|
|
|
|
case AX25_P_IP:
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NETROM
|
|
|
|
case AX25_P_NETROM:
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_ROSE
|
|
|
|
case AX25_P_ROSE:
|
|
|
|
#endif
|
|
|
|
return -ESOCKTNOSUPPORT;
|
|
|
|
#ifdef CONFIG_NETROM_MODULE
|
|
|
|
case AX25_P_NETROM:
|
|
|
|
if (ax25_protocol_is_registered(AX25_P_NETROM))
|
|
|
|
return -ESOCKTNOSUPPORT;
|
2012-07-13 14:33:08 +08:00
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_ROSE_MODULE
|
|
|
|
case AX25_P_ROSE:
|
|
|
|
if (ax25_protocol_is_registered(AX25_P_ROSE))
|
|
|
|
return -ESOCKTNOSUPPORT;
|
2021-03-10 13:39:41 +08:00
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOCK_RAW:
|
2019-09-20 15:35:47 +08:00
|
|
|
if (!capable(CAP_NET_RAW))
|
|
|
|
return -EPERM;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -ESOCKTNOSUPPORT;
|
|
|
|
}
|
|
|
|
|
2015-05-09 10:09:13 +08:00
|
|
|
sk = sk_alloc(net, PF_AX25, GFP_ATOMIC, &ax25_proto, kern);
|
2007-11-01 15:39:31 +08:00
|
|
|
if (sk == NULL)
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2015-06-25 21:19:07 +08:00
|
|
|
ax25 = ax25_sk(sk)->cb = ax25_create_cb();
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!ax25) {
|
|
|
|
sk_free(sk);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
sock_init_data(sock, sk);
|
|
|
|
|
|
|
|
sk->sk_destruct = ax25_free_sock;
|
|
|
|
sock->ops = &ax25_proto_ops;
|
|
|
|
sk->sk_protocol = protocol;
|
|
|
|
|
|
|
|
ax25->sk = sk;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sock *ax25_make_new(struct sock *osk, struct ax25_dev *ax25_dev)
|
|
|
|
{
|
|
|
|
struct sock *sk;
|
|
|
|
ax25_cb *ax25, *oax25;
|
|
|
|
|
2015-05-09 10:09:13 +08:00
|
|
|
sk = sk_alloc(sock_net(osk), PF_AX25, GFP_ATOMIC, osk->sk_prot, 0);
|
2007-11-01 15:39:31 +08:00
|
|
|
if (sk == NULL)
|
2005-04-17 06:20:36 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if ((ax25 = ax25_create_cb()) == NULL) {
|
|
|
|
sk_free(sk);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (osk->sk_type) {
|
|
|
|
case SOCK_DGRAM:
|
|
|
|
break;
|
|
|
|
case SOCK_SEQPACKET:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sk_free(sk);
|
|
|
|
ax25_cb_put(ax25);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sock_init_data(NULL, sk);
|
|
|
|
|
|
|
|
sk->sk_type = osk->sk_type;
|
|
|
|
sk->sk_priority = osk->sk_priority;
|
|
|
|
sk->sk_protocol = osk->sk_protocol;
|
|
|
|
sk->sk_rcvbuf = osk->sk_rcvbuf;
|
|
|
|
sk->sk_sndbuf = osk->sk_sndbuf;
|
|
|
|
sk->sk_state = TCP_ESTABLISHED;
|
2005-08-24 01:11:30 +08:00
|
|
|
sock_copy_flags(sk, osk);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-06-25 21:19:07 +08:00
|
|
|
oax25 = sk_to_ax25(osk);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ax25->modulus = oax25->modulus;
|
|
|
|
ax25->backoff = oax25->backoff;
|
|
|
|
ax25->pidincl = oax25->pidincl;
|
|
|
|
ax25->iamdigi = oax25->iamdigi;
|
|
|
|
ax25->rtt = oax25->rtt;
|
|
|
|
ax25->t1 = oax25->t1;
|
|
|
|
ax25->t2 = oax25->t2;
|
|
|
|
ax25->t3 = oax25->t3;
|
|
|
|
ax25->n2 = oax25->n2;
|
|
|
|
ax25->idle = oax25->idle;
|
|
|
|
ax25->paclen = oax25->paclen;
|
|
|
|
ax25->window = oax25->window;
|
|
|
|
|
|
|
|
ax25->ax25_dev = ax25_dev;
|
|
|
|
ax25->source_addr = oax25->source_addr;
|
|
|
|
|
|
|
|
if (oax25->digipeat != NULL) {
|
2006-11-17 22:43:07 +08:00
|
|
|
ax25->digipeat = kmemdup(oax25->digipeat, sizeof(ax25_digi),
|
|
|
|
GFP_ATOMIC);
|
|
|
|
if (ax25->digipeat == NULL) {
|
2005-04-17 06:20:36 +08:00
|
|
|
sk_free(sk);
|
|
|
|
ax25_cb_put(ax25);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-25 21:19:07 +08:00
|
|
|
ax25_sk(sk)->cb = ax25;
|
2009-09-27 18:57:02 +08:00
|
|
|
sk->sk_destruct = ax25_free_sock;
|
2005-04-17 06:20:36 +08:00
|
|
|
ax25->sk = sk;
|
|
|
|
|
|
|
|
return sk;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ax25_release(struct socket *sock)
|
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
ax25_cb *ax25;
|
2022-03-18 08:54:04 +08:00
|
|
|
ax25_dev *ax25_dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (sk == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
sock_hold(sk);
|
|
|
|
lock_sock(sk);
|
2022-03-18 08:54:04 +08:00
|
|
|
sock_orphan(sk);
|
2015-06-25 21:19:07 +08:00
|
|
|
ax25 = sk_to_ax25(sk);
|
2022-03-18 08:54:04 +08:00
|
|
|
ax25_dev = ax25->ax25_dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (sk->sk_type == SOCK_SEQPACKET) {
|
|
|
|
switch (ax25->state) {
|
|
|
|
case AX25_STATE_0:
|
ax25: Fix ax25 session cleanup problems
There are session cleanup problems in ax25_release() and
ax25_disconnect(). If we setup a session and then disconnect,
the disconnected session is still in "LISTENING" state that
is shown below.
Active AX.25 sockets
Dest Source Device State Vr/Vs Send-Q Recv-Q
DL9SAU-4 DL9SAU-3 ??? LISTENING 000/000 0 0
DL9SAU-3 DL9SAU-4 ??? LISTENING 000/000 0 0
The first reason is caused by del_timer_sync() in ax25_release().
The timers of ax25 are used for correct session cleanup. If we use
ax25_release() to close ax25 sessions and ax25_dev is not null,
the del_timer_sync() functions in ax25_release() will execute.
As a result, the sessions could not be cleaned up correctly,
because the timers have stopped.
In order to solve this problem, this patch adds a device_up flag
in ax25_dev in order to judge whether the device is up. If there
are sessions to be cleaned up, the del_timer_sync() in
ax25_release() will not execute. What's more, we add ax25_cb_del()
in ax25_kill_by_device(), because the timers have been stopped
and there are no functions that could delete ax25_cb if we do not
call ax25_release(). Finally, we reorder the position of
ax25_list_lock in ax25_cb_del() in order to synchronize among
different functions that call ax25_cb_del().
The second reason is caused by improper check in ax25_disconnect().
The incoming ax25 sessions which ax25->sk is null will close
heartbeat timer, because the check "if(!ax25->sk || ..)" is
satisfied. As a result, the session could not be cleaned up properly.
In order to solve this problem, this patch changes the improper
check to "if(ax25->sk && ..)" in ax25_disconnect().
What`s more, the ax25_disconnect() may be called twice, which is
not necessary. For example, ax25_kill_by_device() calls
ax25_disconnect() and sets ax25->state to AX25_STATE_0, but
ax25_release() calls ax25_disconnect() again.
In order to solve this problem, this patch add a check in
ax25_release(). If the flag of ax25->sk equals to SOCK_DEAD,
the ax25_disconnect() in ax25_release() should not be executed.
Fixes: 82e31755e55f ("ax25: Fix UAF bugs in ax25 timers")
Fixes: 8a367e74c012 ("ax25: Fix segfault after sock connection timeout")
Reported-and-tested-by: Thomas Osterried <thomas@osterried.de>
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Link: https://lore.kernel.org/r/20220530152158.108619-1-duoming@zju.edu.cn
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2022-05-30 23:21:58 +08:00
|
|
|
if (!sock_flag(ax25->sk, SOCK_DEAD)) {
|
|
|
|
release_sock(sk);
|
|
|
|
ax25_disconnect(ax25, 0);
|
|
|
|
lock_sock(sk);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
ax25_destroy_socket(ax25);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_STATE_1:
|
|
|
|
case AX25_STATE_2:
|
|
|
|
ax25_send_control(ax25, AX25_DISC, AX25_POLLON, AX25_COMMAND);
|
|
|
|
release_sock(sk);
|
|
|
|
ax25_disconnect(ax25, 0);
|
|
|
|
lock_sock(sk);
|
2016-06-17 00:42:30 +08:00
|
|
|
if (!sock_flag(ax25->sk, SOCK_DESTROY))
|
|
|
|
ax25_destroy_socket(ax25);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AX25_STATE_3:
|
|
|
|
case AX25_STATE_4:
|
|
|
|
ax25_clear_queues(ax25);
|
|
|
|
ax25->n2count = 0;
|
|
|
|
|
|
|
|
switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
|
|
|
|
case AX25_PROTO_STD_SIMPLEX:
|
|
|
|
case AX25_PROTO_STD_DUPLEX:
|
|
|
|
ax25_send_control(ax25,
|
|
|
|
AX25_DISC,
|
|
|
|
AX25_POLLON,
|
|
|
|
AX25_COMMAND);
|
|
|
|
ax25_stop_t2timer(ax25);
|
|
|
|
ax25_stop_t3timer(ax25);
|
|
|
|
ax25_stop_idletimer(ax25);
|
|
|
|
break;
|
|
|
|
#ifdef CONFIG_AX25_DAMA_SLAVE
|
|
|
|
case AX25_PROTO_DAMA_SLAVE:
|
|
|
|
ax25_stop_t3timer(ax25);
|
|
|
|
ax25_stop_idletimer(ax25);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
ax25_calculate_t1(ax25);
|
|
|
|
ax25_start_t1timer(ax25);
|
|
|
|
ax25->state = AX25_STATE_2;
|
|
|
|
sk->sk_state = TCP_CLOSE;
|
|
|
|
sk->sk_shutdown |= SEND_SHUTDOWN;
|
|
|
|
sk->sk_state_change(sk);
|
|
|
|
sock_set_flag(sk, SOCK_DESTROY);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sk->sk_state = TCP_CLOSE;
|
|
|
|
sk->sk_shutdown |= SEND_SHUTDOWN;
|
|
|
|
sk->sk_state_change(sk);
|
|
|
|
ax25_destroy_socket(ax25);
|
|
|
|
}
|
2022-03-28 21:00:14 +08:00
|
|
|
if (ax25_dev) {
|
ax25: Fix ax25 session cleanup problems
There are session cleanup problems in ax25_release() and
ax25_disconnect(). If we setup a session and then disconnect,
the disconnected session is still in "LISTENING" state that
is shown below.
Active AX.25 sockets
Dest Source Device State Vr/Vs Send-Q Recv-Q
DL9SAU-4 DL9SAU-3 ??? LISTENING 000/000 0 0
DL9SAU-3 DL9SAU-4 ??? LISTENING 000/000 0 0
The first reason is caused by del_timer_sync() in ax25_release().
The timers of ax25 are used for correct session cleanup. If we use
ax25_release() to close ax25 sessions and ax25_dev is not null,
the del_timer_sync() functions in ax25_release() will execute.
As a result, the sessions could not be cleaned up correctly,
because the timers have stopped.
In order to solve this problem, this patch adds a device_up flag
in ax25_dev in order to judge whether the device is up. If there
are sessions to be cleaned up, the del_timer_sync() in
ax25_release() will not execute. What's more, we add ax25_cb_del()
in ax25_kill_by_device(), because the timers have been stopped
and there are no functions that could delete ax25_cb if we do not
call ax25_release(). Finally, we reorder the position of
ax25_list_lock in ax25_cb_del() in order to synchronize among
different functions that call ax25_cb_del().
The second reason is caused by improper check in ax25_disconnect().
The incoming ax25 sessions which ax25->sk is null will close
heartbeat timer, because the check "if(!ax25->sk || ..)" is
satisfied. As a result, the session could not be cleaned up properly.
In order to solve this problem, this patch changes the improper
check to "if(ax25->sk && ..)" in ax25_disconnect().
What`s more, the ax25_disconnect() may be called twice, which is
not necessary. For example, ax25_kill_by_device() calls
ax25_disconnect() and sets ax25->state to AX25_STATE_0, but
ax25_release() calls ax25_disconnect() again.
In order to solve this problem, this patch add a check in
ax25_release(). If the flag of ax25->sk equals to SOCK_DEAD,
the ax25_disconnect() in ax25_release() should not be executed.
Fixes: 82e31755e55f ("ax25: Fix UAF bugs in ax25 timers")
Fixes: 8a367e74c012 ("ax25: Fix segfault after sock connection timeout")
Reported-and-tested-by: Thomas Osterried <thomas@osterried.de>
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Link: https://lore.kernel.org/r/20220530152158.108619-1-duoming@zju.edu.cn
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2022-05-30 23:21:58 +08:00
|
|
|
if (!ax25_dev->device_up) {
|
|
|
|
del_timer_sync(&ax25->timer);
|
|
|
|
del_timer_sync(&ax25->t1timer);
|
|
|
|
del_timer_sync(&ax25->t2timer);
|
|
|
|
del_timer_sync(&ax25->t3timer);
|
|
|
|
del_timer_sync(&ax25->idletimer);
|
|
|
|
}
|
2022-06-08 12:39:55 +08:00
|
|
|
netdev_put(ax25_dev->dev, &ax25_dev->dev_tracker);
|
2022-03-28 21:00:14 +08:00
|
|
|
ax25_dev_put(ax25_dev);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
sock->sk = NULL;
|
|
|
|
release_sock(sk);
|
|
|
|
sock_put(sk);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We support a funny extension here so you can (as root) give any callsign
|
|
|
|
* digipeated via a local address as source. This hack is obsolete now
|
|
|
|
* that we've implemented support for SO_BINDTODEVICE. It is however small
|
|
|
|
* and trivially backward compatible.
|
|
|
|
*/
|
|
|
|
static int ax25_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
|
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
struct full_sockaddr_ax25 *addr = (struct full_sockaddr_ax25 *)uaddr;
|
|
|
|
ax25_dev *ax25_dev = NULL;
|
2005-08-24 01:11:45 +08:00
|
|
|
ax25_uid_assoc *user;
|
|
|
|
ax25_address call;
|
2005-04-17 06:20:36 +08:00
|
|
|
ax25_cb *ax25;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (addr_len != sizeof(struct sockaddr_ax25) &&
|
2008-01-29 12:44:11 +08:00
|
|
|
addr_len != sizeof(struct full_sockaddr_ax25))
|
|
|
|
/* support for old structure may go away some time
|
|
|
|
* ax25_bind(): uses old (6 digipeater) socket structure.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
if ((addr_len < sizeof(struct sockaddr_ax25) + sizeof(ax25_address) * 6) ||
|
2008-01-29 12:44:11 +08:00
|
|
|
(addr_len > sizeof(struct full_sockaddr_ax25)))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (addr->fsa_ax25.sax25_family != AF_AX25)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2008-11-14 07:39:06 +08:00
|
|
|
user = ax25_findbyuid(current_euid());
|
2005-08-24 01:11:45 +08:00
|
|
|
if (user) {
|
|
|
|
call = user->call;
|
|
|
|
ax25_uid_put(user);
|
|
|
|
} else {
|
|
|
|
if (ax25_uid_policy && !capable(CAP_NET_ADMIN))
|
|
|
|
return -EACCES;
|
|
|
|
|
|
|
|
call = addr->fsa_ax25.sax25_call;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
lock_sock(sk);
|
|
|
|
|
2015-06-25 21:19:07 +08:00
|
|
|
ax25 = sk_to_ax25(sk);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!sock_flag(sk, SOCK_ZAPPED)) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2005-08-24 01:11:45 +08:00
|
|
|
ax25->source_addr = call;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* User already set interface with SO_BINDTODEVICE
|
|
|
|
*/
|
|
|
|
if (ax25->ax25_dev != NULL)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (addr_len > sizeof(struct sockaddr_ax25) && addr->fsa_ax25.sax25_ndigis == 1) {
|
|
|
|
if (ax25cmp(&addr->fsa_digipeater[0], &null_ax25_address) != 0 &&
|
|
|
|
(ax25_dev = ax25_addr_ax25dev(&addr->fsa_digipeater[0])) == NULL) {
|
|
|
|
err = -EADDRNOTAVAIL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((ax25_dev = ax25_addr_ax25dev(&addr->fsa_ax25.sax25_call)) == NULL) {
|
|
|
|
err = -EADDRNOTAVAIL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
ax25: fix UAF bugs of net_device caused by rebinding operation
The ax25_kill_by_device() will set s->ax25_dev = NULL and
call ax25_disconnect() to change states of ax25_cb and
sock, if we call ax25_bind() before ax25_kill_by_device().
However, if we call ax25_bind() again between the window of
ax25_kill_by_device() and ax25_dev_device_down(), the values
and states changed by ax25_kill_by_device() will be reassigned.
Finally, ax25_dev_device_down() will deallocate net_device.
If we dereference net_device in syscall functions such as
ax25_release(), ax25_sendmsg(), ax25_getsockopt(), ax25_getname()
and ax25_info_show(), a UAF bug will occur.
One of the possible race conditions is shown below:
(USE) | (FREE)
ax25_bind() |
| ax25_kill_by_device()
ax25_bind() |
ax25_connect() | ...
| ax25_dev_device_down()
| ...
| dev_put_track(dev, ...) //FREE
ax25_release() | ...
ax25_send_control() |
alloc_skb() //USE |
the corresponding fail log is shown below:
===============================================================
BUG: KASAN: use-after-free in ax25_send_control+0x43/0x210
...
Call Trace:
...
ax25_send_control+0x43/0x210
ax25_release+0x2db/0x3b0
__sock_release+0x6d/0x120
sock_close+0xf/0x20
__fput+0x11f/0x420
...
Allocated by task 1283:
...
__kasan_kmalloc+0x81/0xa0
alloc_netdev_mqs+0x5a/0x680
mkiss_open+0x6c/0x380
tty_ldisc_open+0x55/0x90
...
Freed by task 1969:
...
kfree+0xa3/0x2c0
device_release+0x54/0xe0
kobject_put+0xa5/0x120
tty_ldisc_kill+0x3e/0x80
...
In order to fix these UAF bugs caused by rebinding operation,
this patch adds dev_hold_track() into ax25_bind() and
corresponding dev_put_track() into ax25_kill_by_device().
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-02-09 20:53:45 +08:00
|
|
|
if (ax25_dev) {
|
2005-04-17 06:20:36 +08:00
|
|
|
ax25_fillin_cb(ax25, ax25_dev);
|
2022-06-08 12:39:55 +08:00
|
|
|
netdev_hold(ax25_dev->dev, &ax25_dev->dev_tracker, GFP_ATOMIC);
|
ax25: fix UAF bugs of net_device caused by rebinding operation
The ax25_kill_by_device() will set s->ax25_dev = NULL and
call ax25_disconnect() to change states of ax25_cb and
sock, if we call ax25_bind() before ax25_kill_by_device().
However, if we call ax25_bind() again between the window of
ax25_kill_by_device() and ax25_dev_device_down(), the values
and states changed by ax25_kill_by_device() will be reassigned.
Finally, ax25_dev_device_down() will deallocate net_device.
If we dereference net_device in syscall functions such as
ax25_release(), ax25_sendmsg(), ax25_getsockopt(), ax25_getname()
and ax25_info_show(), a UAF bug will occur.
One of the possible race conditions is shown below:
(USE) | (FREE)
ax25_bind() |
| ax25_kill_by_device()
ax25_bind() |
ax25_connect() | ...
| ax25_dev_device_down()
| ...
| dev_put_track(dev, ...) //FREE
ax25_release() | ...
ax25_send_control() |
alloc_skb() //USE |
the corresponding fail log is shown below:
===============================================================
BUG: KASAN: use-after-free in ax25_send_control+0x43/0x210
...
Call Trace:
...
ax25_send_control+0x43/0x210
ax25_release+0x2db/0x3b0
__sock_release+0x6d/0x120
sock_close+0xf/0x20
__fput+0x11f/0x420
...
Allocated by task 1283:
...
__kasan_kmalloc+0x81/0xa0
alloc_netdev_mqs+0x5a/0x680
mkiss_open+0x6c/0x380
tty_ldisc_open+0x55/0x90
...
Freed by task 1969:
...
kfree+0xa3/0x2c0
device_release+0x54/0xe0
kobject_put+0xa5/0x120
tty_ldisc_kill+0x3e/0x80
...
In order to fix these UAF bugs caused by rebinding operation,
this patch adds dev_hold_track() into ax25_bind() and
corresponding dev_put_track() into ax25_kill_by_device().
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-02-09 20:53:45 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
done:
|
|
|
|
ax25_cb_add(ax25);
|
|
|
|
sock_reset_flag(sk, SOCK_ZAPPED);
|
|
|
|
|
|
|
|
out:
|
|
|
|
release_sock(sk);
|
|
|
|
|
2010-08-16 14:28:19 +08:00
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: nonblock behaviour looks like it may have a bug.
|
|
|
|
*/
|
2006-12-15 07:49:28 +08:00
|
|
|
static int __must_check ax25_connect(struct socket *sock,
|
|
|
|
struct sockaddr *uaddr, int addr_len, int flags)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
2015-06-25 21:19:07 +08:00
|
|
|
ax25_cb *ax25 = sk_to_ax25(sk), *ax25t;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct full_sockaddr_ax25 *fsa = (struct full_sockaddr_ax25 *)uaddr;
|
|
|
|
ax25_digi *digi = NULL;
|
|
|
|
int ct = 0, err = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* some sanity checks. code further down depends on this
|
|
|
|
*/
|
|
|
|
|
2008-01-10 19:57:29 +08:00
|
|
|
if (addr_len == sizeof(struct sockaddr_ax25))
|
|
|
|
/* support for this will go away in early 2.5.x
|
|
|
|
* ax25_connect(): uses obsolete socket structure
|
|
|
|
*/
|
|
|
|
;
|
|
|
|
else if (addr_len != sizeof(struct full_sockaddr_ax25))
|
|
|
|
/* support for old structure may go away some time
|
|
|
|
* ax25_connect(): uses old (6 digipeater) socket structure.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
if ((addr_len < sizeof(struct sockaddr_ax25) + sizeof(ax25_address) * 6) ||
|
2008-01-10 19:57:29 +08:00
|
|
|
(addr_len > sizeof(struct full_sockaddr_ax25)))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
|
|
if (fsa->fsa_ax25.sax25_family != AF_AX25)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
lock_sock(sk);
|
|
|
|
|
|
|
|
/* deal with restarts */
|
|
|
|
if (sock->state == SS_CONNECTING) {
|
|
|
|
switch (sk->sk_state) {
|
|
|
|
case TCP_SYN_SENT: /* still trying */
|
|
|
|
err = -EINPROGRESS;
|
2007-04-21 07:06:45 +08:00
|
|
|
goto out_release;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
case TCP_ESTABLISHED: /* connection established */
|
|
|
|
sock->state = SS_CONNECTED;
|
2007-04-21 07:06:45 +08:00
|
|
|
goto out_release;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
case TCP_CLOSE: /* connection refused */
|
|
|
|
sock->state = SS_UNCONNECTED;
|
|
|
|
err = -ECONNREFUSED;
|
2007-04-21 07:06:45 +08:00
|
|
|
goto out_release;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sk->sk_state == TCP_ESTABLISHED && sk->sk_type == SOCK_SEQPACKET) {
|
|
|
|
err = -EISCONN; /* No reconnect on a seqpacket socket */
|
2007-04-21 07:06:45 +08:00
|
|
|
goto out_release;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sk->sk_state = TCP_CLOSE;
|
|
|
|
sock->state = SS_UNCONNECTED;
|
|
|
|
|
2005-11-09 01:41:34 +08:00
|
|
|
kfree(ax25->digipeat);
|
|
|
|
ax25->digipeat = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle digi-peaters to be used.
|
|
|
|
*/
|
|
|
|
if (addr_len > sizeof(struct sockaddr_ax25) &&
|
|
|
|
fsa->fsa_ax25.sax25_ndigis != 0) {
|
|
|
|
/* Valid number of digipeaters ? */
|
2020-07-22 23:19:01 +08:00
|
|
|
if (fsa->fsa_ax25.sax25_ndigis < 1 ||
|
2020-07-23 22:49:57 +08:00
|
|
|
fsa->fsa_ax25.sax25_ndigis > AX25_MAX_DIGIS ||
|
2020-07-22 23:19:01 +08:00
|
|
|
addr_len < sizeof(struct sockaddr_ax25) +
|
|
|
|
sizeof(ax25_address) * fsa->fsa_ax25.sax25_ndigis) {
|
2005-04-17 06:20:36 +08:00
|
|
|
err = -EINVAL;
|
2007-04-21 07:06:45 +08:00
|
|
|
goto out_release;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((digi = kmalloc(sizeof(ax25_digi), GFP_KERNEL)) == NULL) {
|
|
|
|
err = -ENOBUFS;
|
2007-04-21 07:06:45 +08:00
|
|
|
goto out_release;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
digi->ndigi = fsa->fsa_ax25.sax25_ndigis;
|
|
|
|
digi->lastrepeat = -1;
|
|
|
|
|
|
|
|
while (ct < fsa->fsa_ax25.sax25_ndigis) {
|
|
|
|
if ((fsa->fsa_digipeater[ct].ax25_call[6] &
|
|
|
|
AX25_HBIT) && ax25->iamdigi) {
|
|
|
|
digi->repeated[ct] = 1;
|
|
|
|
digi->lastrepeat = ct;
|
|
|
|
} else {
|
|
|
|
digi->repeated[ct] = 0;
|
|
|
|
}
|
|
|
|
digi->calls[ct] = fsa->fsa_digipeater[ct];
|
|
|
|
ct++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Must bind first - autobinding in this may or may not work. If
|
|
|
|
* the socket is already bound, check to see if the device has
|
|
|
|
* been filled in, error if it hasn't.
|
|
|
|
*/
|
|
|
|
if (sock_flag(sk, SOCK_ZAPPED)) {
|
|
|
|
/* check if we can remove this feature. It is broken. */
|
|
|
|
printk(KERN_WARNING "ax25_connect(): %s uses autobind, please contact jreuter@yaina.de\n",
|
|
|
|
current->comm);
|
|
|
|
if ((err = ax25_rt_autobind(ax25, &fsa->fsa_ax25.sax25_call)) < 0) {
|
|
|
|
kfree(digi);
|
2007-04-21 07:06:45 +08:00
|
|
|
goto out_release;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ax25_fillin_cb(ax25, ax25->ax25_dev);
|
|
|
|
ax25_cb_add(ax25);
|
|
|
|
} else {
|
|
|
|
if (ax25->ax25_dev == NULL) {
|
|
|
|
kfree(digi);
|
|
|
|
err = -EHOSTUNREACH;
|
2007-04-21 07:06:45 +08:00
|
|
|
goto out_release;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sk->sk_type == SOCK_SEQPACKET &&
|
|
|
|
(ax25t=ax25_find_cb(&ax25->source_addr, &fsa->fsa_ax25.sax25_call, digi,
|
2007-02-09 22:24:31 +08:00
|
|
|
ax25->ax25_dev->dev))) {
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(digi);
|
|
|
|
err = -EADDRINUSE; /* Already such a connection */
|
|
|
|
ax25_cb_put(ax25t);
|
2007-04-21 07:06:45 +08:00
|
|
|
goto out_release;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ax25->dest_addr = fsa->fsa_ax25.sax25_call;
|
|
|
|
ax25->digipeat = digi;
|
|
|
|
|
|
|
|
/* First the easy one */
|
|
|
|
if (sk->sk_type != SOCK_SEQPACKET) {
|
|
|
|
sock->state = SS_CONNECTED;
|
|
|
|
sk->sk_state = TCP_ESTABLISHED;
|
2007-04-21 07:06:45 +08:00
|
|
|
goto out_release;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Move to connecting socket, ax.25 lapb WAIT_UA.. */
|
|
|
|
sock->state = SS_CONNECTING;
|
|
|
|
sk->sk_state = TCP_SYN_SENT;
|
|
|
|
|
|
|
|
switch (ax25->ax25_dev->values[AX25_VALUES_PROTOCOL]) {
|
|
|
|
case AX25_PROTO_STD_SIMPLEX:
|
|
|
|
case AX25_PROTO_STD_DUPLEX:
|
|
|
|
ax25_std_establish_data_link(ax25);
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef CONFIG_AX25_DAMA_SLAVE
|
|
|
|
case AX25_PROTO_DAMA_SLAVE:
|
|
|
|
ax25->modulus = AX25_MODULUS;
|
|
|
|
ax25->window = ax25->ax25_dev->values[AX25_VALUES_WINDOW];
|
|
|
|
if (ax25->ax25_dev->dama.slave)
|
|
|
|
ax25_ds_establish_data_link(ax25);
|
|
|
|
else
|
|
|
|
ax25_std_establish_data_link(ax25);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
ax25->state = AX25_STATE_1;
|
|
|
|
|
|
|
|
ax25_start_heartbeat(ax25);
|
|
|
|
|
|
|
|
/* Now the loop */
|
|
|
|
if (sk->sk_state != TCP_ESTABLISHED && (flags & O_NONBLOCK)) {
|
|
|
|
err = -EINPROGRESS;
|
2007-04-21 07:06:45 +08:00
|
|
|
goto out_release;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sk->sk_state == TCP_SYN_SENT) {
|
2007-04-21 07:06:45 +08:00
|
|
|
DEFINE_WAIT(wait);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
for (;;) {
|
2010-04-20 21:03:51 +08:00
|
|
|
prepare_to_wait(sk_sleep(sk), &wait,
|
2007-07-19 09:43:13 +08:00
|
|
|
TASK_INTERRUPTIBLE);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (sk->sk_state != TCP_SYN_SENT)
|
|
|
|
break;
|
2007-04-21 07:06:45 +08:00
|
|
|
if (!signal_pending(current)) {
|
|
|
|
release_sock(sk);
|
2005-04-17 06:20:36 +08:00
|
|
|
schedule();
|
|
|
|
lock_sock(sk);
|
|
|
|
continue;
|
|
|
|
}
|
2007-04-21 07:06:45 +08:00
|
|
|
err = -ERESTARTSYS;
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-04-20 21:03:51 +08:00
|
|
|
finish_wait(sk_sleep(sk), &wait);
|
2007-04-21 07:06:45 +08:00
|
|
|
|
|
|
|
if (err)
|
|
|
|
goto out_release;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sk->sk_state != TCP_ESTABLISHED) {
|
|
|
|
/* Not in ABM, not in WAIT_UA -> failed */
|
|
|
|
sock->state = SS_UNCONNECTED;
|
|
|
|
err = sock_error(sk); /* Always set at this point */
|
2007-04-21 07:06:45 +08:00
|
|
|
goto out_release;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sock->state = SS_CONNECTED;
|
|
|
|
|
2007-04-21 07:06:45 +08:00
|
|
|
err = 0;
|
|
|
|
out_release:
|
2005-04-17 06:20:36 +08:00
|
|
|
release_sock(sk);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2017-03-09 16:09:05 +08:00
|
|
|
static int ax25_accept(struct socket *sock, struct socket *newsock, int flags,
|
|
|
|
bool kern)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct sk_buff *skb;
|
|
|
|
struct sock *newsk;
|
2007-04-21 07:06:45 +08:00
|
|
|
DEFINE_WAIT(wait);
|
2005-04-17 06:20:36 +08:00
|
|
|
struct sock *sk;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (sock->state != SS_UNCONNECTED)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if ((sk = sock->sk) == NULL)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
lock_sock(sk);
|
|
|
|
if (sk->sk_type != SOCK_SEQPACKET) {
|
|
|
|
err = -EOPNOTSUPP;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sk->sk_state != TCP_LISTEN) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The read queue this time is holding sockets ready to use
|
|
|
|
* hooked into the SABM we saved
|
|
|
|
*/
|
|
|
|
for (;;) {
|
2010-04-20 21:03:51 +08:00
|
|
|
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
|
2005-04-17 06:20:36 +08:00
|
|
|
skb = skb_dequeue(&sk->sk_receive_queue);
|
|
|
|
if (skb)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (flags & O_NONBLOCK) {
|
2007-04-21 07:06:45 +08:00
|
|
|
err = -EWOULDBLOCK;
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-04-21 07:06:45 +08:00
|
|
|
if (!signal_pending(current)) {
|
|
|
|
release_sock(sk);
|
2005-04-17 06:20:36 +08:00
|
|
|
schedule();
|
|
|
|
lock_sock(sk);
|
|
|
|
continue;
|
|
|
|
}
|
2007-04-21 07:06:45 +08:00
|
|
|
err = -ERESTARTSYS;
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-04-20 21:03:51 +08:00
|
|
|
finish_wait(sk_sleep(sk), &wait);
|
2007-04-21 07:06:45 +08:00
|
|
|
|
|
|
|
if (err)
|
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
newsk = skb->sk;
|
2008-06-17 17:20:54 +08:00
|
|
|
sock_graft(newsk, newsock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Now attach up the new socket */
|
|
|
|
kfree_skb(skb);
|
2019-11-06 06:11:52 +08:00
|
|
|
sk_acceptq_removed(sk);
|
2005-04-17 06:20:36 +08:00
|
|
|
newsock->state = SS_CONNECTED;
|
|
|
|
|
|
|
|
out:
|
|
|
|
release_sock(sk);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ax25_getname(struct socket *sock, struct sockaddr *uaddr,
|
2018-02-13 03:00:20 +08:00
|
|
|
int peer)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct full_sockaddr_ax25 *fsa = (struct full_sockaddr_ax25 *)uaddr;
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
unsigned char ndigi, i;
|
|
|
|
ax25_cb *ax25;
|
|
|
|
int err = 0;
|
|
|
|
|
2011-01-12 16:34:49 +08:00
|
|
|
memset(fsa, 0, sizeof(*fsa));
|
2005-04-17 06:20:36 +08:00
|
|
|
lock_sock(sk);
|
2015-06-25 21:19:07 +08:00
|
|
|
ax25 = sk_to_ax25(sk);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (peer != 0) {
|
|
|
|
if (sk->sk_state != TCP_ESTABLISHED) {
|
|
|
|
err = -ENOTCONN;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
fsa->fsa_ax25.sax25_family = AF_AX25;
|
|
|
|
fsa->fsa_ax25.sax25_call = ax25->dest_addr;
|
|
|
|
|
|
|
|
if (ax25->digipeat != NULL) {
|
|
|
|
ndigi = ax25->digipeat->ndigi;
|
|
|
|
fsa->fsa_ax25.sax25_ndigis = ndigi;
|
|
|
|
for (i = 0; i < ndigi; i++)
|
|
|
|
fsa->fsa_digipeater[i] =
|
|
|
|
ax25->digipeat->calls[i];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fsa->fsa_ax25.sax25_family = AF_AX25;
|
|
|
|
fsa->fsa_ax25.sax25_call = ax25->source_addr;
|
|
|
|
fsa->fsa_ax25.sax25_ndigis = 1;
|
|
|
|
if (ax25->ax25_dev != NULL) {
|
|
|
|
memcpy(&fsa->fsa_digipeater[0],
|
|
|
|
ax25->ax25_dev->dev->dev_addr, AX25_ADDR_LEN);
|
|
|
|
} else {
|
|
|
|
fsa->fsa_digipeater[0] = null_ax25_address;
|
|
|
|
}
|
|
|
|
}
|
2018-02-13 03:00:20 +08:00
|
|
|
err = sizeof (struct full_sockaddr_ax25);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
release_sock(sk);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2015-03-02 15:37:48 +08:00
|
|
|
static int ax25_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-01-18 05:53:15 +08:00
|
|
|
DECLARE_SOCKADDR(struct sockaddr_ax25 *, usax, msg->msg_name);
|
2005-04-17 06:20:36 +08:00
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
struct sockaddr_ax25 sax;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
ax25_digi dtmp, *dp;
|
|
|
|
ax25_cb *ax25;
|
|
|
|
size_t size;
|
|
|
|
int lv, err, addr_len = msg->msg_namelen;
|
|
|
|
|
|
|
|
if (msg->msg_flags & ~(MSG_DONTWAIT|MSG_EOR|MSG_CMSG_COMPAT))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
lock_sock(sk);
|
2015-06-25 21:19:07 +08:00
|
|
|
ax25 = sk_to_ax25(sk);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (sock_flag(sk, SOCK_ZAPPED)) {
|
|
|
|
err = -EADDRNOTAVAIL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sk->sk_shutdown & SEND_SHUTDOWN) {
|
|
|
|
send_sig(SIGPIPE, current, 0);
|
|
|
|
err = -EPIPE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ax25->ax25_dev == NULL) {
|
|
|
|
err = -ENETUNREACH;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len > ax25->ax25_dev->dev->mtu) {
|
|
|
|
err = -EMSGSIZE;
|
|
|
|
goto out;
|
|
|
|
}
|
2007-02-09 22:24:31 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (usax != NULL) {
|
|
|
|
if (usax->sax25_family != AF_AX25) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2008-01-10 19:57:29 +08:00
|
|
|
if (addr_len == sizeof(struct sockaddr_ax25))
|
|
|
|
/* ax25_sendmsg(): uses obsolete socket structure */
|
|
|
|
;
|
|
|
|
else if (addr_len != sizeof(struct full_sockaddr_ax25))
|
|
|
|
/* support for old structure may go away some time
|
|
|
|
* ax25_sendmsg(): uses old (6 digipeater)
|
|
|
|
* socket structure.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
if ((addr_len < sizeof(struct sockaddr_ax25) + sizeof(ax25_address) * 6) ||
|
2007-02-09 22:24:31 +08:00
|
|
|
(addr_len > sizeof(struct full_sockaddr_ax25))) {
|
|
|
|
err = -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (addr_len > sizeof(struct sockaddr_ax25) && usax->sax25_ndigis != 0) {
|
|
|
|
int ct = 0;
|
|
|
|
struct full_sockaddr_ax25 *fsa = (struct full_sockaddr_ax25 *)usax;
|
|
|
|
|
|
|
|
/* Valid number of digipeaters ? */
|
2020-07-23 22:49:57 +08:00
|
|
|
if (usax->sax25_ndigis < 1 ||
|
|
|
|
usax->sax25_ndigis > AX25_MAX_DIGIS ||
|
|
|
|
addr_len < sizeof(struct sockaddr_ax25) +
|
2020-07-23 00:05:12 +08:00
|
|
|
sizeof(ax25_address) * usax->sax25_ndigis) {
|
2005-04-17 06:20:36 +08:00
|
|
|
err = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
dtmp.ndigi = usax->sax25_ndigis;
|
|
|
|
|
|
|
|
while (ct < usax->sax25_ndigis) {
|
|
|
|
dtmp.repeated[ct] = 0;
|
|
|
|
dtmp.calls[ct] = fsa->fsa_digipeater[ct];
|
|
|
|
ct++;
|
|
|
|
}
|
|
|
|
|
|
|
|
dtmp.lastrepeat = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sax = *usax;
|
|
|
|
if (sk->sk_type == SOCK_SEQPACKET &&
|
|
|
|
ax25cmp(&ax25->dest_addr, &sax.sax25_call)) {
|
|
|
|
err = -EISCONN;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (usax->sax25_ndigis == 0)
|
|
|
|
dp = NULL;
|
|
|
|
else
|
|
|
|
dp = &dtmp;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* FIXME: 1003.1g - if the socket is like this because
|
|
|
|
* it has become closed (not started closed) and is VC
|
|
|
|
* we ought to SIGPIPE, EPIPE
|
|
|
|
*/
|
|
|
|
if (sk->sk_state != TCP_ESTABLISHED) {
|
|
|
|
err = -ENOTCONN;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
sax.sax25_family = AF_AX25;
|
|
|
|
sax.sax25_call = ax25->dest_addr;
|
|
|
|
dp = ax25->digipeat;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build a packet */
|
|
|
|
/* Assume the worst case */
|
|
|
|
size = len + ax25->ax25_dev->dev->hard_header_len;
|
|
|
|
|
|
|
|
skb = sock_alloc_send_skb(sk, size, msg->msg_flags&MSG_DONTWAIT, &err);
|
|
|
|
if (skb == NULL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
skb_reserve(skb, size - len);
|
|
|
|
|
|
|
|
/* User data follows immediately after the AX.25 data */
|
2014-04-07 09:25:44 +08:00
|
|
|
if (memcpy_from_msg(skb_put(skb, len), msg, len)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
err = -EFAULT;
|
|
|
|
kfree_skb(skb);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2007-04-11 11:45:18 +08:00
|
|
|
skb_reset_network_header(skb);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Add the PID if one is not supplied by the user in the skb */
|
2007-03-14 00:51:52 +08:00
|
|
|
if (!ax25->pidincl)
|
networking: make skb_push & __skb_push return void pointers
It seems like a historic accident that these return unsigned char *,
and in many places that means casts are required, more often than not.
Make these functions return void * and remove all the casts across
the tree, adding a (u8 *) cast only where the unsigned char pointer
was used directly, all done with the following spatch:
@@
expression SKB, LEN;
typedef u8;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
@@
- *(fn(SKB, LEN))
+ *(u8 *)fn(SKB, LEN)
@@
expression E, SKB, LEN;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
type T;
@@
- E = ((T *)(fn(SKB, LEN)))
+ E = fn(SKB, LEN)
@@
expression SKB, LEN;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
@@
- fn(SKB, LEN)[0]
+ *(u8 *)fn(SKB, LEN)
Note that the last part there converts from push(...)[0] to the
more idiomatic *(u8 *)push(...).
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 20:29:23 +08:00
|
|
|
*(u8 *)skb_push(skb, 1) = sk->sk_protocol;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (sk->sk_type == SOCK_SEQPACKET) {
|
|
|
|
/* Connected mode sockets go via the LAPB machine */
|
|
|
|
if (sk->sk_state != TCP_ESTABLISHED) {
|
|
|
|
kfree_skb(skb);
|
|
|
|
err = -ENOTCONN;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Shove it onto the queue and kick */
|
|
|
|
ax25_output(ax25, ax25->paclen, skb);
|
|
|
|
|
|
|
|
err = len;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2007-03-14 00:51:52 +08:00
|
|
|
skb_push(skb, 1 + ax25_addr_size(dp));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-04-14 15:20:07 +08:00
|
|
|
/* Building AX.25 Header */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Build an AX.25 header */
|
2007-03-14 00:51:52 +08:00
|
|
|
lv = ax25_addr_build(skb->data, &ax25->source_addr, &sax.sax25_call,
|
|
|
|
dp, AX25_COMMAND, AX25_MODULUS);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-03-14 00:51:52 +08:00
|
|
|
skb_set_transport_header(skb, lv);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-04-26 09:04:18 +08:00
|
|
|
*skb_transport_header(skb) = AX25_UI;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Datagram frames go straight out of the door as UI */
|
2005-04-22 07:46:56 +08:00
|
|
|
ax25_queue_xmit(skb, ax25->ax25_dev->dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
err = len;
|
|
|
|
|
|
|
|
out:
|
|
|
|
release_sock(sk);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2015-03-02 15:37:48 +08:00
|
|
|
static int ax25_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
|
|
|
|
int flags)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
2022-06-14 17:25:57 +08:00
|
|
|
struct sk_buff *skb, *last;
|
|
|
|
struct sk_buff_head *sk_queue;
|
2005-04-17 06:20:36 +08:00
|
|
|
int copied;
|
|
|
|
int err = 0;
|
2022-06-14 17:25:57 +08:00
|
|
|
int off = 0;
|
|
|
|
long timeo;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
lock_sock(sk);
|
|
|
|
/*
|
|
|
|
* This works for seqpacket too. The receiver has ordered the
|
|
|
|
* queue for us! We do one quick check first though
|
|
|
|
*/
|
|
|
|
if (sk->sk_type == SOCK_SEQPACKET && sk->sk_state != TCP_ESTABLISHED) {
|
|
|
|
err = -ENOTCONN;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2022-06-14 17:25:57 +08:00
|
|
|
/* We need support for non-blocking reads. */
|
|
|
|
sk_queue = &sk->sk_receive_queue;
|
|
|
|
skb = __skb_try_recv_datagram(sk, sk_queue, flags, &off, &err, &last);
|
|
|
|
/* If no packet is available, release_sock(sk) and try again. */
|
|
|
|
if (!skb) {
|
|
|
|
if (err != -EAGAIN)
|
|
|
|
goto out;
|
|
|
|
release_sock(sk);
|
|
|
|
timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);
|
|
|
|
while (timeo && !__skb_wait_for_more_packets(sk, sk_queue, &err,
|
|
|
|
&timeo, last)) {
|
|
|
|
skb = __skb_try_recv_datagram(sk, sk_queue, flags, &off,
|
|
|
|
&err, &last);
|
|
|
|
if (skb)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (err != -EAGAIN)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (!skb)
|
|
|
|
goto done;
|
|
|
|
lock_sock(sk);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-06-25 21:19:07 +08:00
|
|
|
if (!sk_to_ax25(sk)->pidincl)
|
2005-04-17 06:20:36 +08:00
|
|
|
skb_pull(skb, 1); /* Remove PID */
|
|
|
|
|
2007-03-14 00:06:52 +08:00
|
|
|
skb_reset_transport_header(skb);
|
|
|
|
copied = skb->len;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (copied > size) {
|
|
|
|
copied = size;
|
|
|
|
msg->msg_flags |= MSG_TRUNC;
|
|
|
|
}
|
|
|
|
|
2014-11-06 05:46:40 +08:00
|
|
|
skb_copy_datagram_msg(skb, 0, msg, copied);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-11-21 10:14:22 +08:00
|
|
|
if (msg->msg_name) {
|
2005-04-17 06:20:36 +08:00
|
|
|
ax25_digi digi;
|
|
|
|
ax25_address src;
|
2007-03-20 06:33:04 +08:00
|
|
|
const unsigned char *mac = skb_mac_header(skb);
|
2014-01-18 05:53:15 +08:00
|
|
|
DECLARE_SOCKADDR(struct sockaddr_ax25 *, sax, msg->msg_name);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-04-07 09:51:48 +08:00
|
|
|
memset(sax, 0, sizeof(struct full_sockaddr_ax25));
|
2007-03-20 06:33:04 +08:00
|
|
|
ax25_addr_parse(mac + 1, skb->data - mac - 1, &src, NULL,
|
|
|
|
&digi, NULL, NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
sax->sax25_family = AF_AX25;
|
|
|
|
/* We set this correctly, even though we may not let the
|
|
|
|
application know the digi calls further down (because it
|
|
|
|
did NOT ask to know them). This could get political... **/
|
|
|
|
sax->sax25_ndigis = digi.ndigi;
|
|
|
|
sax->sax25_call = src;
|
|
|
|
|
|
|
|
if (sax->sax25_ndigis != 0) {
|
|
|
|
int ct;
|
|
|
|
struct full_sockaddr_ax25 *fsa = (struct full_sockaddr_ax25 *)sax;
|
|
|
|
|
|
|
|
for (ct = 0; ct < digi.ndigi; ct++)
|
|
|
|
fsa->fsa_digipeater[ct] = digi.calls[ct];
|
|
|
|
}
|
|
|
|
msg->msg_namelen = sizeof(struct full_sockaddr_ax25);
|
|
|
|
}
|
|
|
|
|
|
|
|
skb_free_datagram(sk, skb);
|
|
|
|
err = copied;
|
|
|
|
|
|
|
|
out:
|
|
|
|
release_sock(sk);
|
|
|
|
|
2022-06-14 17:25:57 +08:00
|
|
|
done:
|
2005-04-17 06:20:36 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ax25_shutdown(struct socket *sk, int how)
|
|
|
|
{
|
|
|
|
/* FIXME - generate DM and RNR states */
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ax25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
void __user *argp = (void __user *)arg;
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
lock_sock(sk);
|
|
|
|
switch (cmd) {
|
|
|
|
case TIOCOUTQ: {
|
|
|
|
long amount;
|
2009-06-18 10:05:41 +08:00
|
|
|
|
|
|
|
amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (amount < 0)
|
|
|
|
amount = 0;
|
|
|
|
res = put_user(amount, (int __user *)argp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TIOCINQ: {
|
|
|
|
struct sk_buff *skb;
|
|
|
|
long amount = 0L;
|
|
|
|
/* These two are safe on a single CPU system as only user tasks fiddle here */
|
|
|
|
if ((skb = skb_peek(&sk->sk_receive_queue)) != NULL)
|
|
|
|
amount = skb->len;
|
2005-09-13 05:24:55 +08:00
|
|
|
res = put_user(amount, (int __user *) argp);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SIOCAX25ADDUID: /* Add a uid to the uid/call map table */
|
|
|
|
case SIOCAX25DELUID: /* Delete a uid from the uid/call map table */
|
|
|
|
case SIOCAX25GETUID: {
|
|
|
|
struct sockaddr_ax25 sax25;
|
|
|
|
if (copy_from_user(&sax25, argp, sizeof(sax25))) {
|
|
|
|
res = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
res = ax25_uid_ioctl(cmd, &sax25);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SIOCAX25NOUID: { /* Set the default policy (default/bar) */
|
|
|
|
long amount;
|
|
|
|
if (!capable(CAP_NET_ADMIN)) {
|
|
|
|
res = -EPERM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (get_user(amount, (long __user *)argp)) {
|
|
|
|
res = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
2013-10-18 17:06:56 +08:00
|
|
|
if (amount < 0 || amount > AX25_NOUID_BLOCK) {
|
2005-04-17 06:20:36 +08:00
|
|
|
res = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ax25_uid_policy = amount;
|
|
|
|
res = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SIOCADDRT:
|
|
|
|
case SIOCDELRT:
|
|
|
|
case SIOCAX25OPTRT:
|
|
|
|
if (!capable(CAP_NET_ADMIN)) {
|
|
|
|
res = -EPERM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
res = ax25_rt_ioctl(cmd, argp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCAX25CTLCON:
|
|
|
|
if (!capable(CAP_NET_ADMIN)) {
|
|
|
|
res = -EPERM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
res = ax25_ctl_ioctl(cmd, argp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCAX25GETINFO:
|
|
|
|
case SIOCAX25GETINFOOLD: {
|
2015-06-25 21:19:07 +08:00
|
|
|
ax25_cb *ax25 = sk_to_ax25(sk);
|
2005-04-17 06:20:36 +08:00
|
|
|
struct ax25_info_struct ax25_info;
|
|
|
|
|
|
|
|
ax25_info.t1 = ax25->t1 / HZ;
|
|
|
|
ax25_info.t2 = ax25->t2 / HZ;
|
|
|
|
ax25_info.t3 = ax25->t3 / HZ;
|
|
|
|
ax25_info.idle = ax25->idle / (60 * HZ);
|
|
|
|
ax25_info.n2 = ax25->n2;
|
|
|
|
ax25_info.t1timer = ax25_display_timer(&ax25->t1timer) / HZ;
|
|
|
|
ax25_info.t2timer = ax25_display_timer(&ax25->t2timer) / HZ;
|
|
|
|
ax25_info.t3timer = ax25_display_timer(&ax25->t3timer) / HZ;
|
|
|
|
ax25_info.idletimer = ax25_display_timer(&ax25->idletimer) / (60 * HZ);
|
|
|
|
ax25_info.n2count = ax25->n2count;
|
|
|
|
ax25_info.state = ax25->state;
|
2009-09-20 14:32:55 +08:00
|
|
|
ax25_info.rcv_q = sk_rmem_alloc_get(sk);
|
|
|
|
ax25_info.snd_q = sk_wmem_alloc_get(sk);
|
2005-04-17 06:20:36 +08:00
|
|
|
ax25_info.vs = ax25->vs;
|
|
|
|
ax25_info.vr = ax25->vr;
|
|
|
|
ax25_info.va = ax25->va;
|
|
|
|
ax25_info.vs_max = ax25->vs; /* reserved */
|
|
|
|
ax25_info.paclen = ax25->paclen;
|
|
|
|
ax25_info.window = ax25->window;
|
|
|
|
|
|
|
|
/* old structure? */
|
|
|
|
if (cmd == SIOCAX25GETINFOOLD) {
|
|
|
|
static int warned = 0;
|
|
|
|
if (!warned) {
|
|
|
|
printk(KERN_INFO "%s uses old SIOCAX25GETINFO\n",
|
|
|
|
current->comm);
|
|
|
|
warned=1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (copy_to_user(argp, &ax25_info, sizeof(struct ax25_info_struct_deprecated))) {
|
|
|
|
res = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (copy_to_user(argp, &ax25_info, sizeof(struct ax25_info_struct))) {
|
|
|
|
res = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SIOCAX25ADDFWD:
|
|
|
|
case SIOCAX25DELFWD: {
|
|
|
|
struct ax25_fwd_struct ax25_fwd;
|
|
|
|
if (!capable(CAP_NET_ADMIN)) {
|
|
|
|
res = -EPERM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (copy_from_user(&ax25_fwd, argp, sizeof(ax25_fwd))) {
|
|
|
|
res = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
res = ax25_fwd_ioctl(cmd, &ax25_fwd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SIOCGIFADDR:
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
case SIOCGIFDSTADDR:
|
|
|
|
case SIOCSIFDSTADDR:
|
|
|
|
case SIOCGIFBRDADDR:
|
|
|
|
case SIOCSIFBRDADDR:
|
|
|
|
case SIOCGIFNETMASK:
|
|
|
|
case SIOCSIFNETMASK:
|
|
|
|
case SIOCGIFMETRIC:
|
|
|
|
case SIOCSIFMETRIC:
|
|
|
|
res = -EINVAL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2006-01-04 06:18:33 +08:00
|
|
|
res = -ENOIOCTLCMD;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
release_sock(sk);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
|
|
|
|
static void *ax25_info_start(struct seq_file *seq, loff_t *pos)
|
2008-01-14 14:29:41 +08:00
|
|
|
__acquires(ax25_list_lock)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
spin_lock_bh(&ax25_list_lock);
|
2010-02-09 07:19:59 +08:00
|
|
|
return seq_hlist_start(&ax25_list, *pos);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *ax25_info_next(struct seq_file *seq, void *v, loff_t *pos)
|
|
|
|
{
|
2010-02-09 07:19:59 +08:00
|
|
|
return seq_hlist_next(v, &ax25_list, pos);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-02-09 22:24:31 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static void ax25_info_stop(struct seq_file *seq, void *v)
|
2008-01-14 14:29:41 +08:00
|
|
|
__releases(ax25_list_lock)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
spin_unlock_bh(&ax25_list_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ax25_info_show(struct seq_file *seq, void *v)
|
|
|
|
{
|
2010-02-09 07:19:59 +08:00
|
|
|
ax25_cb *ax25 = hlist_entry(v, struct ax25_cb, ax25_node);
|
2005-09-07 06:49:39 +08:00
|
|
|
char buf[11];
|
2005-04-17 06:20:36 +08:00
|
|
|
int k;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* New format:
|
|
|
|
* magic dev src_addr dest_addr,digi1,digi2,.. st vs vr va t1 t1 t2 t2 t3 t3 idle idle n2 n2 rtt window paclen Snd-Q Rcv-Q inode
|
|
|
|
*/
|
|
|
|
|
2019-04-21 19:48:06 +08:00
|
|
|
seq_printf(seq, "%p %s %s%s ",
|
|
|
|
ax25,
|
2005-04-17 06:20:36 +08:00
|
|
|
ax25->ax25_dev == NULL? "???" : ax25->ax25_dev->dev->name,
|
2005-09-07 06:49:39 +08:00
|
|
|
ax2asc(buf, &ax25->source_addr),
|
2005-04-17 06:20:36 +08:00
|
|
|
ax25->iamdigi? "*":"");
|
2005-09-07 06:49:39 +08:00
|
|
|
seq_printf(seq, "%s", ax2asc(buf, &ax25->dest_addr));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
for (k=0; (ax25->digipeat != NULL) && (k < ax25->digipeat->ndigi); k++) {
|
|
|
|
seq_printf(seq, ",%s%s",
|
2005-09-07 06:49:39 +08:00
|
|
|
ax2asc(buf, &ax25->digipeat->calls[k]),
|
2005-04-17 06:20:36 +08:00
|
|
|
ax25->digipeat->repeated[k]? "*":"");
|
|
|
|
}
|
|
|
|
|
|
|
|
seq_printf(seq, " %d %d %d %d %lu %lu %lu %lu %lu %lu %lu %lu %d %d %lu %d %d",
|
|
|
|
ax25->state,
|
|
|
|
ax25->vs, ax25->vr, ax25->va,
|
|
|
|
ax25_display_timer(&ax25->t1timer) / HZ, ax25->t1 / HZ,
|
|
|
|
ax25_display_timer(&ax25->t2timer) / HZ, ax25->t2 / HZ,
|
|
|
|
ax25_display_timer(&ax25->t3timer) / HZ, ax25->t3 / HZ,
|
|
|
|
ax25_display_timer(&ax25->idletimer) / (60 * HZ),
|
|
|
|
ax25->idle / (60 * HZ),
|
|
|
|
ax25->n2count, ax25->n2,
|
|
|
|
ax25->rtt / HZ,
|
|
|
|
ax25->window,
|
|
|
|
ax25->paclen);
|
|
|
|
|
|
|
|
if (ax25->sk != NULL) {
|
2008-02-12 13:24:56 +08:00
|
|
|
seq_printf(seq, " %d %d %lu\n",
|
2009-06-18 10:05:41 +08:00
|
|
|
sk_wmem_alloc_get(ax25->sk),
|
|
|
|
sk_rmem_alloc_get(ax25->sk),
|
2008-02-12 13:24:56 +08:00
|
|
|
sock_i_ino(ax25->sk));
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
seq_puts(seq, " * * *\n");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-11 14:07:31 +08:00
|
|
|
static const struct seq_operations ax25_info_seqops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.start = ax25_info_start,
|
|
|
|
.next = ax25_info_next,
|
|
|
|
.stop = ax25_info_stop,
|
|
|
|
.show = ax25_info_show,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2009-10-05 13:58:39 +08:00
|
|
|
static const struct net_proto_family ax25_family_ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.family = PF_AX25,
|
|
|
|
.create = ax25_create,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
2005-12-23 04:49:22 +08:00
|
|
|
static const struct proto_ops ax25_proto_ops = {
|
2005-09-13 05:25:25 +08:00
|
|
|
.family = PF_AX25,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.release = ax25_release,
|
|
|
|
.bind = ax25_bind,
|
|
|
|
.connect = ax25_connect,
|
|
|
|
.socketpair = sock_no_socketpair,
|
|
|
|
.accept = ax25_accept,
|
|
|
|
.getname = ax25_getname,
|
2018-06-29 00:43:44 +08:00
|
|
|
.poll = datagram_poll,
|
2005-09-13 05:25:25 +08:00
|
|
|
.ioctl = ax25_ioctl,
|
2019-04-18 04:51:48 +08:00
|
|
|
.gettstamp = sock_gettstamp,
|
2005-09-13 05:25:25 +08:00
|
|
|
.listen = ax25_listen,
|
|
|
|
.shutdown = ax25_shutdown,
|
|
|
|
.setsockopt = ax25_setsockopt,
|
|
|
|
.getsockopt = ax25_getsockopt,
|
|
|
|
.sendmsg = ax25_sendmsg,
|
|
|
|
.recvmsg = ax25_recvmsg,
|
|
|
|
.mmap = sock_no_mmap,
|
|
|
|
.sendpage = sock_no_sendpage,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called by socket.c on kernel start up
|
|
|
|
*/
|
2009-03-09 16:18:29 +08:00
|
|
|
static struct packet_type ax25_packet_type __read_mostly = {
|
2009-02-01 16:45:17 +08:00
|
|
|
.type = cpu_to_be16(ETH_P_AX25),
|
2005-04-17 06:20:36 +08:00
|
|
|
.func = ax25_kiss_rcv,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct notifier_block ax25_dev_notifier = {
|
2013-05-28 09:30:21 +08:00
|
|
|
.notifier_call = ax25_device_event,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init ax25_init(void)
|
|
|
|
{
|
|
|
|
int rc = proto_register(&ax25_proto, 0);
|
|
|
|
|
|
|
|
if (rc != 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
sock_register(&ax25_family_ops);
|
|
|
|
dev_add_pack(&ax25_packet_type);
|
|
|
|
register_netdevice_notifier(&ax25_dev_notifier);
|
|
|
|
|
2018-04-14 01:44:18 +08:00
|
|
|
proc_create_seq("ax25_route", 0444, init_net.proc_net, &ax25_rt_seqops);
|
|
|
|
proc_create_seq("ax25", 0444, init_net.proc_net, &ax25_info_seqops);
|
|
|
|
proc_create_seq("ax25_calls", 0444, init_net.proc_net,
|
|
|
|
&ax25_uid_seqops);
|
2005-04-17 06:20:36 +08:00
|
|
|
out:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
module_init(ax25_init);
|
|
|
|
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Jonathan Naylor G4KLX <g4klx@g4klx.demon.co.uk>");
|
|
|
|
MODULE_DESCRIPTION("The amateur radio AX.25 link layer protocol");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS_NETPROTO(PF_AX25);
|
|
|
|
|
|
|
|
static void __exit ax25_exit(void)
|
|
|
|
{
|
2013-02-18 09:34:56 +08:00
|
|
|
remove_proc_entry("ax25_route", init_net.proc_net);
|
|
|
|
remove_proc_entry("ax25", init_net.proc_net);
|
|
|
|
remove_proc_entry("ax25_calls", init_net.proc_net);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
unregister_netdevice_notifier(&ax25_dev_notifier);
|
|
|
|
|
|
|
|
dev_remove_pack(&ax25_packet_type);
|
|
|
|
|
|
|
|
sock_unregister(PF_AX25);
|
|
|
|
proto_unregister(&ax25_proto);
|
2012-04-19 00:11:23 +08:00
|
|
|
|
|
|
|
ax25_rt_free();
|
|
|
|
ax25_uid_free();
|
|
|
|
ax25_dev_free();
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
module_exit(ax25_exit);
|