Stefano Garzarella
2021-Feb-11 16:25 UTC
[PATCH for 5.10] vdpa_sim: fix param validation in vdpasim_get_config()
Commit 65b709586e222fa6ffd4166ac7fdb5d5dad113ee upstream. Before this patch, if 'offset + len' was equal to sizeof(struct virtio_net_config), the entire buffer wasn't filled, returning incorrect values to the caller. Since 'vdpasim->config' type is 'struct virtio_net_config', we can safely copy its content under this condition. Commit 65b709586e22 ("vdpa_sim: add get_config callback in vdpasim_dev_attr") unintentionally solved it upstream while refactoring vdpa_sim.c to support multiple devices. But we don't want to backport it to stable branches as it contains many changes. Fixes: 2c53d0f64c06 ("vdpasim: vDPA device simulator") Cc: <stable at vger.kernel.org> # 5.10.x Signed-off-by: Stefano Garzarella <sgarzare at redhat.com> --- drivers/vdpa/vdpa_sim/vdpa_sim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c index 6a90fdb9cbfc..8ca178d7b02f 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -572,7 +572,7 @@ static void vdpasim_get_config(struct vdpa_device *vdpa, unsigned int offset, { struct vdpasim *vdpasim = vdpa_to_sim(vdpa); - if (offset + len < sizeof(struct virtio_net_config)) + if (offset + len <= sizeof(struct virtio_net_config)) memcpy(buf, (u8 *)&vdpasim->config + offset, len); } -- 2.29.2
Greg KH
2021-Feb-15 14:32 UTC
[PATCH for 5.10] vdpa_sim: fix param validation in vdpasim_get_config()
On Thu, Feb 11, 2021 at 05:25:19PM +0100, Stefano Garzarella wrote:> Commit 65b709586e222fa6ffd4166ac7fdb5d5dad113ee upstream.No, this really is not that commit, so please do not say it is.> Before this patch, if 'offset + len' was equal to > sizeof(struct virtio_net_config), the entire buffer wasn't filled, > returning incorrect values to the caller. > > Since 'vdpasim->config' type is 'struct virtio_net_config', we can > safely copy its content under this condition. > > Commit 65b709586e22 ("vdpa_sim: add get_config callback in > vdpasim_dev_attr") unintentionally solved it upstream while > refactoring vdpa_sim.c to support multiple devices. But we don't want > to backport it to stable branches as it contains many changes. > > Fixes: 2c53d0f64c06 ("vdpasim: vDPA device simulator") > Cc: <stable at vger.kernel.org> # 5.10.x > Signed-off-by: Stefano Garzarella <sgarzare at redhat.com> > --- > drivers/vdpa/vdpa_sim/vdpa_sim.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c > index 6a90fdb9cbfc..8ca178d7b02f 100644 > --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c > +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c > @@ -572,7 +572,7 @@ static void vdpasim_get_config(struct vdpa_device *vdpa, unsigned int offset, > { > struct vdpasim *vdpasim = vdpa_to_sim(vdpa); > > - if (offset + len < sizeof(struct virtio_net_config)) > + if (offset + len <= sizeof(struct virtio_net_config)) > memcpy(buf, (u8 *)&vdpasim->config + offset, len); > }I'll be glad to take a one-off patch, but why can't we take the real upstream patch? That is always the better long-term solution, right? thanks, greg k-h
Jason Wang
2021-Feb-18 06:39 UTC
[PATCH for 5.10] vdpa_sim: fix param validation in vdpasim_get_config()
On 2021/2/12 ??12:25, Stefano Garzarella wrote:> Commit 65b709586e222fa6ffd4166ac7fdb5d5dad113ee upstream. > > Before this patch, if 'offset + len' was equal to > sizeof(struct virtio_net_config), the entire buffer wasn't filled, > returning incorrect values to the caller. > > Since 'vdpasim->config' type is 'struct virtio_net_config', we can > safely copy its content under this condition. > > Commit 65b709586e22 ("vdpa_sim: add get_config callback in > vdpasim_dev_attr") unintentionally solved it upstream while > refactoring vdpa_sim.c to support multiple devices. But we don't want > to backport it to stable branches as it contains many changes. > > Fixes: 2c53d0f64c06 ("vdpasim: vDPA device simulator") > Cc: <stable at vger.kernel.org> # 5.10.x > Signed-off-by: Stefano Garzarella <sgarzare at redhat.com> > --- > drivers/vdpa/vdpa_sim/vdpa_sim.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c > index 6a90fdb9cbfc..8ca178d7b02f 100644 > --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c > +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c > @@ -572,7 +572,7 @@ static void vdpasim_get_config(struct vdpa_device *vdpa, unsigned int offset, > { > struct vdpasim *vdpasim = vdpa_to_sim(vdpa); > > - if (offset + len < sizeof(struct virtio_net_config)) > + if (offset + len <= sizeof(struct virtio_net_config)) > memcpy(buf, (u8 *)&vdpasim->config + offset, len); > } >Acked-by: Jason Wang <jasowang at redhat.com>