Drivers: hv: vmbus: Avoid use-after-free in vmbus_onoffer_rescind()
authorAndrea Parri (Microsoft) <parri.andrea@gmail.com>
Wed, 9 Dec 2020 07:08:25 +0000 (08:08 +0100)
committerWei Liu <wei.liu@kernel.org>
Fri, 5 Feb 2021 09:55:42 +0000 (09:55 +0000)
When channel->device_obj is non-NULL, vmbus_onoffer_rescind() could
invoke put_device(), that will eventually release the device and free
the channel object (cf. vmbus_device_release()).  However, a pointer
to the object is dereferenced again later to load the primary_channel.
The use-after-free can be avoided by noticing that this load/check is
redundant if device_obj is non-NULL: primary_channel must be NULL if
device_obj is non-NULL, cf. vmbus_add_channel_work().

Fixes: 54a66265d6754b ("Drivers: hv: vmbus: Fix rescind handling")
Reported-by: Juan Vazquez <juvazq@microsoft.com>
Signed-off-by: Andrea Parri (Microsoft) <parri.andrea@gmail.com>
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
Link: https://lore.kernel.org/r/20201209070827.29335-5-parri.andrea@gmail.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
drivers/hv/channel_mgmt.c

index 5bc5eef5da15948d73334410f31a11199eae9431..4072fd1f22146e6e4759ff6318685b2ee167c335 100644 (file)
@@ -1116,8 +1116,7 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr)
                        vmbus_device_unregister(channel->device_obj);
                        put_device(dev);
                }
-       }
-       if (channel->primary_channel != NULL) {
+       } else if (channel->primary_channel != NULL) {
                /*
                 * Sub-channel is being rescinded. Following is the channel
                 * close sequence when initiated from the driveri (refer to