* [PATCH v2] vhost/vsock: don't check owner in vhost_vsock_stop() while releasing
@ 2022-02-22 9:47 Stefano Garzarella
2022-02-23 2:09 ` Jason Wang
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Stefano Garzarella @ 2022-02-22 9:47 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Stefan Hajnoczi, Jason Wang, netdev, virtualization,
Stefano Garzarella, syzbot+1e3ea63db39f2b4440e0, kvm,
Anirudh Rayabharam, syzbot+3140b17cb44a7b174008, linux-kernel,
Mike Christie, Dan Carpenter, stable
vhost_vsock_stop() calls vhost_dev_check_owner() to check the device
ownership. It expects current->mm to be valid.
vhost_vsock_stop() is also called by vhost_vsock_dev_release() when
the user has not done close(), so when we are in do_exit(). In this
case current->mm is invalid and we're releasing the device, so we
should clean it anyway.
Let's check the owner only when vhost_vsock_stop() is called
by an ioctl.
When invoked from release we can not fail so we don't check return
code of vhost_vsock_stop(). We need to stop vsock even if it's not
the owner.
Fixes: 433fc58e6bf2 ("VSOCK: Introduce vhost_vsock.ko")
Cc: stable@vger.kernel.org
Reported-by: syzbot+1e3ea63db39f2b4440e0@syzkaller.appspotmail.com
Reported-and-tested-by: syzbot+3140b17cb44a7b174008@syzkaller.appspotmail.com
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
v2:
- initialized `ret` in vhost_vsock_stop [Dan]
- added comment about vhost_vsock_stop() calling in the code and an explanation
in the commit message [MST]
v1: https://lore.kernel.org/virtualization/20220221114916.107045-1-sgarzare@redhat.com
---
drivers/vhost/vsock.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
index d6ca1c7ad513..37f0b4274113 100644
--- a/drivers/vhost/vsock.c
+++ b/drivers/vhost/vsock.c
@@ -629,16 +629,18 @@ static int vhost_vsock_start(struct vhost_vsock *vsock)
return ret;
}
-static int vhost_vsock_stop(struct vhost_vsock *vsock)
+static int vhost_vsock_stop(struct vhost_vsock *vsock, bool check_owner)
{
size_t i;
- int ret;
+ int ret = 0;
mutex_lock(&vsock->dev.mutex);
- ret = vhost_dev_check_owner(&vsock->dev);
- if (ret)
- goto err;
+ if (check_owner) {
+ ret = vhost_dev_check_owner(&vsock->dev);
+ if (ret)
+ goto err;
+ }
for (i = 0; i < ARRAY_SIZE(vsock->vqs); i++) {
struct vhost_virtqueue *vq = &vsock->vqs[i];
@@ -753,7 +755,12 @@ static int vhost_vsock_dev_release(struct inode *inode, struct file *file)
* inefficient. Room for improvement here. */
vsock_for_each_connected_socket(vhost_vsock_reset_orphans);
- vhost_vsock_stop(vsock);
+ /* Don't check the owner, because we are in the release path, so we
+ * need to stop the vsock device in any case.
+ * vhost_vsock_stop() can not fail in this case, so we don't need to
+ * check the return code.
+ */
+ vhost_vsock_stop(vsock, false);
vhost_vsock_flush(vsock);
vhost_dev_stop(&vsock->dev);
@@ -868,7 +875,7 @@ static long vhost_vsock_dev_ioctl(struct file *f, unsigned int ioctl,
if (start)
return vhost_vsock_start(vsock);
else
- return vhost_vsock_stop(vsock);
+ return vhost_vsock_stop(vsock, true);
case VHOST_GET_FEATURES:
features = VHOST_VSOCK_FEATURES;
if (copy_to_user(argp, &features, sizeof(features)))
--
2.35.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] vhost/vsock: don't check owner in vhost_vsock_stop() while releasing
2022-02-22 9:47 [PATCH v2] vhost/vsock: don't check owner in vhost_vsock_stop() while releasing Stefano Garzarella
@ 2022-02-23 2:09 ` Jason Wang
2022-02-23 12:40 ` patchwork-bot+netdevbpf
2022-02-24 8:53 ` Stefan Hajnoczi
2 siblings, 0 replies; 4+ messages in thread
From: Jason Wang @ 2022-02-23 2:09 UTC (permalink / raw)
To: Stefano Garzarella
Cc: Michael S. Tsirkin, Stefan Hajnoczi, netdev, virtualization,
syzbot, kvm, Anirudh Rayabharam, syzbot+3140b17cb44a7b174008,
linux-kernel, Mike Christie, Dan Carpenter, stable
On Tue, Feb 22, 2022 at 5:47 PM Stefano Garzarella <sgarzare@redhat.com> wrote:
>
> vhost_vsock_stop() calls vhost_dev_check_owner() to check the device
> ownership. It expects current->mm to be valid.
>
> vhost_vsock_stop() is also called by vhost_vsock_dev_release() when
> the user has not done close(), so when we are in do_exit(). In this
> case current->mm is invalid and we're releasing the device, so we
> should clean it anyway.
>
> Let's check the owner only when vhost_vsock_stop() is called
> by an ioctl.
>
> When invoked from release we can not fail so we don't check return
> code of vhost_vsock_stop(). We need to stop vsock even if it's not
> the owner.
>
> Fixes: 433fc58e6bf2 ("VSOCK: Introduce vhost_vsock.ko")
> Cc: stable@vger.kernel.org
> Reported-by: syzbot+1e3ea63db39f2b4440e0@syzkaller.appspotmail.com
> Reported-and-tested-by: syzbot+3140b17cb44a7b174008@syzkaller.appspotmail.com
> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
> ---
> v2:
> - initialized `ret` in vhost_vsock_stop [Dan]
> - added comment about vhost_vsock_stop() calling in the code and an explanation
> in the commit message [MST]
>
> v1: https://lore.kernel.org/virtualization/20220221114916.107045-1-sgarzare@redhat.com
> ---
> drivers/vhost/vsock.c | 21 ++++++++++++++-------
> 1 file changed, 14 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
> index d6ca1c7ad513..37f0b4274113 100644
> --- a/drivers/vhost/vsock.c
> +++ b/drivers/vhost/vsock.c
> @@ -629,16 +629,18 @@ static int vhost_vsock_start(struct vhost_vsock *vsock)
> return ret;
> }
>
> -static int vhost_vsock_stop(struct vhost_vsock *vsock)
> +static int vhost_vsock_stop(struct vhost_vsock *vsock, bool check_owner)
> {
> size_t i;
> - int ret;
> + int ret = 0;
>
> mutex_lock(&vsock->dev.mutex);
>
> - ret = vhost_dev_check_owner(&vsock->dev);
> - if (ret)
> - goto err;
> + if (check_owner) {
> + ret = vhost_dev_check_owner(&vsock->dev);
> + if (ret)
> + goto err;
> + }
>
> for (i = 0; i < ARRAY_SIZE(vsock->vqs); i++) {
> struct vhost_virtqueue *vq = &vsock->vqs[i];
> @@ -753,7 +755,12 @@ static int vhost_vsock_dev_release(struct inode *inode, struct file *file)
> * inefficient. Room for improvement here. */
> vsock_for_each_connected_socket(vhost_vsock_reset_orphans);
>
> - vhost_vsock_stop(vsock);
> + /* Don't check the owner, because we are in the release path, so we
> + * need to stop the vsock device in any case.
> + * vhost_vsock_stop() can not fail in this case, so we don't need to
> + * check the return code.
> + */
> + vhost_vsock_stop(vsock, false);
> vhost_vsock_flush(vsock);
> vhost_dev_stop(&vsock->dev);
>
> @@ -868,7 +875,7 @@ static long vhost_vsock_dev_ioctl(struct file *f, unsigned int ioctl,
> if (start)
> return vhost_vsock_start(vsock);
> else
> - return vhost_vsock_stop(vsock);
> + return vhost_vsock_stop(vsock, true);
> case VHOST_GET_FEATURES:
> features = VHOST_VSOCK_FEATURES;
> if (copy_to_user(argp, &features, sizeof(features)))
> --
> 2.35.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] vhost/vsock: don't check owner in vhost_vsock_stop() while releasing
2022-02-22 9:47 [PATCH v2] vhost/vsock: don't check owner in vhost_vsock_stop() while releasing Stefano Garzarella
2022-02-23 2:09 ` Jason Wang
@ 2022-02-23 12:40 ` patchwork-bot+netdevbpf
2022-02-24 8:53 ` Stefan Hajnoczi
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-02-23 12:40 UTC (permalink / raw)
To: Stefano Garzarella
Cc: mst, stefanha, jasowang, netdev, virtualization,
syzbot+1e3ea63db39f2b4440e0, kvm, mail,
syzbot+3140b17cb44a7b174008, linux-kernel, michael.christie,
dan.carpenter, stable
Hello:
This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:
On Tue, 22 Feb 2022 10:47:42 +0100 you wrote:
> vhost_vsock_stop() calls vhost_dev_check_owner() to check the device
> ownership. It expects current->mm to be valid.
>
> vhost_vsock_stop() is also called by vhost_vsock_dev_release() when
> the user has not done close(), so when we are in do_exit(). In this
> case current->mm is invalid and we're releasing the device, so we
> should clean it anyway.
>
> [...]
Here is the summary with links:
- [v2] vhost/vsock: don't check owner in vhost_vsock_stop() while releasing
https://git.kernel.org/netdev/net/c/a58da53ffd70
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] vhost/vsock: don't check owner in vhost_vsock_stop() while releasing
2022-02-22 9:47 [PATCH v2] vhost/vsock: don't check owner in vhost_vsock_stop() while releasing Stefano Garzarella
2022-02-23 2:09 ` Jason Wang
2022-02-23 12:40 ` patchwork-bot+netdevbpf
@ 2022-02-24 8:53 ` Stefan Hajnoczi
2 siblings, 0 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2022-02-24 8:53 UTC (permalink / raw)
To: Stefano Garzarella
Cc: Michael S. Tsirkin, Jason Wang, netdev, virtualization,
syzbot+1e3ea63db39f2b4440e0, kvm, Anirudh Rayabharam,
syzbot+3140b17cb44a7b174008, linux-kernel, Mike Christie,
Dan Carpenter, stable
[-- Attachment #1: Type: text/plain, Size: 1418 bytes --]
On Tue, Feb 22, 2022 at 10:47:42AM +0100, Stefano Garzarella wrote:
> vhost_vsock_stop() calls vhost_dev_check_owner() to check the device
> ownership. It expects current->mm to be valid.
>
> vhost_vsock_stop() is also called by vhost_vsock_dev_release() when
> the user has not done close(), so when we are in do_exit(). In this
> case current->mm is invalid and we're releasing the device, so we
> should clean it anyway.
>
> Let's check the owner only when vhost_vsock_stop() is called
> by an ioctl.
>
> When invoked from release we can not fail so we don't check return
> code of vhost_vsock_stop(). We need to stop vsock even if it's not
> the owner.
>
> Fixes: 433fc58e6bf2 ("VSOCK: Introduce vhost_vsock.ko")
> Cc: stable@vger.kernel.org
> Reported-by: syzbot+1e3ea63db39f2b4440e0@syzkaller.appspotmail.com
> Reported-and-tested-by: syzbot+3140b17cb44a7b174008@syzkaller.appspotmail.com
> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
> ---
> v2:
> - initialized `ret` in vhost_vsock_stop [Dan]
> - added comment about vhost_vsock_stop() calling in the code and an explanation
> in the commit message [MST]
>
> v1: https://lore.kernel.org/virtualization/20220221114916.107045-1-sgarzare@redhat.com
> ---
> drivers/vhost/vsock.c | 21 ++++++++++++++-------
> 1 file changed, 14 insertions(+), 7 deletions(-)
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-02-24 8:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-22 9:47 [PATCH v2] vhost/vsock: don't check owner in vhost_vsock_stop() while releasing Stefano Garzarella
2022-02-23 2:09 ` Jason Wang
2022-02-23 12:40 ` patchwork-bot+netdevbpf
2022-02-24 8:53 ` Stefan Hajnoczi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).