]> git.proxmox.com Git - mirror_qemu.git/commit
block/nbd: fix possible use after free of s->connect_thread
authorVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Tue, 6 Apr 2021 15:51:14 +0000 (18:51 +0300)
committerMax Reitz <mreitz@redhat.com>
Tue, 13 Apr 2021 13:35:12 +0000 (15:35 +0200)
commit0267101af64292c9a84fd9319a763ddfbce9ddc7
tree1fdbfb0a65f1afd795e6e5b8baa2ed1e00ae4ac6
parentdce628a97fde2594f99d738883a157f05aa0a14f
block/nbd: fix possible use after free of s->connect_thread

If on nbd_close() we detach the thread (in
nbd_co_establish_connection_cancel() thr->state becomes
CONNECT_THREAD_RUNNING_DETACHED), after that point we should not use
s->connect_thread (which is set to NULL), as running thread may free it
at any time.

Still nbd_co_establish_connection() does exactly this: it saves
s->connect_thread to local variable (just for better code style) and
use it even after yield point, when thread may be already detached.

Fix that. Also check thr to be non-NULL on
nbd_co_establish_connection() start for safety.

After this patch "case CONNECT_THREAD_RUNNING_DETACHED" becomes
impossible in the second switch in nbd_co_establish_connection().
Still, don't add extra abort() just before the release. If it somehow
possible to reach this "case:" it won't hurt. Anyway, good refactoring
of all this reconnect mess will come soon.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210406155114.1057355-1-vsementsov@virtuozzo.com>
Reviewed-by: Roman Kagan <rvkagan@yandex-team.ru>
Signed-off-by: Max Reitz <mreitz@redhat.com>
block/nbd.c