]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
ax25: add refcount in ax25_dev to avoid UAF bugs
authorDuoming Zhou <duoming@zju.edu.cn>
Fri, 15 Apr 2022 16:14:15 +0000 (19:14 +0300)
committerStefan Bader <stefan.bader@canonical.com>
Wed, 27 Apr 2022 10:01:05 +0000 (12:01 +0200)
commitadf70120d7e7b32ce1333f965af7e5afeb43f2ce
tree906d560264a3a9ccc6a6554b5081f823aca38b3e
parent30e2763f839e2b9ba4e099242351d3d0c0a8f69a
ax25: add refcount in ax25_dev to avoid UAF bugs

BugLink: https://bugs.launchpad.net/bugs/1969857
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 5.15: adjusted context]
Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
include/net/ax25.h
net/ax25/af_ax25.c
net/ax25/ax25_dev.c
net/ax25/ax25_route.c