Stefano Garzarella
2022-Feb-21 11:49 UTC
[PATCH] vhost/vsock: don't check owner in vhost_vsock_stop() while releasing
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. Fixes: 433fc58e6bf2 ("VSOCK: Introduce vhost_vsock.ko") Cc: stable at vger.kernel.org Reported-by: syzbot+1e3ea63db39f2b4440e0 at syzkaller.appspotmail.com Signed-off-by: Stefano Garzarella <sgarzare at redhat.com> --- drivers/vhost/vsock.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index d6ca1c7ad513..f00d2dfd72b7 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; 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,7 @@ 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); + vhost_vsock_stop(vsock, false); vhost_vsock_flush(vsock); vhost_dev_stop(&vsock->dev); @@ -868,7 +870,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
Stefano Garzarella
2022-Feb-21 13:59 UTC
[PATCH] vhost/vsock: don't check owner in vhost_vsock_stop() while releasing
On Mon, Feb 21, 2022 at 12:49 PM Stefano Garzarella <sgarzare at 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. > > Fixes: 433fc58e6bf2 ("VSOCK: Introduce vhost_vsock.ko") > Cc: stable at vger.kernel.org > Reported-by: syzbot+1e3ea63db39f2b4440e0 at syzkaller.appspotmail.com > Signed-off-by: Stefano Garzarella <sgarzare at redhat.com> > --- > drivers/vhost/vsock.c | 14 ++++++++------ > 1 file changed, 8 insertions(+), 6 deletions(-)Reported-and-tested-by: syzbot+0abd373e2e50d704db87 at syzkaller.appspotmail.com Reported-and-tested-by: syzbot+3140b17cb44a7b174008 at syzkaller.appspotmail.com
Michael S. Tsirkin
2022-Feb-21 15:03 UTC
[PATCH] vhost/vsock: don't check owner in vhost_vsock_stop() while releasing
On Mon, Feb 21, 2022 at 12:49:16PM +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.> Fixes: 433fc58e6bf2 ("VSOCK: Introduce vhost_vsock.ko") > Cc: stable at vger.kernel.org > Reported-by: syzbot+1e3ea63db39f2b4440e0 at syzkaller.appspotmail.com > Signed-off-by: Stefano Garzarella <sgarzare at redhat.com> > --- > drivers/vhost/vsock.c | 14 ++++++++------ > 1 file changed, 8 insertions(+), 6 deletions(-) > > diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c > index d6ca1c7ad513..f00d2dfd72b7 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; > > 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,7 @@ 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);Let's add an explanation: 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.> + vhost_vsock_stop(vsock, false); > vhost_vsock_flush(vsock); > vhost_dev_stop(&vsock->dev); > > @@ -868,7 +870,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
Dan Carpenter
2022-Feb-22 05:30 UTC
[PATCH] vhost/vsock: don't check owner in vhost_vsock_stop() while releasing
Hi Stefano, url: https://github.com/0day-ci/linux/commits/Stefano-Garzarella/vhost-vsock-don-t-check-owner-in-vhost_vsock_stop-while-releasing/20220221-195038 base: https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git linux-next config: x86_64-randconfig-m031-20220221 (https://download.01.org/0day-ci/archive/20220222/202202220707.AM3rKUcP-lkp at intel.com/config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp at intel.com> Reported-by: Dan Carpenter <dan.carpenter at oracle.com> smatch warnings: drivers/vhost/vsock.c:655 vhost_vsock_stop() error: uninitialized symbol 'ret'. vim +/ret +655 drivers/vhost/vsock.c 3ace84c91bfcde Stefano Garzarella 2022-02-21 632 static int vhost_vsock_stop(struct vhost_vsock *vsock, bool check_owner) 433fc58e6bf2c8 Asias He 2016-07-28 633 { 433fc58e6bf2c8 Asias He 2016-07-28 634 size_t i; 433fc58e6bf2c8 Asias He 2016-07-28 635 int ret; 433fc58e6bf2c8 Asias He 2016-07-28 636 433fc58e6bf2c8 Asias He 2016-07-28 637 mutex_lock(&vsock->dev.mutex); 433fc58e6bf2c8 Asias He 2016-07-28 638 3ace84c91bfcde Stefano Garzarella 2022-02-21 639 if (check_owner) { 433fc58e6bf2c8 Asias He 2016-07-28 640 ret = vhost_dev_check_owner(&vsock->dev); 433fc58e6bf2c8 Asias He 2016-07-28 641 if (ret) 433fc58e6bf2c8 Asias He 2016-07-28 642 goto err; 3ace84c91bfcde Stefano Garzarella 2022-02-21 643 } "ret" not initialized on else path. 433fc58e6bf2c8 Asias He 2016-07-28 644 433fc58e6bf2c8 Asias He 2016-07-28 645 for (i = 0; i < ARRAY_SIZE(vsock->vqs); i++) { 433fc58e6bf2c8 Asias He 2016-07-28 646 struct vhost_virtqueue *vq = &vsock->vqs[i]; 433fc58e6bf2c8 Asias He 2016-07-28 647 433fc58e6bf2c8 Asias He 2016-07-28 648 mutex_lock(&vq->mutex); 247643f85782fc Eugenio P?rez 2020-03-31 649 vhost_vq_set_backend(vq, NULL); 433fc58e6bf2c8 Asias He 2016-07-28 650 mutex_unlock(&vq->mutex); 433fc58e6bf2c8 Asias He 2016-07-28 651 } 433fc58e6bf2c8 Asias He 2016-07-28 652 433fc58e6bf2c8 Asias He 2016-07-28 653 err: 433fc58e6bf2c8 Asias He 2016-07-28 654 mutex_unlock(&vsock->dev.mutex); 433fc58e6bf2c8 Asias He 2016-07-28 @655 return ret; 433fc58e6bf2c8 Asias He 2016-07-28 656 } --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all at lists.01.org