diff mbox series

[v2] rpmsg: virtio: don't let virtio core to validate used length

Message ID 20211124162045.25983-1-arnaud.pouliquen@foss.st.com (mailing list archive)
State Changes Requested
Headers show
Series [v2] rpmsg: virtio: don't let virtio core to validate used length | expand

Commit Message

Arnaud Pouliquen Nov. 24, 2021, 4:20 p.m. UTC
Using OpenAMP library on remote side, when the rpmsg framework tries to
reuse the buffer the following error message is displayed in
the virtqueue_get_buf_ctx_split function:
"virtio_rpmsg_bus virtio0: output:used len 28 is larger than in buflen 0"

As described in virtio specification:
"many drivers ignored the len value, as a result, many devices set len
incorrectly. Thus, when using the legacy interface, it is generally
a good idea to ignore the len value in used ring entries if possible."

To stay in compliance with the legacy libraries, this patch prevents the
virtio core from validating used length.

Fixes: 939779f5152d ("virtio_ring: validate used buffer length")

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
---
Update vs v1[1]: update commit message to clarify the context.

base-commit: fa55b7dcdc43c1aa1ba12bca9d2dd4318c2a0dbf

[1]https://lore.kernel.org/lkml/20211122160812.25125-1-arnaud.pouliquen@foss.st.com/T/
---
 drivers/rpmsg/virtio_rpmsg_bus.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Michael S. Tsirkin Nov. 24, 2021, 9:12 p.m. UTC | #1
On Wed, Nov 24, 2021 at 05:20:45PM +0100, Arnaud Pouliquen wrote:
> Using OpenAMP library on remote side, when the rpmsg framework tries to
> reuse the buffer the following error message is displayed in
> the virtqueue_get_buf_ctx_split function:
> "virtio_rpmsg_bus virtio0: output:used len 28 is larger than in buflen 0"
> 
> As described in virtio specification:
> "many drivers ignored the len value, as a result, many devices set len
> incorrectly. Thus, when using the legacy interface, it is generally
> a good idea to ignore the len value in used ring entries if possible."
> 
> To stay in compliance with the legacy libraries, this patch prevents the
> virtio core from validating used length.
> 
> Fixes: 939779f5152d ("virtio_ring: validate used buffer length")
> 
> Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
> Cc: Jason Wang <jasowang@redhat.com>
> Cc: Michael S. Tsirkin <mst@redhat.com>
> ---

Arnaud, thanks a lot for the analysis.

Jason, I think this is another good point. We really should not
validate input for legacy devices at all.


