* [PATCH] net: ethtool: avoid allocation failure for dump_regs
@ 2017-01-18 13:34 David Arcari
2017-01-18 16:45 ` David Miller
0 siblings, 1 reply; 8+ messages in thread
From: David Arcari @ 2017-01-18 13:34 UTC (permalink / raw)
To: netdev; +Cc: David Arcari
If the user executes 'ethtool -d' for an interface and the associated
get_regs_len() function returns 0, the user will see a call trace from
the vmalloc() call in ethtool_get_regs(). This patch modifies
ethtool_get_regs() to avoid the call to vmalloc when the size is zero.
Signed-off-by: David Arcari <darcari@redhat.com>
---
net/core/ethtool.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index e23766c..47acd6f 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -1405,7 +1405,7 @@ static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
if (regs.len > reglen)
regs.len = reglen;
- regbuf = vzalloc(reglen);
+ regbuf = reglen ? vzalloc(reglen) : NULL;
if (reglen && !regbuf)
return -ENOMEM;
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] net: ethtool: avoid allocation failure for dump_regs
2017-01-18 13:34 [PATCH] net: ethtool: avoid allocation failure for dump_regs David Arcari
@ 2017-01-18 16:45 ` David Miller
2017-01-19 12:35 ` David Arcari
0 siblings, 1 reply; 8+ messages in thread
From: David Miller @ 2017-01-18 16:45 UTC (permalink / raw)
To: darcari; +Cc: netdev
From: David Arcari <darcari@redhat.com>
Date: Wed, 18 Jan 2017 08:34:05 -0500
> If the user executes 'ethtool -d' for an interface and the associated
> get_regs_len() function returns 0, the user will see a call trace from
> the vmalloc() call in ethtool_get_regs(). This patch modifies
> ethtool_get_regs() to avoid the call to vmalloc when the size is zero.
>
> Signed-off-by: David Arcari <darcari@redhat.com>
I think when the driver indicates this, it is equivalent to saying that
the operation isn't supported.
Also, this guards us against ->get_regs() methods that don't handle
zero length requests properly. I see many which are going to do
really terrible things in that situation.
Therefore, if get_regs_len() returns zero, treat it the safe as if the
ethtool operations were NULL.
Thanks.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] net: ethtool: avoid allocation failure for dump_regs
2017-01-18 16:45 ` David Miller
@ 2017-01-19 12:35 ` David Arcari
2017-01-19 14:15 ` John W. Linville
0 siblings, 1 reply; 8+ messages in thread
From: David Arcari @ 2017-01-19 12:35 UTC (permalink / raw)
To: David Miller; +Cc: netdev
On 01/18/2017 11:45 AM, David Miller wrote:
> From: David Arcari <darcari@redhat.com>
> Date: Wed, 18 Jan 2017 08:34:05 -0500
>
>> If the user executes 'ethtool -d' for an interface and the associated
>> get_regs_len() function returns 0, the user will see a call trace from
>> the vmalloc() call in ethtool_get_regs(). This patch modifies
>> ethtool_get_regs() to avoid the call to vmalloc when the size is zero.
>>
>> Signed-off-by: David Arcari <darcari@redhat.com>
> I think when the driver indicates this, it is equivalent to saying that
> the operation isn't supported.
>
> Also, this guards us against ->get_regs() methods that don't handle
> zero length requests properly. I see many which are going to do
> really terrible things in that situation.
>
> Therefore, if get_regs_len() returns zero, treat it the safe as if the
> ethtool operations were NULL.
>
> Thanks.
That was actually the fix that I was originally considering, but it
turns out
there is a problem with it.
I found that the vmalloc error was occurring because
ieee80211_get_regs_len() in
net/mac80211/ethtool.c was returning zero. The ieee80211_get_regs in
the same
file returns the hw version. It turns out that this information is used
by the
at76c50x-usb driver in the user space ethtool to report which HW variant
is in
use. Returning an error when regs_len() returns zero would break this
functionality.
-Dave
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] net: ethtool: avoid allocation failure for dump_regs
2017-01-19 12:35 ` David Arcari
@ 2017-01-19 14:15 ` John W. Linville
2017-01-19 15:56 ` John W. Linville
0 siblings, 1 reply; 8+ messages in thread
From: John W. Linville @ 2017-01-19 14:15 UTC (permalink / raw)
To: David Arcari; +Cc: David Miller, netdev
On Thu, Jan 19, 2017 at 07:35:22AM -0500, David Arcari wrote:
> On 01/18/2017 11:45 AM, David Miller wrote:
> > From: David Arcari <darcari@redhat.com>
> > Date: Wed, 18 Jan 2017 08:34:05 -0500
> >
> >> If the user executes 'ethtool -d' for an interface and the associated
> >> get_regs_len() function returns 0, the user will see a call trace from
> >> the vmalloc() call in ethtool_get_regs(). This patch modifies
> >> ethtool_get_regs() to avoid the call to vmalloc when the size is zero.
> >>
> >> Signed-off-by: David Arcari <darcari@redhat.com>
> > I think when the driver indicates this, it is equivalent to saying that
> > the operation isn't supported.
> >
> > Also, this guards us against ->get_regs() methods that don't handle
> > zero length requests properly. I see many which are going to do
> > really terrible things in that situation.
> >
> > Therefore, if get_regs_len() returns zero, treat it the safe as if the
> > ethtool operations were NULL.
> >
> > Thanks.
>
> That was actually the fix that I was originally considering, but it
> turns out
> there is a problem with it.
>
> I found that the vmalloc error was occurring because
> ieee80211_get_regs_len() in
> net/mac80211/ethtool.c was returning zero. The ieee80211_get_regs in
> the same
> file returns the hw version. It turns out that this information is used
> by the
> at76c50x-usb driver in the user space ethtool to report which HW variant
> is in
> use. Returning an error when regs_len() returns zero would break this
> functionality.
>
> -Dave
I'm responsible for this mess. The original idea was for various
mac80211-based drivers to override the ethtool operation and provide
their own dump operation, but the mac80211 crowd never embraced
the idea.
In the meantime, I added the default implementation which just
passed-up wdev->wiphy->hw_version as the version info for a 0-length
register dump. I then implemented a driver-specific regiser dump
handler for userland ethtool that would interpret the hardware version
information for the at76c50x-usb driver.
So the net of it is, if we treat a return of 0 from get_regs_len()
as "not supported", we break this one driver-specific feature for
userland ethtool. Realistically, there are probably very few users
to care. But I can't guarantee that the number is zero.
Possible solutions:
-- break userland ethtool for at76c50x-usb
-- avoid 0-len allocation attempt (David Arcari's patch)
-- make allocator accept a 0 length value w/o oops'ing
-- change mac8011 code to return non-zero from get_regs_len()
Thoughts? The last option holds a certain attraction, but I'm not
sure how to make it useful...?
John
--
John W. Linville Someday the world will need a hero, and you
linville@tuxdriver.com might be all we have. Be ready.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] net: ethtool: avoid allocation failure for dump_regs
2017-01-19 14:15 ` John W. Linville
@ 2017-01-19 15:56 ` John W. Linville
[not found] ` <20170119155620.GD6245-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: John W. Linville @ 2017-01-19 15:56 UTC (permalink / raw)
To: David Arcari; +Cc: David Miller, netdev, Johannes Berg, Kalle Valo
I forgot to Cc Johannes and Kalle...
On Thu, Jan 19, 2017 at 09:15:09AM -0500, John W. Linville wrote:
> On Thu, Jan 19, 2017 at 07:35:22AM -0500, David Arcari wrote:
> > On 01/18/2017 11:45 AM, David Miller wrote:
> > > From: David Arcari <darcari@redhat.com>
> > > Date: Wed, 18 Jan 2017 08:34:05 -0500
> > >
> > >> If the user executes 'ethtool -d' for an interface and the associated
> > >> get_regs_len() function returns 0, the user will see a call trace from
> > >> the vmalloc() call in ethtool_get_regs(). This patch modifies
> > >> ethtool_get_regs() to avoid the call to vmalloc when the size is zero.
> > >>
> > >> Signed-off-by: David Arcari <darcari@redhat.com>
> > > I think when the driver indicates this, it is equivalent to saying that
> > > the operation isn't supported.
> > >
> > > Also, this guards us against ->get_regs() methods that don't handle
> > > zero length requests properly. I see many which are going to do
> > > really terrible things in that situation.
> > >
> > > Therefore, if get_regs_len() returns zero, treat it the safe as if the
> > > ethtool operations were NULL.
> > >
> > > Thanks.
> >
> > That was actually the fix that I was originally considering, but it
> > turns out
> > there is a problem with it.
> >
> > I found that the vmalloc error was occurring because
> > ieee80211_get_regs_len() in
> > net/mac80211/ethtool.c was returning zero. The ieee80211_get_regs in
> > the same
> > file returns the hw version. It turns out that this information is used
> > by the
> > at76c50x-usb driver in the user space ethtool to report which HW variant
> > is in
> > use. Returning an error when regs_len() returns zero would break this
> > functionality.
> >
> > -Dave
>
> I'm responsible for this mess. The original idea was for various
> mac80211-based drivers to override the ethtool operation and provide
> their own dump operation, but the mac80211 crowd never embraced
> the idea.
>
> In the meantime, I added the default implementation which just
> passed-up wdev->wiphy->hw_version as the version info for a 0-length
> register dump. I then implemented a driver-specific regiser dump
> handler for userland ethtool that would interpret the hardware version
> information for the at76c50x-usb driver.
>
> So the net of it is, if we treat a return of 0 from get_regs_len()
> as "not supported", we break this one driver-specific feature for
> userland ethtool. Realistically, there are probably very few users
> to care. But I can't guarantee that the number is zero.
>
> Possible solutions:
>
> -- break userland ethtool for at76c50x-usb
> -- avoid 0-len allocation attempt (David Arcari's patch)
> -- make allocator accept a 0 length value w/o oops'ing
> -- change mac8011 code to return non-zero from get_regs_len()
>
> Thoughts? The last option holds a certain attraction, but I'm not
> sure how to make it useful...?
>
> John
>
> --
> John W. Linville Someday the world will need a hero, and you
> linville@tuxdriver.com might be all we have. Be ready.
>
--
John W. Linville Someday the world will need a hero, and you
linville@tuxdriver.com might be all we have. Be ready.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] net: ethtool: avoid allocation failure for dump_regs
[not found] ` <20170119155620.GD6245-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org>
@ 2017-01-19 18:08 ` Kalle Valo
[not found] ` <87h94uorc1.fsf-HodKDYzPHsUD5k0oWYwrnHL1okKdlPRT@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: Kalle Valo @ 2017-01-19 18:08 UTC (permalink / raw)
To: John W. Linville
Cc: David Arcari, David Miller, netdev-u79uwXL29TY76Z2rM5mHXA,
Johannes Berg, linux-wireless-u79uwXL29TY76Z2rM5mHXA
"John W. Linville" <linville-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org> writes:
> I forgot to Cc Johannes and Kalle...
Also adding linux-wireless.
> On Thu, Jan 19, 2017 at 09:15:09AM -0500, John W. Linville wrote:
>> On Thu, Jan 19, 2017 at 07:35:22AM -0500, David Arcari wrote:
>> > On 01/18/2017 11:45 AM, David Miller wrote:
>> > > From: David Arcari <darcari-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
>> > > Date: Wed, 18 Jan 2017 08:34:05 -0500
>> > >
>> > >> If the user executes 'ethtool -d' for an interface and the associated
>> > >> get_regs_len() function returns 0, the user will see a call trace from
>> > >> the vmalloc() call in ethtool_get_regs(). This patch modifies
>> > >> ethtool_get_regs() to avoid the call to vmalloc when the size is zero.
>> > >>
>> > >> Signed-off-by: David Arcari <darcari-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
>> > > I think when the driver indicates this, it is equivalent to saying that
>> > > the operation isn't supported.
>> > >
>> > > Also, this guards us against ->get_regs() methods that don't handle
>> > > zero length requests properly. I see many which are going to do
>> > > really terrible things in that situation.
>> > >
>> > > Therefore, if get_regs_len() returns zero, treat it the safe as if the
>> > > ethtool operations were NULL.
>> > >
>> > > Thanks.
>> >
>> > That was actually the fix that I was originally considering, but it
>> > turns out
>> > there is a problem with it.
>> >
>> > I found that the vmalloc error was occurring because
>> > ieee80211_get_regs_len() in
>> > net/mac80211/ethtool.c was returning zero. The ieee80211_get_regs in
>> > the same
>> > file returns the hw version. It turns out that this information is used
>> > by the
>> > at76c50x-usb driver in the user space ethtool to report which HW variant
>> > is in
>> > use. Returning an error when regs_len() returns zero would break this
>> > functionality.
>> >
>> > -Dave
>>
>> I'm responsible for this mess. The original idea was for various
>> mac80211-based drivers to override the ethtool operation and provide
>> their own dump operation, but the mac80211 crowd never embraced
>> the idea.
>>
>> In the meantime, I added the default implementation which just
>> passed-up wdev->wiphy->hw_version as the version info for a 0-length
>> register dump. I then implemented a driver-specific regiser dump
>> handler for userland ethtool that would interpret the hardware version
>> information for the at76c50x-usb driver.
>>
>> So the net of it is, if we treat a return of 0 from get_regs_len()
>> as "not supported", we break this one driver-specific feature for
>> userland ethtool. Realistically, there are probably very few users
>> to care. But I can't guarantee that the number is zero.
I know the number is not zero, because I remember using it years back
with something else than at76c50x-usb. But is the number more than one,
I don't know :)
>> Possible solutions:
>>
>> -- break userland ethtool for at76c50x-usb
>> -- avoid 0-len allocation attempt (David Arcari's patch)
>> -- make allocator accept a 0 length value w/o oops'ing
>> -- change mac8011 code to return non-zero from get_regs_len()
>>
>> Thoughts? The last option holds a certain attraction, but I'm not
>> sure how to make it useful...?
If it were only about at76c50x-usb I would say go for it, nobody sane
should use that device anymore. But on the other hand I'm worried that
this interface might be used by other (proprietary) user space tools
with other, more important, drivers. A difficult situation.
--
Kalle Valo
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] net: ethtool: avoid allocation failure for dump_regs
[not found] ` <87h94uorc1.fsf-HodKDYzPHsUD5k0oWYwrnHL1okKdlPRT@public.gmane.org>
@ 2017-01-19 19:22 ` David Miller
2017-01-20 11:44 ` Kalle Valo
0 siblings, 1 reply; 8+ messages in thread
From: David Miller @ 2017-01-19 19:22 UTC (permalink / raw)
To: kvalo-sgV2jX0FEOL9JmXXK+q4OQ
Cc: linville-2XuSBdqkA4R54TAoqtyWWQ, darcari-H+wXaHxf7aLQT0dZR+AlfA,
netdev-u79uwXL29TY76Z2rM5mHXA,
johannes.berg-ral2JQCrhuEAvxtiuMwx3w,
linux-wireless-u79uwXL29TY76Z2rM5mHXA
From: Kalle Valo <kvalo-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
Date: Thu, 19 Jan 2017 20:08:30 +0200
> "John W. Linville" <linville-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org> writes:
>
>> I forgot to Cc Johannes and Kalle...
>
> Also adding linux-wireless.
>
>> On Thu, Jan 19, 2017 at 09:15:09AM -0500, John W. Linville wrote:
>>> On Thu, Jan 19, 2017 at 07:35:22AM -0500, David Arcari wrote:
>>> > On 01/18/2017 11:45 AM, David Miller wrote:
>>> > > From: David Arcari <darcari-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
>>> > > Date: Wed, 18 Jan 2017 08:34:05 -0500
>>> > >
>>> > >> If the user executes 'ethtool -d' for an interface and the associated
>>> > >> get_regs_len() function returns 0, the user will see a call trace from
>>> > >> the vmalloc() call in ethtool_get_regs(). This patch modifies
>>> > >> ethtool_get_regs() to avoid the call to vmalloc when the size is zero.
>>> > >>
>>> > >> Signed-off-by: David Arcari <darcari-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
>>> > > I think when the driver indicates this, it is equivalent to saying that
>>> > > the operation isn't supported.
>>> > >
>>> > > Also, this guards us against ->get_regs() methods that don't handle
>>> > > zero length requests properly. I see many which are going to do
>>> > > really terrible things in that situation.
>>> > >
>>> > > Therefore, if get_regs_len() returns zero, treat it the safe as if the
>>> > > ethtool operations were NULL.
>>> > >
>>> > > Thanks.
>>> >
>>> > That was actually the fix that I was originally considering, but it
>>> > turns out
>>> > there is a problem with it.
>>> >
>>> > I found that the vmalloc error was occurring because
>>> > ieee80211_get_regs_len() in
>>> > net/mac80211/ethtool.c was returning zero. The ieee80211_get_regs in
>>> > the same
>>> > file returns the hw version. It turns out that this information is used
>>> > by the
>>> > at76c50x-usb driver in the user space ethtool to report which HW variant
>>> > is in
>>> > use. Returning an error when regs_len() returns zero would break this
>>> > functionality.
>>> >
>>> > -Dave
>>>
>>> I'm responsible for this mess. The original idea was for various
>>> mac80211-based drivers to override the ethtool operation and provide
>>> their own dump operation, but the mac80211 crowd never embraced
>>> the idea.
>>>
>>> In the meantime, I added the default implementation which just
>>> passed-up wdev->wiphy->hw_version as the version info for a 0-length
>>> register dump. I then implemented a driver-specific regiser dump
>>> handler for userland ethtool that would interpret the hardware version
>>> information for the at76c50x-usb driver.
>>>
>>> So the net of it is, if we treat a return of 0 from get_regs_len()
>>> as "not supported", we break this one driver-specific feature for
>>> userland ethtool. Realistically, there are probably very few users
>>> to care. But I can't guarantee that the number is zero.
>
> I know the number is not zero, because I remember using it years back
> with something else than at76c50x-usb. But is the number more than one,
> I don't know :)
I'm trying to dig down and figure out why this problem is showing up now.
ethtool_get_regs() has been using vzalloc() since 2011, and before that it
used plain vmalloc().
This code has therefore been using v{m,z}alloc() forever. What changed?
The zero size check has been in the vmalloc implementation since at least
2009.
I don't understand why this is all triggering and being noticed now. The
whole ieee80211 "return zero length regs and return hw version in get_regs"
thing should have been failing for at least 7 years now.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] net: ethtool: avoid allocation failure for dump_regs
2017-01-19 19:22 ` David Miller
@ 2017-01-20 11:44 ` Kalle Valo
0 siblings, 0 replies; 8+ messages in thread
From: Kalle Valo @ 2017-01-20 11:44 UTC (permalink / raw)
To: David Miller; +Cc: linville, darcari, netdev, johannes.berg, linux-wireless
David Miller <davem@davemloft.net> writes:
> From: Kalle Valo <kvalo@codeaurora.org>
> Date: Thu, 19 Jan 2017 20:08:30 +0200
>
>> "John W. Linville" <linville@tuxdriver.com> writes:
>>
>>> I forgot to Cc Johannes and Kalle...
>>
>> Also adding linux-wireless.
>>
>>> On Thu, Jan 19, 2017 at 09:15:09AM -0500, John W. Linville wrote:
>>>
>>>> I'm responsible for this mess. The original idea was for various
>>>> mac80211-based drivers to override the ethtool operation and provide
>>>> their own dump operation, but the mac80211 crowd never embraced
>>>> the idea.
>>>>
>>>> In the meantime, I added the default implementation which just
>>>> passed-up wdev->wiphy->hw_version as the version info for a 0-length
>>>> register dump. I then implemented a driver-specific regiser dump
>>>> handler for userland ethtool that would interpret the hardware version
>>>> information for the at76c50x-usb driver.
>>>>
>>>> So the net of it is, if we treat a return of 0 from get_regs_len()
>>>> as "not supported", we break this one driver-specific feature for
>>>> userland ethtool. Realistically, there are probably very few users
>>>> to care. But I can't guarantee that the number is zero.
>>
>> I know the number is not zero, because I remember using it years back
>> with something else than at76c50x-usb. But is the number more than one,
>> I don't know :)
>
> I'm trying to dig down and figure out why this problem is showing up now.
> ethtool_get_regs() has been using vzalloc() since 2011, and before that it
> used plain vmalloc().
>
> This code has therefore been using v{m,z}alloc() forever. What changed?
>
> The zero size check has been in the vmalloc implementation since at least
> 2009.
>
> I don't understand why this is all triggering and being noticed now. The
> whole ieee80211 "return zero length regs and return hw version in get_regs"
> thing should have been failing for at least 7 years now.
Maybe just nobody hasn't used it since? If my memory serves me right
(too often it does not) It's 6-7 years since I used this, and if the
kernel I worked on at the time was a year or two old, I might have used
a version without the zero size check.
But I'm just hand-waving here, I cannot be sure what's the last kernel I
used.
--
Kalle Valo
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2017-01-20 11:44 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-18 13:34 [PATCH] net: ethtool: avoid allocation failure for dump_regs David Arcari
2017-01-18 16:45 ` David Miller
2017-01-19 12:35 ` David Arcari
2017-01-19 14:15 ` John W. Linville
2017-01-19 15:56 ` John W. Linville
[not found] ` <20170119155620.GD6245-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org>
2017-01-19 18:08 ` Kalle Valo
[not found] ` <87h94uorc1.fsf-HodKDYzPHsUD5k0oWYwrnHL1okKdlPRT@public.gmane.org>
2017-01-19 19:22 ` David Miller
2017-01-20 11:44 ` Kalle Valo
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).