From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2A8BC433F5 for ; Tue, 8 Mar 2022 06:16:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242143AbiCHGR2 (ORCPT ); Tue, 8 Mar 2022 01:17:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344406AbiCHGRI (ORCPT ); Tue, 8 Mar 2022 01:17:08 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id ABF8A2E6BE for ; Mon, 7 Mar 2022 22:16:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646720171; 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=c5ugwLO4/RAIk+A33RH1Nda04XboyFL8Xk9nspKrv+Q=; b=KroPkbxi1L9hH/HmXZgxQhdBuekA4HxqXcDzsresT6Cwo1ZF2iPR2/08WoFCAlgUegXm4H tteJRZtglg8X/UYn6LVuSY0XdpzFn7lOtlTOiezUxssBHnJgsCusmhMTCkJBfuEoQDTgby 9yPcyxLQDV/WOkXeKQYUcHYFAWasC08= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-190-CjUjc8p6Ne2On3LACfWhzg-1; Tue, 08 Mar 2022 01:16:10 -0500 X-MC-Unique: CjUjc8p6Ne2On3LACfWhzg-1 Received: by mail-lf1-f72.google.com with SMTP id j22-20020a05651231d600b0044830cff16fso1264983lfe.12 for ; Mon, 07 Mar 2022 22:16:10 -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=c5ugwLO4/RAIk+A33RH1Nda04XboyFL8Xk9nspKrv+Q=; b=KjAbrA/1O7JprwWMGDo0guv8h82fAP8hUfkuSPjdhadsUGWh4kv4cY331PyObUIBGR gk1Z4WEbps7ZWP/QbASD1+nW8j3klnbNkFmn/JWUlTRUzmzLvQc2vxIqnjsF52+t1b7q d7OJFUpWnVVq8wOISehchCoitBqPED/6O5SrcFLEoVURsSnBUwRdlNQaIPYpc9lHe4UH 9l/rRFSPXlTIORZd7TnfAHq3MxSjY9EkH0Z22+8JxQIHXQiEWJMr2PVyCiRkUpSfDO79 yBtSj0FiZILbMZ9dAzOVfsX/j7yNu0yU0wRfg4EEj5zXT5QdMHYmfzI+428VHTTm2JQJ QOGg== X-Gm-Message-State: AOAM532EAD7ZdhVdb2gMjs506Lx+aKORq+WoZk9ZBzy0M62xNZGEd0JK pAr8/fjqCQritA/L1ykfTrH09l8bzfl0bEQtUP6EOSjmRKDaNQWFBu5AWiysFi7SqYja00M8dXq fjvEOFLptrXValEvzi6bcLo9NNHZ/3I+rKVXeXXTd X-Received: by 2002:a2e:9045:0:b0:247:da7d:a460 with SMTP id n5-20020a2e9045000000b00247da7da460mr9533965ljg.300.1646720168270; Mon, 07 Mar 2022 22:16:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJxait3lv+dLzC+BdDFV83vSleLNh5HIk4y197ubAHp3aPkfzkCIzF+1Ixw1dsakTX8Qi9vOeSnOuGXbcvWoGxY= X-Received: by 2002:a2e:9045:0:b0:247:da7d:a460 with SMTP id n5-20020a2e9045000000b00247da7da460mr9533952ljg.300.1646720167963; Mon, 07 Mar 2022 22:16:07 -0800 (PST) MIME-Version: 1.0 References: <20220307191757.3177139-1-lee.jones@linaro.org> In-Reply-To: <20220307191757.3177139-1-lee.jones@linaro.org> From: Jason Wang Date: Tue, 8 Mar 2022 14:15:56 +0800 Message-ID: Subject: Re: [PATCH 1/1] vhost: Protect the virtqueue from being cleared whilst still in use To: Lee Jones Cc: mst , linux-kernel , kvm , virtualization , netdev , stable@vger.kernel.org, syzbot+adc3cb32385586bec859@syzkaller.appspotmail.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 8, 2022 at 3:18 AM Lee Jones wrote: > > vhost_vsock_handle_tx_kick() already holds the mutex during its call > to vhost_get_vq_desc(). All we have to do here is take the same lock > during virtqueue clean-up and we mitigate the reported issues. > > Also WARN() as a precautionary measure. The purpose of this is to > capture possible future race conditions which may pop up over time. > > Link: https://syzkaller.appspot.com/bug?extid=279432d30d825e63ba00 > > Cc: > Reported-by: syzbot+adc3cb32385586bec859@syzkaller.appspotmail.com > Signed-off-by: Lee Jones > --- > drivers/vhost/vhost.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c > index 59edb5a1ffe28..ef7e371e3e649 100644 > --- a/drivers/vhost/vhost.c > +++ b/drivers/vhost/vhost.c > @@ -693,6 +693,15 @@ void vhost_dev_cleanup(struct vhost_dev *dev) > int i; > > for (i = 0; i < dev->nvqs; ++i) { > + /* No workers should run here by design. However, races have > + * previously occurred where drivers have been unable to flush > + * all work properly prior to clean-up. Without a successful > + * flush the guest will malfunction, but avoiding host memory > + * corruption in those cases does seem preferable. > + */ > + WARN_ON(mutex_is_locked(&dev->vqs[i]->mutex)); > + I don't get how this can help, the mutex could be grabbed in the middle of the above and below line. > + mutex_lock(&dev->vqs[i]->mutex); > if (dev->vqs[i]->error_ctx) > eventfd_ctx_put(dev->vqs[i]->error_ctx); > if (dev->vqs[i]->kick) > @@ -700,6 +709,7 @@ void vhost_dev_cleanup(struct vhost_dev *dev) > if (dev->vqs[i]->call_ctx.ctx) > eventfd_ctx_put(dev->vqs[i]->call_ctx.ctx); > vhost_vq_reset(dev, dev->vqs[i]); > + mutex_unlock(&dev->vqs[i]->mutex); > } I'm not sure it's correct to assume some behaviour of a buggy device. For the device mutex, we use that to protect more than just err/call and vq. Thanks > vhost_dev_free_iovecs(dev); > if (dev->log_ctx) > -- > 2.35.1.616.g0bdcbb4464-goog >