> Update vs v1[1]: update commit message to clarify the context.
> 
> base-commit: fa55b7dcdc43c1aa1ba12bca9d2dd4318c2a0dbf
> 
> [1]https://lore.kernel.org/lkml/20211122160812.25125-1-arnaud.pouliquen@foss.st.com/T/
> ---
>  drivers/rpmsg/virtio_rpmsg_bus.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
> index 9c112aa65040..5f73f19c2c38 100644
> --- a/drivers/rpmsg/virtio_rpmsg_bus.c
> +++ b/drivers/rpmsg/virtio_rpmsg_bus.c
> @@ -1054,6 +1054,7 @@ static struct virtio_driver virtio_ipc_driver = {
>  	.feature_table_size = ARRAY_SIZE(features),
>  	.driver.name	= KBUILD_MODNAME,
>  	.driver.owner	= THIS_MODULE,
> +	.suppress_used_validation = true,
>  	.id_table	= id_table,
>  	.probe		= rpmsg_probe,
>  	.remove		= rpmsg_remove,
> -- 
> 2.17.1
Jason Wang Nov. 25, 2021, 2:15 a.m. UTC | #2
On Thu, Nov 25, 2021 at 5:12 AM Michael S. Tsirkin <mst@redhat.com> wrote:
>
> On Wed, Nov 24, 2021 at 05:20:45PM +0100, Arnaud Pouliquen wrote:
> > Using OpenAMP library on remote side, when the rpmsg framework tries to
> > reuse the buffer the following error message is displayed in
> > the virtqueue_get_buf_ctx_split function:
> > "virtio_rpmsg_bus virtio0: output:used len 28 is larger than in buflen 0"
> >
> > As described in virtio specification:
> > "many drivers ignored the len value, as a result, many devices set len
> > incorrectly. Thus, when using the legacy interface, it is generally
> > a good idea to ignore the len value in used ring entries if possible."
> >
> > To stay in compliance with the legacy libraries, this patch prevents the
> > virtio core from validating used length.
> >
> > Fixes: 939779f5152d ("virtio_ring: validate used buffer length")
> >
> > Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
> > Cc: Jason Wang <jasowang@redhat.com>
> > Cc: Michael S. Tsirkin <mst@redhat.com>
> > ---
>
> Arnaud, thanks a lot for the analysis.
>
> Jason, I think this is another good point. We really should not
> validate input for legacy devices at all.

I agree. Will do that in the next version.

Thanks

>
>
> > Update vs v1[1]: update commit message to clarify the context.
> >
> > base-commit: fa55b7dcdc43c1aa1ba12bca9d2dd4318c2a0dbf
> >
> > [1]https://lore.kernel.org/lkml/20211122160812.25125-1-arnaud.pouliquen@foss.st.com/T/
> > ---
> >  drivers/rpmsg/virtio_rpmsg_bus.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
> > index 9c112aa65040..5f73f19c2c38 100644
> > --- a/drivers/rpmsg/virtio_rpmsg_bus.c
> > +++ b/drivers/rpmsg/virtio_rpmsg_bus.c
> > @@ -1054,6 +1054,7 @@ static struct virtio_driver virtio_ipc_driver = {
> >       .feature_table_size = ARRAY_SIZE(features),
> >       .driver.name    = KBUILD_MODNAME,
> >       .driver.owner   = THIS_MODULE,
> > +     .suppress_used_validation = true,
> >       .id_table       = id_table,
> >       .probe          = rpmsg_probe,
> >       .remove         = rpmsg_remove,
> > --
> > 2.17.1
>
Mathieu Poirier Dec. 2, 2021, 5 p.m. UTC | #3
Hey guys,

On Thu, Nov 25, 2021 at 10:15:44AM +0800, Jason Wang wrote:
> On Thu, Nov 25, 2021 at 5:12 AM Michael S. Tsirkin <mst@redhat.com> wrote:
> >
> > On Wed, Nov 24, 2021 at 05:20:45PM +0100, Arnaud Pouliquen wrote:
> > > Using OpenAMP library on remote side, when the rpmsg framework tries to
> > > reuse the buffer the following error message is displayed in
> > > the virtqueue_get_buf_ctx_split function:
> > > "virtio_rpmsg_bus virtio0: output:used len 28 is larger than in buflen 0"
> > >
> > > As described in virtio specification:
> > > "many drivers ignored the len value, as a result, many devices set len
> > > incorrectly. Thus, when using the legacy interface, it is generally
> > > a good idea to ignore the len value in used ring entries if possible."
> > >
> > > To stay in compliance with the legacy libraries, this patch prevents the
> > > virtio core from validating used length.
> > >
> > > Fixes: 939779f5152d ("virtio_ring: validate used buffer length")
> > >
> > > Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
> > > Cc: Jason Wang <jasowang@redhat.com>
> > > Cc: Michael S. Tsirkin <mst@redhat.com>
> > > ---
> >
> > Arnaud, thanks a lot for the analysis.
> >
> > Jason, I think this is another good point. We really should not
> > validate input for legacy devices at all.
> 
> I agree. Will do that in the next version.

I'm a little unclear about the "next version" in the above comment - is this
something I should wait for?  Should I move forward with Arnaud's patch?

Thanks,
Mathieu

> 
> Thanks
> 
> >
> >
> > > Update vs v1[1]: update commit message to clarify the context.
> > >
> > > base-commit: fa55b7dcdc43c1aa1ba12bca9d2dd4318c2a0dbf
> > >
> > > [1]https://lore.kernel.org/lkml/20211122160812.25125-1-arnaud.pouliquen@foss.st.com/T/
> > > ---
> > >  drivers/rpmsg/virtio_rpmsg_bus.c | 1 +
> > >  1 file changed, 1 insertion(+)
> > >
> > > diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
> > > index 9c112aa65040..5f73f19c2c38 100644
> > > --- a/drivers/rpmsg/virtio_rpmsg_bus.c
> > > +++ b/drivers/rpmsg/virtio_rpmsg_bus.c
> > > @@ -1054,6 +1054,7 @@ static struct virtio_driver virtio_ipc_driver = {
> > >       .feature_table_size = ARRAY_SIZE(features),
> > >       .driver.name    = KBUILD_MODNAME,
> > >       .driver.owner   = THIS_MODULE,
> > > +     .suppress_used_validation = true,
> > >       .id_table       = id_table,
> > >       .probe          = rpmsg_probe,
> > >       .remove         = rpmsg_remove,
> > > --
> > > 2.17.1
> >
>
Jason Wang Dec. 3, 2021, 2:07 a.m. UTC | #4
On Fri, Dec 3, 2021 at 1:00 AM Mathieu Poirier
<mathieu.poirier@linaro.org> wrote:
>
> Hey guys,
>
> On Thu, Nov 25, 2021 at 10:15:44AM +0800, Jason Wang wrote:
> > On Thu, Nov 25, 2021 at 5:12 AM Michael S. Tsirkin <mst@redhat.com> wrote:
> > >
> > > On Wed, Nov 24, 2021 at 05:20:45PM +0100, Arnaud Pouliquen wrote:
> > > > Using OpenAMP library on remote side, when the rpmsg framework tries to
> > > > reuse the buffer the following error message is displayed in
> > > > the virtqueue_get_buf_ctx_split function:
> > > > "virtio_rpmsg_bus virtio0: output:used len 28 is larger than in buflen 0"
> > > >
> > > > As described in virtio specification:
> > > > "many drivers ignored the len value, as a result, many devices set len
> > > > incorrectly. Thus, when using the legacy interface, it is generally
> > > > a good idea to ignore the len value in used ring entries if possible."
> > > >
> > > > To stay in compliance with the legacy libraries, this patch prevents the
> > > > virtio core from validating used length.
> > > >
> > > > Fixes: 939779f5152d ("virtio_ring: validate used buffer length")
> > > >
> > > > Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
> > > > Cc: Jason Wang <jasowang@redhat.com>
> > > > Cc: Michael S. Tsirkin <mst@redhat.com>
> > > > ---
> > >
> > > Arnaud, thanks a lot for the analysis.
> > >
> > > Jason, I think this is another good point. We really should not
> > > validate input for legacy devices at all.
> >
> > I agree. Will do that in the next version.
>
> I'm a little unclear about the "next version" in the above comment - is this
> something I should wait for?  Should I move forward with Arnaud's patch?

Just to make it clear. If my understanding is correct, my series was
reverted so this patch is not needed.

For "next version", I meant I will resend the new version of used
length validation that

- only do the validation when it was explicitly enabled
- warn instead of bug
- do not validate legacy device

Thanks

>
> Thanks,
> Mathieu
>
> >
> > Thanks
> >
> > >
> > >
> > > > Update vs v1[1]: update commit message to clarify the context.
> > > >
> > > > base-commit: fa55b7dcdc43c1aa1ba12bca9d2dd4318c2a0dbf
> > > >
> > > > [1]https://lore.kernel.org/lkml/20211122160812.25125-1-arnaud.pouliquen@foss.st.com/T/
> > > > ---
> > > >  drivers/rpmsg/virtio_rpmsg_bus.c | 1 +
> > > >  1 file changed, 1 insertion(+)
> > > >
> > > > diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
> > > > index 9c112aa65040..5f73f19c2c38 100644
> > > > --- a/drivers/rpmsg/virtio_rpmsg_bus.c
> > > > +++ b/drivers/rpmsg/virtio_rpmsg_bus.c
> > > > @@ -1054,6 +1054,7 @@ static struct virtio_driver virtio_ipc_driver = {
> > > >       .feature_table_size = ARRAY_SIZE(features),
> > > >       .driver.name    = KBUILD_MODNAME,
> > > >       .driver.owner   = THIS_MODULE,
> > > > +     .suppress_used_validation = true,
> > > >       .id_table       = id_table,
> > > >       .probe          = rpmsg_probe,
> > > >       .remove         = rpmsg_remove,
> > > > --
> > > > 2.17.1
> > >
> >
>
Arnaud Pouliquen Dec. 3, 2021, 2:34 p.m. UTC | #5
On 12/3/21 3:07 AM, Jason Wang wrote:
> On Fri, Dec 3, 2021 at 1:00 AM Mathieu Poirier
> <mathieu.poirier@linaro.org> wrote:
>>
>> Hey guys,
>>
>> On Thu, Nov 25, 2021 at 10:15:44AM +0800, Jason Wang wrote:
>>> On Thu, Nov 25, 2021 at 5:12 AM Michael S. Tsirkin <mst@redhat.com> wrote:
>>>>
>>>> On Wed, Nov 24, 2021 at 05:20:45PM +0100, Arnaud Pouliquen wrote:
>>>>> Using OpenAMP library on remote side, when the rpmsg framework tries to
>>>>> reuse the buffer the following error message is displayed in
>>>>> the virtqueue_get_buf_ctx_split function:
>>>>> "virtio_rpmsg_bus virtio0: output:used len 28 is larger than in buflen 0"
>>>>>
>>>>> As described in virtio specification:
>>>>> "many drivers ignored the len value, as a result, many devices set len
>>>>> incorrectly. Thus, when using the legacy interface, it is generally
>>>>> a good idea to ignore the len value in used ring entries if possible."
>>>>>
>>>>> To stay in compliance with the legacy libraries, this patch prevents the
>>>>> virtio core from validating used length.
>>>>>
>>>>> Fixes: 939779f5152d ("virtio_ring: validate used buffer length")
>>>>>
>>>>> Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
>>>>> Cc: Jason Wang <jasowang@redhat.com>
>>>>> Cc: Michael S. Tsirkin <mst@redhat.com>
>>>>> ---
>>>>
>>>> Arnaud, thanks a lot for the analysis.
>>>>
>>>> Jason, I think this is another good point. We really should not
>>>> validate input for legacy devices at all.
>>>
>>> I agree. Will do that in the next version.
>>
>> I'm a little unclear about the "next version" in the above comment - is this
>> something I should wait for?  Should I move forward with Arnaud's patch?
> 
> Just to make it clear. If my understanding is correct, my series was
> reverted so this patch is not needed.

Indeed your patchset is no longer in the v5.16-rc3

Thanks,
Arnaud

> 
> For "next version", I meant I will resend the new version of used
> length validation that
> 
> - only do the validation when it was explicitly enabled
> - warn instead of bug
> - do not validate legacy device
> 
> Thanks
> 
>>
>> Thanks,
>> Mathieu
>>
>>>
>>> Thanks
>>>
>>>>
>>>>
>>>>> Update vs v1[1]: update commit message to clarify the context.
>>>>>
>>>>> base-commit: fa55b7dcdc43c1aa1ba12bca9d2dd4318c2a0dbf
>>>>>
>>>>> [1]https://lore.kernel.org/lkml/20211122160812.25125-1-arnaud.pouliquen@foss.st.com/T/
>>>>> ---
>>>>>  drivers/rpmsg/virtio_rpmsg_bus.c | 1 +
>>>>>  1 file changed, 1 insertion(+)
>>>>>
>>>>> diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
>>>>> index 9c112aa65040..5f73f19c2c38 100644
>>>>> --- a/drivers/rpmsg/virtio_rpmsg_bus.c
>>>>> +++ b/drivers/rpmsg/virtio_rpmsg_bus.c
>>>>> @@ -1054,6 +1054,7 @@ static struct virtio_driver virtio_ipc_driver = {
>>>>>       .feature_table_size = ARRAY_SIZE(features),
>>>>>       .driver.name    = KBUILD_MODNAME,
>>>>>       .driver.owner   = THIS_MODULE,
>>>>> +     .suppress_used_validation = true,
>>>>>       .id_table       = id_table,
>>>>>       .probe          = rpmsg_probe,
>>>>>       .remove         = rpmsg_remove,
>>>>> --
>>>>> 2.17.1
>>>>
>>>
>>
>
Mathieu Poirier Dec. 3, 2021, 6:57 p.m. UTC | #6
On Thu, 2 Dec 2021 at 19:07, Jason Wang <jasowang@redhat.com> wrote:
>
> On Fri, Dec 3, 2021 at 1:00 AM Mathieu Poirier
> <mathieu.poirier@linaro.org> wrote:
> >
> > Hey guys,
> >
> > On Thu, Nov 25, 2021 at 10:15:44AM +0800, Jason Wang wrote:
> > > On Thu, Nov 25, 2021 at 5:12 AM Michael S. Tsirkin <mst@redhat.com> wrote:
> > > >
> > > > On Wed, Nov 24, 2021 at 05:20:45PM +0100, Arnaud Pouliquen wrote:
> > > > > Using OpenAMP library on remote side, when the rpmsg framework tries to
> > > > > reuse the buffer the following error message is displayed in
> > > > > the virtqueue_get_buf_ctx_split function:
> > > > > "virtio_rpmsg_bus virtio0: output:used len 28 is larger than in buflen 0"
> > > > >
> > > > > As described in virtio specification:
> > > > > "many drivers ignored the len value, as a result, many devices set len
> > > > > incorrectly. Thus, when using the legacy interface, it is generally
> > > > > a good idea to ignore the len value in used ring entries if possible."
> > > > >
> > > > > To stay in compliance with the legacy libraries, this patch prevents the
> > > > > virtio core from validating used length.
> > > > >
> > > > > Fixes: 939779f5152d ("virtio_ring: validate used buffer length")
> > > > >
> > > > > Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
> > > > > Cc: Jason Wang <jasowang@redhat.com>
> > > > > Cc: Michael S. Tsirkin <mst@redhat.com>
> > > > > ---
> > > >
> > > > Arnaud, thanks a lot for the analysis.
> > > >
> > > > Jason, I think this is another good point. We really should not
> > > > validate input for legacy devices at all.
> > >
> > > I agree. Will do that in the next version.
> >
> > I'm a little unclear about the "next version" in the above comment - is this
> > something I should wait for?  Should I move forward with Arnaud's patch?
>
> Just to make it clear. If my understanding is correct, my series was
> reverted so this patch is not needed.

Ok - thanks
diff mbox series

Patch

diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
index 9c112aa65040..5f73f19c2c38 100644
--- a/drivers/rpmsg/virtio_rpmsg_bus.c
+++ b/drivers/rpmsg/virtio_rpmsg_bus.c
@@ -1054,6 +1054,7 @@  static struct virtio_driver virtio_ipc_driver = {
 	.feature_table_size = ARRAY_SIZE(features),
 	.driver.name	= KBUILD_MODNAME,
 	.driver.owner	= THIS_MODULE,
+	.suppress_used_validation = true,
 	.id_table	= id_table,
 	.probe		= rpmsg_probe,
 	.remove		= rpmsg_remove,