OSDN Git Service

vsock: fix the race conditions in multi-transport support
authorAlexander Popov <alex.popov@linux.com>
Mon, 1 Feb 2021 08:47:19 +0000 (11:47 +0300)
committerJakub Kicinski <kuba@kernel.org>
Tue, 2 Feb 2021 03:54:30 +0000 (19:54 -0800)
commitc518adafa39f37858697ac9309c6cf1805581446
tree3210f168d0994023031222b8cce28bc546e3137a
parent938e0fcd3253efdef8924714158911286d08cfe1
vsock: fix the race conditions in multi-transport support

There are multiple similar bugs implicitly introduced by the
commit c0cfa2d8a788fcf4 ("vsock: add multi-transports support") and
commit 6a2c0962105ae8ce ("vsock: prevent transport modules unloading").

The bug pattern:
 [1] vsock_sock.transport pointer is copied to a local variable,
 [2] lock_sock() is called,
 [3] the local variable is used.
VSOCK multi-transport support introduced the race condition:
vsock_sock.transport value may change between [1] and [2].

Let's copy vsock_sock.transport pointer to local variables after
the lock_sock() call.

Fixes: c0cfa2d8a788fcf4 ("vsock: add multi-transports support")
Signed-off-by: Alexander Popov <alex.popov@linux.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Reviewed-by: Jorgen Hansen <jhansen@vmware.com>
Link: https://lore.kernel.org/r/20210201084719.2257066-1-alex.popov@linux.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/vmw_vsock/af_vsock.c