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) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
|
|
|
|
*/
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/socket.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 <linux/in.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/sockios.h>
|
|
|
|
#include <linux/net.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#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/mm.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
|
|
|
|
ax25_dev *ax25_dev_list;
|
|
|
|
DEFINE_SPINLOCK(ax25_dev_lock);
|
|
|
|
|
|
|
|
ax25_dev *ax25_addr_ax25dev(ax25_address *addr)
|
|
|
|
{
|
|
|
|
ax25_dev *ax25_dev, *res = NULL;
|
|
|
|
|
|
|
|
spin_lock_bh(&ax25_dev_lock);
|
|
|
|
for (ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next)
|
2021-10-12 23:58:35 +08:00
|
|
|
if (ax25cmp(addr, (const ax25_address *)ax25_dev->dev->dev_addr) == 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
res = ax25_dev;
|
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_hold(ax25_dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
spin_unlock_bh(&ax25_dev_lock);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is called when an interface is brought up. These are
|
|
|
|
* reasonable defaults.
|
|
|
|
*/
|
|
|
|
void ax25_dev_device_up(struct net_device *dev)
|
|
|
|
{
|
|
|
|
ax25_dev *ax25_dev;
|
|
|
|
|
2006-07-10 03:14:22 +08:00
|
|
|
if ((ax25_dev = kzalloc(sizeof(*ax25_dev), GFP_ATOMIC)) == NULL) {
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(KERN_ERR "AX.25: ax25_dev_device_up - out of memory\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
refcount_set(&ax25_dev->refcount, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
dev->ax25_ptr = ax25_dev;
|
|
|
|
ax25_dev->dev = dev;
|
2021-12-07 09:30:33 +08:00
|
|
|
dev_hold_track(dev, &ax25_dev->dev_tracker, GFP_ATOMIC);
|
2005-04-17 06:20:36 +08:00
|
|
|
ax25_dev->forward = NULL;
|
|
|
|
|
|
|
|
ax25_dev->values[AX25_VALUES_IPDEFMODE] = AX25_DEF_IPDEFMODE;
|
|
|
|
ax25_dev->values[AX25_VALUES_AXDEFMODE] = AX25_DEF_AXDEFMODE;
|
|
|
|
ax25_dev->values[AX25_VALUES_BACKOFF] = AX25_DEF_BACKOFF;
|
|
|
|
ax25_dev->values[AX25_VALUES_CONMODE] = AX25_DEF_CONMODE;
|
|
|
|
ax25_dev->values[AX25_VALUES_WINDOW] = AX25_DEF_WINDOW;
|
|
|
|
ax25_dev->values[AX25_VALUES_EWINDOW] = AX25_DEF_EWINDOW;
|
|
|
|
ax25_dev->values[AX25_VALUES_T1] = AX25_DEF_T1;
|
|
|
|
ax25_dev->values[AX25_VALUES_T2] = AX25_DEF_T2;
|
|
|
|
ax25_dev->values[AX25_VALUES_T3] = AX25_DEF_T3;
|
|
|
|
ax25_dev->values[AX25_VALUES_IDLE] = AX25_DEF_IDLE;
|
|
|
|
ax25_dev->values[AX25_VALUES_N2] = AX25_DEF_N2;
|
|
|
|
ax25_dev->values[AX25_VALUES_PACLEN] = AX25_DEF_PACLEN;
|
|
|
|
ax25_dev->values[AX25_VALUES_PROTOCOL] = AX25_DEF_PROTOCOL;
|
|
|
|
ax25_dev->values[AX25_VALUES_DS_TIMEOUT]= AX25_DEF_DS_TIMEOUT;
|
|
|
|
|
|
|
|
#if defined(CONFIG_AX25_DAMA_SLAVE) || defined(CONFIG_AX25_DAMA_MASTER)
|
2008-02-12 13:38:32 +08:00
|
|
|
ax25_ds_setup_timer(ax25_dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
spin_lock_bh(&ax25_dev_lock);
|
|
|
|
ax25_dev->next = ax25_dev_list;
|
|
|
|
ax25_dev_list = ax25_dev;
|
|
|
|
spin_unlock_bh(&ax25_dev_lock);
|
2022-02-03 23:08:11 +08:00
|
|
|
ax25_dev_hold(ax25_dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-04-19 21:34:18 +08:00
|
|
|
ax25_register_dev_sysctl(ax25_dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ax25_dev_device_down(struct net_device *dev)
|
|
|
|
{
|
|
|
|
ax25_dev *s, *ax25_dev;
|
|
|
|
|
|
|
|
if ((ax25_dev = ax25_dev_ax25dev(dev)) == NULL)
|
|
|
|
return;
|
|
|
|
|
2012-04-19 21:34:18 +08:00
|
|
|
ax25_unregister_dev_sysctl(ax25_dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_lock_bh(&ax25_dev_lock);
|
|
|
|
|
|
|
|
#ifdef CONFIG_AX25_DAMA_SLAVE
|
|
|
|
ax25_ds_del_timer(ax25_dev);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove any packet forwarding that points to this device.
|
|
|
|
*/
|
|
|
|
for (s = ax25_dev_list; s != NULL; s = s->next)
|
|
|
|
if (s->forward == dev)
|
|
|
|
s->forward = NULL;
|
|
|
|
|
|
|
|
if ((s = ax25_dev_list) == ax25_dev) {
|
|
|
|
ax25_dev_list = s->next;
|
|
|
|
spin_unlock_bh(&ax25_dev_lock);
|
2022-02-03 23:08:11 +08:00
|
|
|
ax25_dev_put(ax25_dev);
|
2018-12-30 05:56:36 +08:00
|
|
|
dev->ax25_ptr = NULL;
|
2021-12-07 09:30:33 +08:00
|
|
|
dev_put_track(dev, &ax25_dev->dev_tracker);
|
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);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (s != NULL && s->next != NULL) {
|
|
|
|
if (s->next == ax25_dev) {
|
|
|
|
s->next = ax25_dev->next;
|
|
|
|
spin_unlock_bh(&ax25_dev_lock);
|
2022-02-03 23:08:11 +08:00
|
|
|
ax25_dev_put(ax25_dev);
|
2018-12-30 05:56:36 +08:00
|
|
|
dev->ax25_ptr = NULL;
|
2021-12-07 09:30:33 +08:00
|
|
|
dev_put_track(dev, &ax25_dev->dev_tracker);
|
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);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
s = s->next;
|
|
|
|
}
|
|
|
|
spin_unlock_bh(&ax25_dev_lock);
|
|
|
|
dev->ax25_ptr = NULL;
|
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);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int ax25_fwd_ioctl(unsigned int cmd, struct ax25_fwd_struct *fwd)
|
|
|
|
{
|
|
|
|
ax25_dev *ax25_dev, *fwd_dev;
|
|
|
|
|
|
|
|
if ((ax25_dev = ax25_addr_ax25dev(&fwd->port_from)) == NULL)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SIOCAX25ADDFWD:
|
2022-02-03 23:08:11 +08:00
|
|
|
fwd_dev = ax25_addr_ax25dev(&fwd->port_to);
|
|
|
|
if (!fwd_dev) {
|
|
|
|
ax25_dev_put(ax25_dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
2022-02-03 23:08:11 +08:00
|
|
|
}
|
|
|
|
if (ax25_dev->forward) {
|
|
|
|
ax25_dev_put(fwd_dev);
|
|
|
|
ax25_dev_put(ax25_dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
2022-02-03 23:08:11 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
ax25_dev->forward = fwd_dev->dev;
|
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(fwd_dev);
|
2022-02-03 23:08:11 +08:00
|
|
|
ax25_dev_put(ax25_dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCAX25DELFWD:
|
2022-02-03 23:08:11 +08:00
|
|
|
if (!ax25_dev->forward) {
|
|
|
|
ax25_dev_put(ax25_dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
2022-02-03 23:08:11 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
ax25_dev->forward = NULL;
|
2022-02-03 23:08:11 +08:00
|
|
|
ax25_dev_put(ax25_dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-02-03 23:08:11 +08:00
|
|
|
ax25_dev_put(ax25_dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct net_device *ax25_fwd_dev(struct net_device *dev)
|
|
|
|
{
|
|
|
|
ax25_dev *ax25_dev;
|
|
|
|
|
|
|
|
if ((ax25_dev = ax25_dev_ax25dev(dev)) == NULL)
|
|
|
|
return dev;
|
|
|
|
|
|
|
|
if (ax25_dev->forward == NULL)
|
|
|
|
return dev;
|
|
|
|
|
|
|
|
return ax25_dev->forward;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free all memory associated with device structures.
|
|
|
|
*/
|
|
|
|
void __exit ax25_dev_free(void)
|
|
|
|
{
|
|
|
|
ax25_dev *s, *ax25_dev;
|
|
|
|
|
|
|
|
spin_lock_bh(&ax25_dev_lock);
|
|
|
|
ax25_dev = ax25_dev_list;
|
|
|
|
while (ax25_dev != NULL) {
|
|
|
|
s = ax25_dev;
|
2021-12-07 09:30:33 +08:00
|
|
|
dev_put_track(ax25_dev->dev, &ax25_dev->dev_tracker);
|
2005-04-17 06:20:36 +08:00
|
|
|
ax25_dev = ax25_dev->next;
|
|
|
|
kfree(s);
|
|
|
|
}
|
|
|
|
ax25_dev_list = NULL;
|
|
|
|
spin_unlock_bh(&ax25_dev_lock);
|
|
|
|
}
|