Re: [PATCH 04/20] virtio: Implement get_shm_region for PCI transport

From: Michael S. Tsirkin
Date: Tue Mar 10 2020 - 17:27:21 EST


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.