summaryrefslogtreecommitdiffstats
path: root/include/net
diff options
context:
space:
mode:
authorDuoming Zhou <duoming@zju.edu.cn>2022-04-21 13:24:15 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-04-27 13:39:45 +0200
commite2b558fe507a1ed4c43db2b0057fc6e41f20a14c (patch)
tree0c6822721b1acf6100f5e0131d8ba41a84e922f7 /include/net
parentace51abe0f3a92d512440291f8a47e2cb094ca74 (diff)
downloadlinux-stable-e2b558fe507a1ed4c43db2b0057fc6e41f20a14c.tar.gz
linux-stable-e2b558fe507a1ed4c43db2b0057fc6e41f20a14c.tar.bz2
linux-stable-e2b558fe507a1ed4c43db2b0057fc6e41f20a14c.zip
ax25: add refcount in ax25_dev to avoid UAF bugs
commit d01ffb9eee4af165d83b08dd73ebdf9fe94a519b upstream. 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> [OP: backport to 4.19: adjusted context] Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include/net')
-rw-r--r--include/net/ax25.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/include/net/ax25.h b/include/net/ax25.h
index 8b7eb46ad72d..d81bfb674906 100644
--- a/include/net/ax25.h
+++ b/include/net/ax25.h
@@ -236,6 +236,7 @@ typedef struct ax25_dev {
#if defined(CONFIG_AX25_DAMA_SLAVE) || defined(CONFIG_AX25_DAMA_MASTER)
ax25_dama_info dama;
#endif
+ refcount_t refcount;
} ax25_dev;
typedef struct ax25_cb {
@@ -290,6 +291,15 @@ static __inline__ void ax25_cb_put(ax25_cb *ax25)
}
}
+#define ax25_dev_hold(__ax25_dev) \
+ refcount_inc(&((__ax25_dev)->refcount))
+
+static __inline__ void ax25_dev_put(ax25_dev *ax25_dev)
+{
+ if (refcount_dec_and_test(&ax25_dev->refcount)) {
+ kfree(ax25_dev);
+ }
+}
static inline __be16 ax25_type_trans(struct sk_buff *skb, struct net_device *dev)
{
skb->dev = dev;