* [PATCH for 5.10] vdpa_sim: fix param validation in vdpasim_get_config()
@ 2021-02-11 16:25 Stefano Garzarella
2021-02-15 14:32 ` Greg KH
2021-02-18 6:39 ` Jason Wang
0 siblings, 2 replies; 6+ messages in thread
From: Stefano Garzarella @ 2021-02-11 16:25 UTC (permalink / raw)
To: stable; +Cc: Michael S. Tsirkin, linux-kernel, virtualization, Eli Cohen
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@vger.kernel.org> # 5.10.x
Signed-off-by: Stefano Garzarella <sgarzare@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
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH for 5.10] vdpa_sim: fix param validation in vdpasim_get_config() 2021-02-11 16:25 [PATCH for 5.10] vdpa_sim: fix param validation in vdpasim_get_config() Stefano Garzarella @ 2021-02-15 14:32 ` Greg KH 2021-02-15 15:03 ` Stefano Garzarella 2021-02-18 6:39 ` Jason Wang 1 sibling, 1 reply; 6+ messages in thread From: Greg KH @ 2021-02-15 14:32 UTC (permalink / raw) To: Stefano Garzarella Cc: Michael S. Tsirkin, linux-kernel, stable, virtualization, Eli Cohen 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@vger.kernel.org> # 5.10.x > Signed-off-by: Stefano Garzarella <sgarzare@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 _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH for 5.10] vdpa_sim: fix param validation in vdpasim_get_config() 2021-02-15 14:32 ` Greg KH @ 2021-02-15 15:03 ` Stefano Garzarella 2021-02-15 15:23 ` Greg KH 0 siblings, 1 reply; 6+ messages in thread From: Stefano Garzarella @ 2021-02-15 15:03 UTC (permalink / raw) To: Greg KH; +Cc: Michael S. Tsirkin, linux-kernel, stable, virtualization, Eli Cohen On Mon, Feb 15, 2021 at 03:32:19PM +0100, Greg KH wrote: >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. Oops, sorry. > >> 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@vger.kernel.org> # 5.10.x >> Signed-off-by: Stefano Garzarella <sgarzare@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? Because that patch depends on the following patches merged in v5.11-rc1 while refactoring vdpa_sim: f37cbbc65178 vdpa_sim: make 'config' generic and usable for any device type cf1a3b35382c vdpa_sim: store parsed MAC address in a buffer a13b5918fdd0 vdpa_sim: add work_fn in vdpasim_dev_attr 011c35bac5ef vdpa_sim: add supported_features field in vdpasim_dev_attr 2f8f46188805 vdpa_sim: add device id field in vdpasim_dev_attr 6c6e28fe4579 vdpa_sim: add struct vdpasim_dev_attr for device attributes 36a9c3063025 vdpa_sim: rename vdpasim_config_ops variables 423248d60d2b vdpa_sim: remove hard-coded virtq count Maybe we can skip some of them, but IMHO should be less risky to apply only this change. If you want I can try to figure out the minimum sub-set of patches needed for 65b709586e22 ("vdpa_sim: add get_config callback in vdpasim_dev_attr"). Thanks, Stefano _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH for 5.10] vdpa_sim: fix param validation in vdpasim_get_config() 2021-02-15 15:03 ` Stefano Garzarella @ 2021-02-15 15:23 ` Greg KH 2021-02-16 13:55 ` Stefano Garzarella 0 siblings, 1 reply; 6+ messages in thread From: Greg KH @ 2021-02-15 15:23 UTC (permalink / raw) To: Stefano Garzarella Cc: Michael S. Tsirkin, linux-kernel, stable, virtualization, Eli Cohen On Mon, Feb 15, 2021 at 04:03:21PM +0100, Stefano Garzarella wrote: > On Mon, Feb 15, 2021 at 03:32:19PM +0100, Greg KH wrote: > > 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. > > Oops, sorry. > > > > > > 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@vger.kernel.org> # 5.10.x > > > Signed-off-by: Stefano Garzarella <sgarzare@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? > > Because that patch depends on the following patches merged in v5.11-rc1 > while refactoring vdpa_sim: > f37cbbc65178 vdpa_sim: make 'config' generic and usable for any device type > cf1a3b35382c vdpa_sim: store parsed MAC address in a buffer > a13b5918fdd0 vdpa_sim: add work_fn in vdpasim_dev_attr > 011c35bac5ef vdpa_sim: add supported_features field in vdpasim_dev_attr > 2f8f46188805 vdpa_sim: add device id field in vdpasim_dev_attr > 6c6e28fe4579 vdpa_sim: add struct vdpasim_dev_attr for device attributes > 36a9c3063025 vdpa_sim: rename vdpasim_config_ops variables > 423248d60d2b vdpa_sim: remove hard-coded virtq count > > Maybe we can skip some of them, but IMHO should be less risky to apply only > this change. > > If you want I can try to figure out the minimum sub-set of patches needed > for 65b709586e22 ("vdpa_sim: add get_config callback in vdpasim_dev_attr"). The minimum is always nice :) If it's just too much churn for no good reason, then yes, the one-line change above will be ok, but you need to document the heck out of why this is not upstream and that it is a one-off thing. thanks, greg k-h _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH for 5.10] vdpa_sim: fix param validation in vdpasim_get_config() 2021-02-15 15:23 ` Greg KH @ 2021-02-16 13:55 ` Stefano Garzarella 0 siblings, 0 replies; 6+ messages in thread From: Stefano Garzarella @ 2021-02-16 13:55 UTC (permalink / raw) To: Greg KH; +Cc: Michael S. Tsirkin, linux-kernel, stable, virtualization, Eli Cohen On Mon, Feb 15, 2021 at 04:23:54PM +0100, Greg KH wrote: >On Mon, Feb 15, 2021 at 04:03:21PM +0100, Stefano Garzarella wrote: >> On Mon, Feb 15, 2021 at 03:32:19PM +0100, Greg KH wrote: >> > 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. >> >> Oops, sorry. >> >> > >> > > 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@vger.kernel.org> # 5.10.x >> > > Signed-off-by: Stefano Garzarella <sgarzare@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? >> >> Because that patch depends on the following patches merged in v5.11-rc1 >> while refactoring vdpa_sim: >> f37cbbc65178 vdpa_sim: make 'config' generic and usable for any device type >> cf1a3b35382c vdpa_sim: store parsed MAC address in a buffer >> a13b5918fdd0 vdpa_sim: add work_fn in vdpasim_dev_attr >> 011c35bac5ef vdpa_sim: add supported_features field in vdpasim_dev_attr >> 2f8f46188805 vdpa_sim: add device id field in vdpasim_dev_attr >> 6c6e28fe4579 vdpa_sim: add struct vdpasim_dev_attr for device attributes >> 36a9c3063025 vdpa_sim: rename vdpasim_config_ops variables >> 423248d60d2b vdpa_sim: remove hard-coded virtq count >> >> Maybe we can skip some of them, but IMHO should be less risky to apply only >> this change. >> >> If you want I can try to figure out the minimum sub-set of patches needed >> for 65b709586e22 ("vdpa_sim: add get_config callback in vdpasim_dev_attr"). > >The minimum is always nice :) > The minimum set, including the patch that fixes the issue, is the following: 65b709586e22 vdpa_sim: add get_config callback in vdpasim_dev_attr f37cbbc65178 vdpa_sim: make 'config' generic and usable for any device type cf1a3b35382c vdpa_sim: store parsed MAC address in a buffer 6c6e28fe4579 vdpa_sim: add struct vdpasim_dev_attr for device attributes 423248d60d2b vdpa_sim: remove hard-coded virtq count The patches apply fairly cleanly. There are a few contextual differences due to the lack of the other patches: $ git backport-diff -u master -r linux-5.10.y..HEAD Key: [----] : patches are identical [####] : number of functional differences between upstream/downstream patch [down] : patch is downstream-only The flags [FC] indicate (F)unctional and (C)ontextual differences, respectively 001/5:[----] [--] 'vdpa_sim: remove hard-coded virtq count' 002/5:[----] [-C] 'vdpa_sim: add struct vdpasim_dev_attr for device attributes' 003/5:[----] [--] 'vdpa_sim: store parsed MAC address in a buffer' 004/5:[----] [-C] 'vdpa_sim: make 'config' generic and usable for any device type' 005/5:[----] [-C] 'vdpa_sim: add get_config callback in vdpasim_dev_attr' >If it's just too much churn for no good reason, then yes, the one-line >change above will be ok, but you need to document the heck out of why >this is not upstream and that it is a one-off thing. > Shortly I'll send the series to stable@vger.kernel.org so you can judge if it's okay or better to resend this patch with a better description. Thanks Stefano _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH for 5.10] vdpa_sim: fix param validation in vdpasim_get_config() 2021-02-11 16:25 [PATCH for 5.10] vdpa_sim: fix param validation in vdpasim_get_config() Stefano Garzarella 2021-02-15 14:32 ` Greg KH @ 2021-02-18 6:39 ` Jason Wang 1 sibling, 0 replies; 6+ messages in thread From: Jason Wang @ 2021-02-18 6:39 UTC (permalink / raw) To: Stefano Garzarella, stable Cc: Eli Cohen, Michael S. Tsirkin, linux-kernel, virtualization 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@vger.kernel.org> # 5.10.x > Signed-off-by: Stefano Garzarella <sgarzare@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@redhat.com> _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-02-18 6:39 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2021-02-11 16:25 [PATCH for 5.10] vdpa_sim: fix param validation in vdpasim_get_config() Stefano Garzarella 2021-02-15 14:32 ` Greg KH 2021-02-15 15:03 ` Stefano Garzarella 2021-02-15 15:23 ` Greg KH 2021-02-16 13:55 ` Stefano Garzarella 2021-02-18 6:39 ` Jason Wang
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).