Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp231690pxv; Wed, 14 Jul 2021 02:43:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVmdAfTovdmPgZq0jwSdqQGlXoiUf2QW97xGjo5Y6ORBxRJplmGZ0lx0DBOgD17idcFfrV X-Received: by 2002:aa7:c7c2:: with SMTP id o2mr12612054eds.166.1626255814976; Wed, 14 Jul 2021 02:43:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626255814; cv=none; d=google.com; s=arc-20160816; b=iyGPXgFMgBKWPzjkNYmaDjXsBjxJv69hwbu6KSXAiR72ZgI6ZkTno8yWZZckBDVhOc /XtrcoaofHpyb0PEOKkeKFcm2W9ITf0Us5B2YC+FcVtD0+mHD57biAD/IMkDUZN38uyF MshETYgy2T6z5eAIjgJSeOY+nUsZRveBbD7ghk8FSQl9bnLbO6F4e9w3N6/kix3KMcXv X7qEKMc6XjKwCXNq7C1nTALF9e7suayXGi7QMKDKv+3TsJsS7zqzWrR787ODAEuvmG+Y 76lo060li2ZCjMoFZ2Wl7XHH59TsgEm730XR/TtqvREZCkaRJTytOP0H5HooSo4jlqdZ ut2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=ZplaldvdPUqWqjFHRQy6XqAYb6B2IbOETrAj7lOt6Jc=; b=X5OmCw7Uo2VavduszTueiaoaQkM39GmzE/SekJF6oHN1EwBPPmzu/so7m26YeR8X/z y/cg5Jp+IkhXEoEpAxtqs2ligzZHQ3In5w7wR9zAO+mstZCgK7lgk3l23qwvZTObWumN l2HioUPynh+Z1GEkJc15M3djqNFDHnMMiDLLgS8mU417WRvWRgkiUXuUMPq8vs6yhT7T Qg5FHcsQT9uYXzcSDGix0mov6OAo4CoUf8VWIG6Gnled5eYPy4c02/zOvIcb28Ce9Mdf cpRFTMsyTE4gJo9jwCTfzkknFXxKtUgKKdzMcZqnhAhVEMstlRjEoEBzE0XHCBIfYMSQ Y+nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="U/iYW3aw"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bz24si2072542ejc.249.2021.07.14.02.43.11; Wed, 14 Jul 2021 02:43:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="U/iYW3aw"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S238865AbhGNJpC (ORCPT + 99 others); Wed, 14 Jul 2021 05:45:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:45358 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238720AbhGNJpB (ORCPT ); Wed, 14 Jul 2021 05:45:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626255729; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZplaldvdPUqWqjFHRQy6XqAYb6B2IbOETrAj7lOt6Jc=; b=U/iYW3aw5IvGT0aLmnDGEgbNSbd3zFCuMNZvKUaU6vdvh/QQ3wHtRhFO8uI/3Yie8wQicU A0VzkvKIq4XVYe2Pz89y/TfGPrHHYaqbLAtkTA32Rg5QWVy+NaiLybW60HuUIXYIm1eYq7 IR5D4ADt9M7YDgtgA9PJudwghn9bWfk= Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-280-8m_9zB-tOH2nTGj6cFyM2g-1; Wed, 14 Jul 2021 05:42:08 -0400 X-MC-Unique: 8m_9zB-tOH2nTGj6cFyM2g-1 Received: by mail-pf1-f198.google.com with SMTP id t18-20020a056a001392b02903039eb2e663so1241057pfg.5 for ; Wed, 14 Jul 2021 02:42:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=ZplaldvdPUqWqjFHRQy6XqAYb6B2IbOETrAj7lOt6Jc=; b=DaCpFIoXlPOZJlbS65Kk+lzQCDLGAFP7VFL8jaNr/kRH0iDN71QcX1kGLLoz7pACRz jDySOPPyMvex9T7qZQ/+igeJ9HrnWscob0z5FaorvGbhRqjE8VFsoVBPII2M0sSaBTWv 8AuK2nMeCD3+k2bocXxvk9dudi4Eu/WJxaiErbZ4JKivZK210JiBcEJUupGs+/h/u7Xx IU4ZltyEKQcAQ2S+YIVaLdz4MptKBZ1QcmS4XIVrrlJ5dzWC+Sb1aObqmrOBhIYAaZPp QLDIu8abMNdw9uPeLphIYWdYZdFSfQfPm+c7EbbpPKsqPcVRuyB2L9KrhXNXVXYCzVYP Nm8Q== X-Gm-Message-State: AOAM531HPyAN2kXBc0dAWkEh8dyzskQ1i/af8YCxUPI8JYTCr9Anu/Hr Qio+MDKUdWvRJDZVEDQFLk+/JJkjQNq6I2iSLpA54Ar8PDsM+bWPmJ39zOuTiApEMFAFp7HWsxO GyR4MqVnFKTkDRyX46ovDv8cLxlxzjU2oS6+EtRNkmbb46GtWCt/9M/WsaXN6E8tjSE1khgY1SH /3 X-Received: by 2002:a17:90a:7a86:: with SMTP id q6mr3009945pjf.141.1626255727321; Wed, 14 Jul 2021 02:42:07 -0700 (PDT) X-Received: by 2002:a17:90a:7a86:: with SMTP id q6mr3009902pjf.141.1626255726913; Wed, 14 Jul 2021 02:42:06 -0700 (PDT) Received: from wangxiaodeMacBook-Air.local ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id p5sm2075572pfn.46.2021.07.14.02.41.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 14 Jul 2021 02:42:06 -0700 (PDT) Subject: Re: [PATCH v9 13/17] vdpa: factor out vhost_vdpa_pa_map() and vhost_vdpa_pa_unmap() To: Dan Carpenter Cc: Xie Yongji , mst@redhat.com, stefanha@redhat.com, sgarzare@redhat.com, parav@nvidia.com, hch@infradead.org, christian.brauner@canonical.com, rdunlap@infradead.org, willy@infradead.org, viro@zeniv.linux.org.uk, axboe@kernel.dk, bcrl@kvack.org, corbet@lwn.net, mika.penttila@nextfour.com, joro@8bytes.org, gregkh@linuxfoundation.org, zhe.he@windriver.com, xiaodong.liu@intel.com, songmuchun@bytedance.com, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, kvm@vger.kernel.org, linux-fsdevel@vger.kernel.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org References: <20210713084656.232-1-xieyongji@bytedance.com> <20210713084656.232-14-xieyongji@bytedance.com> <20210713113114.GL1954@kadam> <20e75b53-0dce-2f2d-b717-f78553bddcd8@redhat.com> <20210714080512.GW1954@kadam> From: Jason Wang Message-ID: Date: Wed, 14 Jul 2021 17:41:54 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210714080512.GW1954@kadam> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2021/7/14 下午4:05, Dan Carpenter 写道: > On Wed, Jul 14, 2021 at 10:14:32AM +0800, Jason Wang wrote: >> 在 2021/7/13 下午7:31, Dan Carpenter 写道: >>> On Tue, Jul 13, 2021 at 04:46:52PM +0800, Xie Yongji wrote: >>>> @@ -613,37 +618,28 @@ static void vhost_vdpa_unmap(struct vhost_vdpa *v, u64 iova, u64 size) >>>> } >>>> } >>>> -static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v, >>>> - struct vhost_iotlb_msg *msg) >>>> +static int vhost_vdpa_pa_map(struct vhost_vdpa *v, >>>> + u64 iova, u64 size, u64 uaddr, u32 perm) >>>> { >>>> struct vhost_dev *dev = &v->vdev; >>>> - struct vhost_iotlb *iotlb = dev->iotlb; >>>> struct page **page_list; >>>> unsigned long list_size = PAGE_SIZE / sizeof(struct page *); >>>> unsigned int gup_flags = FOLL_LONGTERM; >>>> unsigned long npages, cur_base, map_pfn, last_pfn = 0; >>>> unsigned long lock_limit, sz2pin, nchunks, i; >>>> - u64 iova = msg->iova; >>>> + u64 start = iova; >>>> long pinned; >>>> int ret = 0; >>>> - if (msg->iova < v->range.first || >>>> - msg->iova + msg->size - 1 > v->range.last) >>>> - return -EINVAL; >>> This is not related to your patch, but can the "msg->iova + msg->size" >>> addition can have an integer overflow. From looking at the callers it >>> seems like it can. msg comes from: >>> vhost_chr_write_iter() >>> --> dev->msg_handler(dev, &msg); >>> --> vhost_vdpa_process_iotlb_msg() >>> --> vhost_vdpa_process_iotlb_update() >> >> Yes. >> >> >>> If I'm thinking of the right thing then these are allowed to overflow to >>> 0 because of the " - 1" but not further than that. I believe the check >>> needs to be something like: >>> >>> if (msg->iova < v->range.first || >>> msg->iova - 1 > U64_MAX - msg->size || >> >> I guess we don't need - 1 here? > The - 1 is important. The highest address is 0xffffffff. So it goes > start + size = 0 and then start + size - 1 == 0xffffffff. Right, so actually msg->iova = 0xfffffffe, msg->size=2 is valid. Thanks > > I guess we could move the - 1 to the other side? > > msg->iova > U64_MAX - msg->size + 1 || > > regards, > dan carpenter > >