netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ethtool: __ethtool_set_sg: check for function pointer before using it
@ 2011-03-17 16:37 Roger Luethi
  2011-03-17 16:52 ` Ben Hutchings
  2011-03-17 17:00 ` Michał Mirosław
  0 siblings, 2 replies; 4+ messages in thread
From: Roger Luethi @ 2011-03-17 16:37 UTC (permalink / raw)
  To: netdev

__ethtool_set_sg does not check if dev->ethtool_ops->set_sg is defined
which can result in a NULL pointer dereference when ethtool is used to
change SG settings for drivers without SG support.

Signed-off-by: Roger Luethi <rl@hellgate.ch>
---

Bug verified. Patch only compile-tested.

 net/core/ethtool.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index c1a71bb..a1086fb 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -1457,6 +1457,9 @@ static int __ethtool_set_sg(struct net_device *dev, u32 data)
 {
 	int err;
 
+	if (!dev->ethtool_ops->set_sg)
+		return -EOPNOTSUPP;
+
 	if (data && !(dev->features & NETIF_F_ALL_CSUM))
 		return -EINVAL;
 
-- 
1.7.3.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ethtool: __ethtool_set_sg: check for function pointer before using it
  2011-03-17 16:37 [PATCH] ethtool: __ethtool_set_sg: check for function pointer before using it Roger Luethi
@ 2011-03-17 16:52 ` Ben Hutchings
  2011-03-18 22:15   ` David Miller
  2011-03-17 17:00 ` Michał Mirosław
  1 sibling, 1 reply; 4+ messages in thread
From: Ben Hutchings @ 2011-03-17 16:52 UTC (permalink / raw)
  To: Roger Luethi, Michał Mirosław; +Cc: netdev

On Thu, 2011-03-17 at 17:37 +0100, Roger Luethi wrote:
> __ethtool_set_sg does not check if dev->ethtool_ops->set_sg is defined
> which can result in a NULL pointer dereference when ethtool is used to
> change SG settings for drivers without SG support.
> 
> Signed-off-by: Roger Luethi <rl@hellgate.ch>
Reviewed-by: Ben Hutchings <bhutchings@solarflare.com>

Michał, was this just an oversight or is there some reason why we
shouldn't check set_sg immediately?

Ben.

> ---
> 
> Bug verified. Patch only compile-tested.
>
>  net/core/ethtool.c |    3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)
> 
> diff --git a/net/core/ethtool.c b/net/core/ethtool.c
> index c1a71bb..a1086fb 100644
> --- a/net/core/ethtool.c
> +++ b/net/core/ethtool.c
> @@ -1457,6 +1457,9 @@ static int __ethtool_set_sg(struct net_device *dev, u32 data)
>  {
>  	int err;
>  
> +	if (!dev->ethtool_ops->set_sg)
> +		return -EOPNOTSUPP;
> +
>  	if (data && !(dev->features & NETIF_F_ALL_CSUM))
>  		return -EINVAL;
>  

-- 
Ben Hutchings, Senior Software Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ethtool: __ethtool_set_sg: check for function pointer before using it
  2011-03-17 16:37 [PATCH] ethtool: __ethtool_set_sg: check for function pointer before using it Roger Luethi
  2011-03-17 16:52 ` Ben Hutchings
@ 2011-03-17 17:00 ` Michał Mirosław
  1 sibling, 0 replies; 4+ messages in thread
From: Michał Mirosław @ 2011-03-17 17:00 UTC (permalink / raw)
  To: Roger Luethi; +Cc: netdev, David Miller

2011/3/17 Roger Luethi <rl@hellgate.ch>:
> __ethtool_set_sg does not check if dev->ethtool_ops->set_sg is defined
> which can result in a NULL pointer dereference when ethtool is used to
> change SG settings for drivers without SG support.
>
> Signed-off-by: Roger Luethi <rl@hellgate.ch>
> ---
>
> Bug verified. Patch only compile-tested.
>
>  net/core/ethtool.c |    3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)
>
> diff --git a/net/core/ethtool.c b/net/core/ethtool.c
> index c1a71bb..a1086fb 100644
> --- a/net/core/ethtool.c
> +++ b/net/core/ethtool.c
> @@ -1457,6 +1457,9 @@ static int __ethtool_set_sg(struct net_device *dev, u32 data)
>  {
>        int err;
>
> +       if (!dev->ethtool_ops->set_sg)
> +               return -EOPNOTSUPP;
> +
>        if (data && !(dev->features & NETIF_F_ALL_CSUM))
>                return -EINVAL;
>

Yes. __ethtool_set_sg() is the only function that was already there
before my unification series and I did tests only on drivers which had
set_sg() defined. :-/

This should go into 2.6.39 as a bugfix (adding Cc: DaveM).

Best Regards,
Michał Mirosław

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ethtool: __ethtool_set_sg: check for function pointer before using it
  2011-03-17 16:52 ` Ben Hutchings
@ 2011-03-18 22:15   ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2011-03-18 22:15 UTC (permalink / raw)
  To: bhutchings; +Cc: rl, mirq-linux, netdev

From: Ben Hutchings <bhutchings@solarflare.com>
Date: Thu, 17 Mar 2011 16:52:13 +0000

> On Thu, 2011-03-17 at 17:37 +0100, Roger Luethi wrote:
>> __ethtool_set_sg does not check if dev->ethtool_ops->set_sg is defined
>> which can result in a NULL pointer dereference when ethtool is used to
>> change SG settings for drivers without SG support.
>> 
>> Signed-off-by: Roger Luethi <rl@hellgate.ch>
> Reviewed-by: Ben Hutchings <bhutchings@solarflare.com>

Applied.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-03-18 22:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-17 16:37 [PATCH] ethtool: __ethtool_set_sg: check for function pointer before using it Roger Luethi
2011-03-17 16:52 ` Ben Hutchings
2011-03-18 22:15   ` David Miller
2011-03-17 17:00 ` Michał Mirosław

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).