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 8F5E8C4332F for ; Tue, 22 Feb 2022 14:05:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232644AbiBVOFd (ORCPT ); Tue, 22 Feb 2022 09:05:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232626AbiBVOFU (ORCPT ); Tue, 22 Feb 2022 09:05:20 -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 2A8F315F0BC for ; Tue, 22 Feb 2022 06:04:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1645538694; 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=+0qFceD01hVCN/fQNTDDfz9J6CvlRYxeXEgGXKvXoqM=; b=g7arPT733wIlIvm1xIhkPotHbM3gxO2VOaQGe57alZLpWFTY01MjbAFesxLbxYTYHpTc02 P4KJGw/yU8oVfuNX8Gn31JElxApZXCF6mWC3lvbx2qmsTm/cTU2qn0bZKEyNHKhRFJDG+1 g2H3zHbvQtczeKil6pVwiw/PFc304iU= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-267-SEbl-5BWOPatbWpAaKFUsQ-1; Tue, 22 Feb 2022 09:04:51 -0500 X-MC-Unique: SEbl-5BWOPatbWpAaKFUsQ-1 Received: by mail-wr1-f69.google.com with SMTP id j27-20020adfb31b000000b001ea8356972bso1260094wrd.1 for ; Tue, 22 Feb 2022 06:04:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=+0qFceD01hVCN/fQNTDDfz9J6CvlRYxeXEgGXKvXoqM=; b=4pgB3+ZyBXZLqFJIYqOeY62yqhNs/YUOHwt2IvXRZxlcmQXUfCVWeiLt2/HhzUtIAw 4dUyyVwI//r+Z+VnuZ/TxaDgXRjsp/OysCYRoolCBNIe+MfdckuahbMOp3FdgXLxa48V fD6MFOcl5vWMdGwsTK+I7Q9AHCvF6MM5qmnSIK9bJHO2z4sjfDcsmxbMmY3lzArFrPM7 u6PB5+aQrFVVx1MAN5d/MzeEtLfO5DFoVeYg/Su81sYAfCxr1yPksIP5KUnT+zVGKTnM cy6I3b+0DHayOH7GXI4TYF+9gWbr/g9Yr3Rv+sqNNaIbHO5pMOL9CRc2/N+YRnED4CLt y5zg== X-Gm-Message-State: AOAM533/Pyya8SOmDM52nUz6Lgiq14PAIYmWgnGDYCffm7Z0EIwG0Azg ERY3a6MwkEBrDRnfe64vZgYlFLHbsuojSE3GPRh1nSUJU/kp1mosMAzmJidQhMnarqRARvN4NMZ BPM7zAqKtK7vx6CYh8xHZWVEY X-Received: by 2002:a1c:2904:0:b0:37b:ea53:4cbf with SMTP id p4-20020a1c2904000000b0037bea534cbfmr3521213wmp.46.1645538690587; Tue, 22 Feb 2022 06:04:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJxnqfwv3DyvbfLKFUSw1w02W2csoa49y5OZ11ejqp+BgbeoaU6MPpX2ME5lsWarq+vpSzVxjA== X-Received: by 2002:a1c:2904:0:b0:37b:ea53:4cbf with SMTP id p4-20020a1c2904000000b0037bea534cbfmr3521190wmp.46.1645538690376; Tue, 22 Feb 2022 06:04:50 -0800 (PST) Received: from redhat.com ([2.55.129.240]) by smtp.gmail.com with ESMTPSA id j6sm41356042wrt.70.2022.02.22.06.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Feb 2022 06:04:49 -0800 (PST) Date: Tue, 22 Feb 2022 09:04:46 -0500 From: "Michael S. Tsirkin" To: Anirudh Rayabharam Cc: Jason Wang , syzbot+0abd373e2e50d704db87@syzkaller.appspotmail.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] vhost: validate range size before adding to iotlb Message-ID: <20220222090406-mutt-send-email-mst@kernel.org> References: <20220221195303.13560-1-mail@anirudhrb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220221195303.13560-1-mail@anirudhrb.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 22, 2022 at 01:23:03AM +0530, Anirudh Rayabharam wrote: > In vhost_iotlb_add_range_ctx(), validate the range size is non-zero > before proceeding with adding it to the iotlb. > > Range size can overflow to 0 when start is 0 and last is (2^64 - 1). > 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 = (2^64 - 1) 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 > > Reported-by: syzbot+0abd373e2e50d704db87@syzkaller.appspotmail.com > Tested-by: syzbot+0abd373e2e50d704db87@syzkaller.appspotmail.com > Signed-off-by: Anirudh Rayabharam > --- > drivers/vhost/iotlb.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/vhost/iotlb.c b/drivers/vhost/iotlb.c > index 670d56c879e5..b9de74bd2f9c 100644 > --- a/drivers/vhost/iotlb.c > +++ b/drivers/vhost/iotlb.c > @@ -53,8 +53,10 @@ int vhost_iotlb_add_range_ctx(struct vhost_iotlb *iotlb, > void *opaque) > { > struct vhost_iotlb_map *map; > + u64 size = last - start + 1; > > - if (last < start) > + // size can overflow to 0 when start is 0 and last is (2^64 - 1). Pls use the old-style /* */ comments. > + if (last < start || size == 0) > return -EFAULT; > > if (iotlb->limit && > @@ -69,7 +71,7 @@ int vhost_iotlb_add_range_ctx(struct vhost_iotlb *iotlb, > return -ENOMEM; > > map->start = start; > - map->size = last - start + 1; > + map->size = size; > map->last = last; > map->addr = addr; > map->perm = perm; > -- > 2.35.1