]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commit
ax25: NPD bug when detaching AX25 device
authorLin Ma <linma@zju.edu.cn>
Fri, 17 Dec 2021 02:29:41 +0000 (10:29 +0800)
committerStefan Bader <stefan.bader@canonical.com>
Mon, 7 Mar 2022 15:34:36 +0000 (16:34 +0100)
commit7de372dd1704111edfe42a56468ac5e4c2b712b7
treed760c8e653d8e144d1d66c329141f909e470aee8
parentc7566aab1fd94d2c95d487b8c2604e5ac6770466
ax25: NPD bug when detaching AX25 device

BugLink: https://bugs.launchpad.net/bugs/1958557
commit 1ade48d0c27d5da1ccf4b583d8c5fc8b534a3ac8 upstream.

The existing cleanup routine implementation is not well synchronized
with the syscall routine. When a device is detaching, below race could
occur.

static int ax25_sendmsg(...) {
  ...
  lock_sock()
  ax25 = sk_to_ax25(sk);
  if (ax25->ax25_dev == NULL) // CHECK
  ...
  ax25_queue_xmit(skb, ax25->ax25_dev->dev); // USE
  ...
}

static void ax25_kill_by_device(...) {
  ...
  if (s->ax25_dev == ax25_dev) {
    s->ax25_dev = NULL;
    ...
}

Other syscall functions like ax25_getsockopt, ax25_getname,
ax25_info_show also suffer from similar races. To fix them, this patch
introduce lock_sock() into ax25_kill_by_device in order to guarantee
that the nullify action in cleanup routine cannot proceed when another
socket request is pending.

Signed-off-by: Hanjie Wu <nagi@zju.edu.cn>
Signed-off-by: Lin Ma <linma@zju.edu.cn>
Signed-off-by: David S. Miller <davem@davemloft.net>
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>
net/ax25/af_ax25.c