Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp967520pxp; Wed, 16 Mar 2022 22:56:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzwbDQ6TDcKJ81xb83N2wUl/12ygawDk2riV/HPhCMJ1UmdgMVMHDfkwTOUSKYdBuqUiN0 X-Received: by 2002:a17:902:c94d:b0:153:9815:f1b8 with SMTP id i13-20020a170902c94d00b001539815f1b8mr3108823pla.41.1647496619262; Wed, 16 Mar 2022 22:56:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1647496619; cv=pass; d=google.com; s=arc-20160816; b=nkBRtSz2qghMngoyVZsPLvwFAVuE1ydOpuek3EQrY7TlBZ69QUzOhrV3X6T4ixilYf 6+PZol7lPA5ObxdpfYTUlZ2V0c36qP0mjfp8vBVWLE9SzTptJcBBnpeTfMVrwImjPjMy tyB9tQaFNOEzhVQVvInoJ1kurOkj2SBCVKg/l/dvDT3GJXNReNJiB/UvmhYsu6Gdce6V TcWGw0pJU15VDS0k9lK3H1NqTpWfB+IV75ZWlIzDiqqPPdWCc9+eA2HuQqtXZeqs7H9h URNGx1HY/Q1sJOsKOZt3KBb8XRa0vgvSkqBgM7lxiAI7yWav3nY4ZNUl4fv4F5QOQZL/ 3fhg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=SYTvhP0m/Gx6FXYlVdSO0C6zDPWvwPEWDnbNrpmJslc=; b=GwHLmIoUmXxDydOPCOrrUTG+sGcNjgtSL/1tM/2j0RjQsFmr6gdzkoqZ0bastDxt4Z W7QbSC3EmUKvbjp1hFGiAxa6INCYX+Dh4VoDiP85mb9+KdeKsbMPUOvCFD2f7TazalPl wVu8FuIlnKmDrut2C+Yw5GHRAlpG0lVfgz8Vl3P0K61X3OLU005xylmyOGhr+BcBECvF KdeXUuQK02gNuPVoeVY70HoPE396Ztb7DP8feQ3LdguFkO+rN6DVwdtutYTbTFDDDk2f FDE8HvtcUOaNbmRIO0xJvOlRToPtDyqh5fFOt+GkDBXFgp+8LRo2blxOwLg+mruSvuLM CA3A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@anirudhrb.com header.s=zoho header.b=sDoZhSh1; arc=pass (i=1 spf=pass spfdomain=anirudhrb.com dkim=pass dkdomain=anirudhrb.com dmarc=pass fromdomain=anirudhrb.com>); spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id s15-20020a170902ea0f00b00151f5a233d1si4120499plg.505.2022.03.16.22.56.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 22:56:59 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@anirudhrb.com header.s=zoho header.b=sDoZhSh1; arc=pass (i=1 spf=pass spfdomain=anirudhrb.com dkim=pass dkdomain=anirudhrb.com dmarc=pass fromdomain=anirudhrb.com>); spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BC83219316D; Wed, 16 Mar 2022 21:52:46 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242882AbiCNQQg (ORCPT + 99 others); Mon, 14 Mar 2022 12:16:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234683AbiCNQQe (ORCPT ); Mon, 14 Mar 2022 12:16:34 -0400 Received: from sender4-of-o53.zoho.com (sender4-of-o53.zoho.com [136.143.188.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5E95403EB for ; Mon, 14 Mar 2022 09:15:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647274494; cv=none; d=zohomail.com; s=zohoarc; b=axCrQtr+KDzg7MysSAuV72E38IwSKOOG8tldIxi0Jt4KJuGQ/MB2oU5Efb8Oi7TXQx2P0Y9qbmuuOYXlF9fCQMOQIlIFRolN36iA5y4fP4LXe9wZrzbHFEPoCDxvGo/GNAstHc0AwiAgM3c04Uz/WxebHVuNE23810Eo9SnBn/g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1647274494; h=Content-Type:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=SYTvhP0m/Gx6FXYlVdSO0C6zDPWvwPEWDnbNrpmJslc=; b=VirgvikMNoWtvfDuPCoT8IPdy/QRh1eZv2gM5IyiCt2ghxSZCEZiQzoaLodMb39FZXYwwoRrkS+Z+AvA/dK0X8MDCGrt+At1XeNYY3sjHZ6qNbR3ppoVZ/pMZbFIgy/V+JqiMzHUpp+3f91GO49CBg/Egns34g77vgUOPo3nCAE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=anirudhrb.com; spf=pass smtp.mailfrom=mail@anirudhrb.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1647274494; s=zoho; d=anirudhrb.com; i=mail@anirudhrb.com; h=Date:From:From:To:To:Cc:Cc:Subject:Subject:Message-ID:References:MIME-Version:Content-Type:In-Reply-To:Message-Id:Reply-To; bh=SYTvhP0m/Gx6FXYlVdSO0C6zDPWvwPEWDnbNrpmJslc=; b=sDoZhSh1QgIfwPKqQ6/oLh5/4Q5FuTJDCj5LQYB14um6TzQBe158uvdUbG86LgH0 GDLejfH9A3vpQgjpAPgGOB1qqrmVIMBXuoZAgeoIi7nU+noXLk7N7fO48M9gKwna5Ts Q5HpTQfbFndOH6sn9v4DTRApoivsYLxmvsKa36x0= Received: from anirudhrb.com (49.207.221.223 [49.207.221.223]) by mx.zohomail.com with SMTPS id 1647274491104743.6587593231992; Mon, 14 Mar 2022 09:14:51 -0700 (PDT) Date: Mon, 14 Mar 2022 21:44:43 +0530 From: Anirudh Rayabharam To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, syzbot+0abd373e2e50d704db87@syzkaller.appspotmail.com, "Michael S. Tsirkin" , Sasha Levin , jasowang@redhat.com Subject: Re: [PATCH 5.15 015/110] vhost: fix hung thread due to erroneous iotlb entries Message-ID: References: <20220314112743.029192918@linuxfoundation.org> <20220314112743.460512435@linuxfoundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220314112743.460512435@linuxfoundation.org> X-ZohoMailClient: External X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Mon, Mar 14, 2022 at 12:53:17PM +0100, Greg Kroah-Hartman wrote: > From: Anirudh Rayabharam > > [ Upstream commit e2ae38cf3d91837a493cb2093c87700ff3cbe667 ] This breaks batching of IOTLB messages. [1] fixes it but hasn't landed in Linus' tree yet. [1]: https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git/commit/?h=linux-next&id=95932ab2ea07b79cdb33121e2f40ccda9e6a73b5 - Anirudh. > > In vhost_iotlb_add_range_ctx(), range size can overflow to 0 when > start is 0 and last is ULONG_MAX. One instance where it can happen > is when userspace sends an IOTLB message with iova=size=uaddr=0 > (vhost_process_iotlb_msg). So, an entry with size = 0, start = 0, > last = ULONG_MAX ends up in the iotlb. Next time a packet is sent, > iotlb_access_ok() loops indefinitely due to that erroneous entry. > > Call Trace: > > iotlb_access_ok+0x21b/0x3e0 drivers/vhost/vhost.c:1340 > vq_meta_prefetch+0xbc/0x280 drivers/vhost/vhost.c:1366 > vhost_transport_do_send_pkt+0xe0/0xfd0 drivers/vhost/vsock.c:104 > vhost_worker+0x23d/0x3d0 drivers/vhost/vhost.c:372 > kthread+0x2e9/0x3a0 kernel/kthread.c:377 > ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295 > > > Reported by syzbot at: > https://syzkaller.appspot.com/bug?extid=0abd373e2e50d704db87 > > To fix this, do two things: > > 1. Return -EINVAL in vhost_chr_write_iter() when userspace asks to map > a range with size 0. > 2. Fix vhost_iotlb_add_range_ctx() to handle the range [0, ULONG_MAX] > by splitting it into two entries. > > Fixes: 0bbe30668d89e ("vhost: factor out IOTLB") > Reported-by: syzbot+0abd373e2e50d704db87@syzkaller.appspotmail.com > Tested-by: syzbot+0abd373e2e50d704db87@syzkaller.appspotmail.com > Signed-off-by: Anirudh Rayabharam > Link: https://lore.kernel.org/r/20220305095525.5145-1-mail@anirudhrb.com > Signed-off-by: Michael S. Tsirkin > Signed-off-by: Sasha Levin > --- > drivers/vhost/iotlb.c | 11 +++++++++++ > drivers/vhost/vhost.c | 5 +++++ > 2 files changed, 16 insertions(+) > > diff --git a/drivers/vhost/iotlb.c b/drivers/vhost/iotlb.c > index 670d56c879e5..40b098320b2a 100644 > --- a/drivers/vhost/iotlb.c > +++ b/drivers/vhost/iotlb.c > @@ -57,6 +57,17 @@ int vhost_iotlb_add_range_ctx(struct vhost_iotlb *iotlb, > if (last < start) > return -EFAULT; > > + /* If the range being mapped is [0, ULONG_MAX], split it into two entries > + * otherwise its size would overflow u64. > + */ > + if (start == 0 && last == ULONG_MAX) { > + u64 mid = last / 2; > + > + vhost_iotlb_add_range_ctx(iotlb, start, mid, addr, perm, opaque); > + addr += mid + 1; > + start = mid + 1; > + } > + > if (iotlb->limit && > iotlb->nmaps == iotlb->limit && > iotlb->flags & VHOST_IOTLB_FLAG_RETIRE) { > diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c > index 59edb5a1ffe2..55475fd59fb7 100644 > --- a/drivers/vhost/vhost.c > +++ b/drivers/vhost/vhost.c > @@ -1170,6 +1170,11 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev, > goto done; > } > > + if (msg.size == 0) { > + ret = -EINVAL; > + goto done; > + } > + > if (dev->msg_handler) > ret = dev->msg_handler(dev, &msg); > else > -- > 2.34.1 > > >