Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1089528ybh; Tue, 10 Mar 2020 14:27:57 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvVul8Fyt+jhi5wFSRIBXNPE94rqQ2uPiSmUd3h0x2y75KLZRfJZ7KK7/hfuQFzLUi4yAbQ X-Received: by 2002:aca:cd0e:: with SMTP id d14mr2558510oig.167.1583875677708; Tue, 10 Mar 2020 14:27:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583875677; cv=none; d=google.com; s=arc-20160816; b=VovnsWffMozM651s9rU/DVwXLqqLgMEXezuQbLmy93OgKFt3525B8mU1+ddT1LFqhW 8sm9pGegZEpVkU4mDbcLWyXk2iUwH7DJ6inPirYZQeWvQhmQIiXdKBScde1+coHt6b/p KSRQlc6ma+naLSpwJVhAKZ7NtR4teAEal5RcLvRz8JWLdRET9d/X9nPTZXPkJB022tkg b+DrO3WKUZHrOOrbw63kjEkzAUIv9NNET9/KVYAysEeprf80rfWb9aw7b/T8PF1BPHXw mage1h6kckdeqUvY7JUHCnKhZ9RyaE5G9kif/CZiVmqvTVRTfFMGExY+i1y/e0e08azY Hj1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=elF36Gh6wAO43EXQWi3veY++EdOPHWUl7a5YAiXhFTQ=; b=OnEolIRsbBYNoxjiTU6ee62xp0tDkQ9UTgNf7jvBI2mPDFz03Ai0blBjlg70M8Xg8a aNdnpQe6bB0kcD/HC4TtWOnMaLPpuwyJ1HoypaO9Tpu995AxMecOliyY6en5smCczY7O VWaO+dRVx3rDskjjzpF6SAFywm0mI8W+kGsqEXIzzbI2ID8qkLaWc3/2w5JPVXGm1TNe oZrvvjdn7OfLKhzovqjAj1yCr9Z7H9itMkV37/PWwdUiyOKt7cFH3fQXFFaARhODF2C8 st2y632SgMy6lfWVpbnE8TL9ThVuNe8AWEs78frK3l18IxceoZGkidkYsjJoEnX+Jzfl 6Dwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HziVMxK2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id q25si3822928ota.36.2020.03.10.14.27.46; Tue, 10 Mar 2020 14:27:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HziVMxK2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727504AbgCJV1U (ORCPT + 99 others); Tue, 10 Mar 2020 17:27:20 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:55880 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726265AbgCJV1U (ORCPT ); Tue, 10 Mar 2020 17:27:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583875638; 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=elF36Gh6wAO43EXQWi3veY++EdOPHWUl7a5YAiXhFTQ=; b=HziVMxK2D5RJcYF0bqBbXWQ4EDx1t0YTx09F0AKtSze4CAM39HvESxL4VhtXPm8gIjJ2yC Xzk353m2CIwXQXo10qBUNwzvgSvQ5ZikWL/laAXQnJA+KfgXFfq1NbNIPZMiop6NKdJNBY k5h56Vg36nn4E+oElzwpeqAx7ehH/TM= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-60-wVchelQ2Odm8hnwS7-Er4A-1; Tue, 10 Mar 2020 17:27:16 -0400 X-MC-Unique: wVchelQ2Odm8hnwS7-Er4A-1 Received: by mail-qt1-f197.google.com with SMTP id r16so10086466qtt.13 for ; Tue, 10 Mar 2020 14:27:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=elF36Gh6wAO43EXQWi3veY++EdOPHWUl7a5YAiXhFTQ=; b=ViCeCPtM0QDX4H4Mns0B7pzDqd7HfGm8+cJs/lPEwO30cZm4BJ80qRoHypFMC7S4zX 4Xa00XT75kSvKjjAuV6MAHhPCQEp0ILB10wgLoez4lk+5nHH5nY6ezWR9O4oIehUy2AO 6Nrm/ujpRCw6nULl/ZmuW/+GOeud0F0/mwMcl3ZTHy32TnJmutLTP9C/MbkhbS+p/jTs UE7hB9yBQpZGmdE/iVk/KgMqk+z8JLHrCGpvlsGiXgtWW7axG769g+TcBtw434TQRF+W YJKQzWa0moPTHE2m5VyGFNYWfKouqLzlBW1h0G3u1S0XBvh/AszgM0v7lI4Aa6JCDHui qTRQ== X-Gm-Message-State: ANhLgQ1tlOpXVVOvkryBS3a8JxlPkShVnwusLCJD0GJO5XOza6+iOIfd Ht130Fx/LoTyX2JRgBQCs4d/MxejsOkjxbesoppXtPDmgP/suRf7XCg9FkZ5ITX1hcAfNnK2B7K BWTPUaEl4LxHN4k5287Adod+A X-Received: by 2002:a37:40d2:: with SMTP id n201mr21535558qka.211.1583875636357; Tue, 10 Mar 2020 14:27:16 -0700 (PDT) X-Received: by 2002:a37:40d2:: with SMTP id n201mr21535545qka.211.1583875636149; Tue, 10 Mar 2020 14:27:16 -0700 (PDT) Received: from redhat.com (bzq-79-178-2-19.red.bezeqint.net. [79.178.2.19]) by smtp.gmail.com with ESMTPSA id x51sm3774837qtj.82.2020.03.10.14.27.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Mar 2020 14:27:14 -0700 (PDT) Date: Tue, 10 Mar 2020 17:27:09 -0400 From: "Michael S. Tsirkin" To: Vivek Goyal Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org, virtio-fs@redhat.com, miklos@szeredi.hu, stefanha@redhat.com, dgilbert@redhat.com, Sebastien Boeuf , kbuild test robot Subject: Re: [PATCH 04/20] virtio: Implement get_shm_region for PCI transport Message-ID: <20200310172603-mutt-send-email-mst@kernel.org> References: <20200304165845.3081-1-vgoyal@redhat.com> <20200304165845.3081-5-vgoyal@redhat.com> <20200310071043-mutt-send-email-mst@kernel.org> <20200310184720.GD38440@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200310184720.GD38440@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 10, 2020 at 02:47:20PM -0400, Vivek Goyal wrote: > On Tue, Mar 10, 2020 at 07:12:25AM -0400, Michael S. Tsirkin wrote: > [..] > > > +static bool vp_get_shm_region(struct virtio_device *vdev, > > > + struct virtio_shm_region *region, u8 id) > > > +{ > > > + struct virtio_pci_device *vp_dev = to_vp_device(vdev); > > > + struct pci_dev *pci_dev = vp_dev->pci_dev; > > > + u8 bar; > > > + u64 offset, len; > > > + phys_addr_t phys_addr; > > > + size_t bar_len; > > > + int ret; > > > + > > > + if (!virtio_pci_find_shm_cap(pci_dev, id, &bar, &offset, &len)) { > > > + return false; > > > + } > > > + > > > + ret = pci_request_region(pci_dev, bar, "virtio-pci-shm"); > > > + if (ret < 0) { > > > + dev_err(&pci_dev->dev, "%s: failed to request BAR\n", > > > + __func__); > > > + return false; > > > + } > > > + > > > + phys_addr = pci_resource_start(pci_dev, bar); > > > + bar_len = pci_resource_len(pci_dev, bar); > > > + > > > + if (offset + len > bar_len) { > > > + dev_err(&pci_dev->dev, > > > + "%s: bar shorter than cap offset+len\n", > > > + __func__); > > > + return false; > > > + } > > > + > > > > Something wrong with indentation here. > > Will fix all indentation related issues in this patch. > > > Also as long as you are validating things, it's worth checking > > offset + len does not overflow. > > Something like addition of following lines? > > + if ((offset + len) < offset) { > + dev_err(&pci_dev->dev, "%s: cap offset+len overflow detected\n", > + __func__); > + return false; > + } > > Vivek That should do it.