Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp125568pxm; Tue, 22 Feb 2022 18:33:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJw9Z2WtIeZVjAwSk0/VnfETMYMtIUJSWkNXPn6nihx6at3K4ptBHcR1yzpzjDSXdhAayJe9 X-Received: by 2002:a50:ef0e:0:b0:40f:b56b:e0cd with SMTP id m14-20020a50ef0e000000b0040fb56be0cdmr30304803eds.373.1645583629565; Tue, 22 Feb 2022 18:33:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645583629; cv=none; d=google.com; s=arc-20160816; b=jCQ41OoeLgUFeduBXJDnQn1ALcTZOb+w+UuD3tNFu3WNtk2G+Ao3XSwRewv9qC1s3/ Jk/fxoOnE4NP1nHZKZ2eHiFy0EgA1TLAVXpcjtoXsJKDRuoKRmrGaoc+e854ySkCfD+D 1K22UddrvyRCn5zjJMjLdk8KgBpfpNzjAf87c/4njGfQ9JYkpMHqoYhRie1Y9fuF013X lfejsYnMLlrxcEr9HSB0IO7K4E7CklKz9iF8hQb3zrW6BXHXOZw2gZ0nZJ69w6iKT//l ZOUGaA3oxH40YbGOEZEZNC4oVyBlrJERE7U6QdmPPosOxNNBXDWuyLYQppG/BOipeO9Z weNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=W9LkpmwRUB9s3DzzklqywD2GBEtiMiXthflpW97NS2M=; b=Ji/dMZFiEr16ZMpdta90AzBD2B4pSt+s/dPs9DqBiM+6lXBcaxIH1XaG2hB94Ifies qSpwR376C1cxI8sLZd4MqHDf1Cfm2Zwyy9elQDYTFv7JK9gmMB5Mpt4jZkyn+fs9KVsn WgcfDAiIiUr80NV5WW8u1UeBeXFjhtJHxuEahsODoa1UW9RzetE1YLuUubXpX2g0Qqou 4MDRRqbZVUNPpGVV+W97lv8MmR8XyqEp7pP1wEQMnZWPSH+Z5mtpMCnOKrREt2UFusWq dNz0AOnvjTWHUTKMvAqhNCqZ6CEJqCul4VOg70L+4ClA9hMfLquco8lklZokMl+la6ei am5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=i3PwiWxK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g5si13695647edy.70.2022.02.22.18.33.26; Tue, 22 Feb 2022 18:33:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=i3PwiWxK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233115AbiBWCJq (ORCPT + 99 others); Tue, 22 Feb 2022 21:09:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236143AbiBWCJp (ORCPT ); Tue, 22 Feb 2022 21:09:45 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C268313CE2 for ; Tue, 22 Feb 2022 18:09:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1645582157; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=W9LkpmwRUB9s3DzzklqywD2GBEtiMiXthflpW97NS2M=; b=i3PwiWxKRcCCRLelxFJMc8oFWIJjZE923xibPM10bxF/6Y42q87Z7EKls4dqbSK8CkhTVA rC2mZJ7gB/56E5HV29FelPEeayZOvACq3ZWQ6BEU8b0lVyKUU4N8Dm58Q5THTFptu64LLQ f5wfu9z6V20Wz+F1X7ca2mgKPWUAEjA= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-633-WlvoN1TNPNS8WQ6ZQCA7RA-1; Tue, 22 Feb 2022 21:09:16 -0500 X-MC-Unique: WlvoN1TNPNS8WQ6ZQCA7RA-1 Received: by mail-lj1-f197.google.com with SMTP id r27-20020a2e575b000000b002463f43ca0aso4049032ljd.7 for ; Tue, 22 Feb 2022 18:09:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=W9LkpmwRUB9s3DzzklqywD2GBEtiMiXthflpW97NS2M=; b=E0L60FDyFIk1Bce8D1p/yrotFkU3YTjJ8/kZmAVhJcCxLFBSi8FQKgDUKsuTAkLtTD OeFPv74+md9wZX7OsXQVSiHzLrvcSMPdVTCVdL3pzFmNMS351b1oQD4qbEzqq3ZQTAL/ byCM2FdvcSUUwQzDEuOoDGa5w1Vnc4wvvEMkxGOI/yTLo1e3ZcJC8dtRXw9dARPU7enF ETIHv6UuzQYxtSbQucY7MhVEFr0FObukMNet+G39evjhjs6vuozFZJ0+gr2LVfIfHThw fmlRL6ZKA7QWsCzo83+V9NOtv7Ldr9I3BfHaRGoEKiqakTuEvtm6sgrJETAezZDQnGHE 4Tng== X-Gm-Message-State: AOAM530J2YmRdP/GsR9SFf+jQBl8wkCs54BfO94BJDmc3M3IcVaC96rV OUMFKnwSMbexwyut8zCTPojGOD2LBq8bVItVc7XQ6JfEvE7AySsBqb5wrCeGcr0SSUyjemPSwx3 PKaqL0DP0YkmWMlBvJtrblXL2YS89AwnVFoQQxL7w X-Received: by 2002:ac2:4da1:0:b0:438:74be:5a88 with SMTP id h1-20020ac24da1000000b0043874be5a88mr17748772lfe.210.1645582155152; Tue, 22 Feb 2022 18:09:15 -0800 (PST) X-Received: by 2002:ac2:4da1:0:b0:438:74be:5a88 with SMTP id h1-20020ac24da1000000b0043874be5a88mr17748759lfe.210.1645582154950; Tue, 22 Feb 2022 18:09:14 -0800 (PST) MIME-Version: 1.0 References: <20220222094742.16359-1-sgarzare@redhat.com> In-Reply-To: <20220222094742.16359-1-sgarzare@redhat.com> From: Jason Wang Date: Wed, 23 Feb 2022 10:09:03 +0800 Message-ID: Subject: Re: [PATCH v2] vhost/vsock: don't check owner in vhost_vsock_stop() while releasing To: Stefano Garzarella Cc: "Michael S. Tsirkin" , Stefan Hajnoczi , netdev , virtualization , syzbot , kvm , Anirudh Rayabharam , syzbot+3140b17cb44a7b174008@syzkaller.appspotmail.com, linux-kernel , Mike Christie , Dan Carpenter , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 22, 2022 at 5:47 PM 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 Acked-by: Jason Wang > --- > 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 >