Re: [PATCH v2] virtio-blk: limit seg_max to a safe value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, May 24, 2021 at 04:47:37PM -0400, Michael S. Tsirkin wrote:
> On Mon, May 24, 2021 at 04:40:20PM +0100, Stefan Hajnoczi wrote:
> > The struct virtio_blk_config seg_max value is read from the device and
> > incremented by 2 to account for the request header and status byte
> > descriptors added by the driver.
> > 
> > In preparation for supporting untrusted virtio-blk devices, protect
> > against integer overflow and limit the value to a safe maximum.
> > 
> > Signed-off-by: Stefan Hajnoczi <stefanha@xxxxxxxxxx>
> > ---
> > v2:
> >  * Limit to a virtio-specific value instead of using SG_MAX_SEGMENTS
> >    [Christoph]
> > ---
> >  drivers/block/virtio_blk.c | 8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
> > index b9fa3ef5b57c..1635d4289202 100644
> > --- a/drivers/block/virtio_blk.c
> > +++ b/drivers/block/virtio_blk.c
> > @@ -21,6 +21,9 @@
> >  #define VQ_NAME_LEN 16
> >  #define MAX_DISCARD_SEGMENTS 256u
> >  
> > +/* The maximum number of sg elements that fit into a virtqueue */
> > +#define VIRTIO_BLK_MAX_SG_ELEMS 32768
> 
> 32768 is what it says for split queues but for packed queues
> it says 2^15.
> 
> So 0x8000 then?

Yes.

2^15 = 0x8000 = 32768

> > +
> >  static int major;
> >  static DEFINE_IDA(vd_index_ida);
> >  
> > @@ -728,7 +731,10 @@ static int virtblk_probe(struct virtio_device *vdev)
> >  	if (err || !sg_elems)
> >  		sg_elems = 1;
> >  
> > -	/* We need an extra sg elements at head and tail. */
> 
> s/an extra/extra/

That line is being removed by this patch :).

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux