netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Advertise PPPoE MTU / avoid memory leak.
@ 2006-09-23 17:30 mostrows
  2006-09-23 21:56 ` David Miller
  2006-09-26  6:32 ` Pekka Savola
  0 siblings, 2 replies; 7+ messages in thread
From: mostrows @ 2006-09-23 17:30 UTC (permalink / raw)
  To: linux-kernel, netdev, ppp-bugs; +Cc: Michal Ostrowski

PPPoE must advertise the underlying device's MTU via the ppp channel
descriptor structure, as multilink functionality depends on it.

__pppoe_xmit must free any skb it allocates if there is an error
submitting the skb downstream.

Signed-off-by: Michal Ostrowski <mostrows@earthlink.net>
---
 drivers/net/pppoe.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/drivers/net/pppoe.c b/drivers/net/pppoe.c
index 475dc93..b4dc516 100644
--- a/drivers/net/pppoe.c
+++ b/drivers/net/pppoe.c
@@ -600,6 +600,7 @@ static int pppoe_connect(struct socket *
 		po->chan.hdrlen = (sizeof(struct pppoe_hdr) +
 				   dev->hard_header_len);
 
+		po->chan.mtu = dev->mtu - sizeof(struct pppoe_hdr);
 		po->chan.private = sk;
 		po->chan.ops = &pppoe_chan_ops;
 
@@ -831,7 +832,7 @@ static int __pppoe_xmit(struct sock *sk,
 	struct pppoe_hdr *ph;
 	int headroom = skb_headroom(skb);
 	int data_len = skb->len;
-	struct sk_buff *skb2;
+	struct sk_buff *skb2 = NULL;
 
 	if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED))
 		goto abort;
@@ -887,6 +888,8 @@ static int __pppoe_xmit(struct sock *sk,
 	return 1;
 
 abort:
+	if (skb2)
+		kfree_skb(skb2);
 	return 0;
 }
 
-- 
1.4.1.1


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

* Re: [PATCH] Advertise PPPoE MTU / avoid memory leak.
  2006-09-23 17:30 [PATCH] Advertise PPPoE MTU / avoid memory leak mostrows
@ 2006-09-23 21:56 ` David Miller
  2006-09-24 12:29   ` Michal Ostrowski
  2006-09-26  6:32 ` Pekka Savola
  1 sibling, 1 reply; 7+ messages in thread
From: David Miller @ 2006-09-23 21:56 UTC (permalink / raw)
  To: mostrows; +Cc: linux-kernel, netdev, ppp-bugs

From: mostrows@earthlink.net
Date: Sat, 23 Sep 2006 12:30:23 -0500

> __pppoe_xmit must free any skb it allocates if there is an error
> submitting the skb downstream.

This isn't right, dev_queue_xmit() can return -ENETDOWN and still
free the SKB, so your change will cause the SKB to be freed up
twice in that case, from dev_queue_xmit():

	rc = -ENETDOWN;
	rcu_read_unlock_bh();

out_kfree_skb:
	kfree_skb(skb);
	return rc;

dev_queue_xmit() is basically expected to consume the packet,
error or not.

What case of calling dev_queue_xmit() did you discover that did not
kfree the SKB on error?  We should fix that.  On a quick scan on the
entire dev_queue_xmit() implmentation, I cannot find such a case.

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

* Re: [PATCH] Advertise PPPoE MTU / avoid memory leak.
  2006-09-23 21:56 ` David Miller
@ 2006-09-24 12:29   ` Michal Ostrowski
  2006-09-25  1:41     ` David Miller
  0 siblings, 1 reply; 7+ messages in thread
From: Michal Ostrowski @ 2006-09-24 12:29 UTC (permalink / raw)
  To: David Miller; +Cc: linux-kernel, netdev, ppp-bugs

On Sat, 2006-09-23 at 14:56 -0700, David Miller wrote:
> From: mostrows@earthlink.net
> Date: Sat, 23 Sep 2006 12:30:23 -0500
> 
> > __pppoe_xmit must free any skb it allocates if there is an error
> > submitting the skb downstream.
> 
> This isn't right, dev_queue_xmit() can return -ENETDOWN and still
> free the SKB, so your change will cause the SKB to be freed up
> twice in that case, from dev_queue_xmit():
> 
> 	rc = -ENETDOWN;
> 	rcu_read_unlock_bh();
> 
> out_kfree_skb:
> 	kfree_skb(skb);
> 	return rc;
> 
> dev_queue_xmit() is basically expected to consume the packet,
> error or not.
> 
> What case of calling dev_queue_xmit() did you discover that did not
> kfree the SKB on error?  We should fix that.  On a quick scan on the
> entire dev_queue_xmit() implmentation, I cannot find such a case.
> 

I think the call path via dev->hard_start_xmit, if it fails, may result
in an skb not being freed.  This appears to be the case with the e100.c
driver.  The qdisc_restart path to dev->hard_start_xmit also appears
susceptible to this.  It appears that not all devices agree as to who
should clean-up an skb on error.

-- 
Michal Ostrowski <mostrows@earthlink.net>


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

* Re: [PATCH] Advertise PPPoE MTU / avoid memory leak.
  2006-09-24 12:29   ` Michal Ostrowski
@ 2006-09-25  1:41     ` David Miller
  2006-09-25 18:16       ` Michal Ostrowski
  0 siblings, 1 reply; 7+ messages in thread
From: David Miller @ 2006-09-25  1:41 UTC (permalink / raw)
  To: mostrows; +Cc: linux-kernel, netdev, ppp-bugs

From: Michal Ostrowski <mostrows@earthlink.net>
Date: Sun, 24 Sep 2006 07:29:25 -0500

> I think the call path via dev->hard_start_xmit, if it fails, may result
> in an skb not being freed.  This appears to be the case with the e100.c
> driver.  The qdisc_restart path to dev->hard_start_xmit also appears
> susceptible to this.  It appears that not all devices agree as to who
> should clean-up an skb on error.

There is a well defined policy about who frees the SKB or has
ownership of it based upon dev->hard_start_xmit() return values.

Any driver deviating from this set of rules should simply be
audited and fixed, as needed.

But, no matter, your change is buggy and we can't apply your
patch (even if it does fix a leak in some legitimate case)
because it introduces an obvious double-free bug.

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

* Re: [PATCH] Advertise PPPoE MTU / avoid memory leak.
  2006-09-25  1:41     ` David Miller
@ 2006-09-25 18:16       ` Michal Ostrowski
  0 siblings, 0 replies; 7+ messages in thread
From: Michal Ostrowski @ 2006-09-25 18:16 UTC (permalink / raw)
  To: David Miller; +Cc: linux-kernel, netdev, ppp-bugs

On Sun, 2006-09-24 at 18:41 -0700, David Miller wrote:
> From: Michal Ostrowski <mostrows@earthlink.net>
> Date: Sun, 24 Sep 2006 07:29:25 -0500
> 
> > I think the call path via dev->hard_start_xmit, if it fails, may result
> > in an skb not being freed.  This appears to be the case with the e100.c
> > driver.  The qdisc_restart path to dev->hard_start_xmit also appears
> > susceptible to this.  It appears that not all devices agree as to who
> > should clean-up an skb on error.
> 
> There is a well defined policy about who frees the SKB or has
> ownership of it based upon dev->hard_start_xmit() return values.
> 
> Any driver deviating from this set of rules should simply be
> audited and fixed, as needed.
> 
> But, no matter, your change is buggy and we can't apply your
> patch (even if it does fix a leak in some legitimate case)
> because it introduces an obvious double-free bug.
> 

Yup.  I'll resubmit a fixed one.


-- 
Michal Ostrowski <mostrows@earthlink.net>


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

* Re: [PATCH] Advertise PPPoE MTU / avoid memory leak.
  2006-09-23 17:30 [PATCH] Advertise PPPoE MTU / avoid memory leak mostrows
  2006-09-23 21:56 ` David Miller
@ 2006-09-26  6:32 ` Pekka Savola
  2006-09-27 13:53   ` Michal Ostrowski
  1 sibling, 1 reply; 7+ messages in thread
From: Pekka Savola @ 2006-09-26  6:32 UTC (permalink / raw)
  To: Michal Ostrowski; +Cc: netdev, ppp-bugs

Speaking of PPPoE and MTU, does Linux support recently-published RFC 
4638:

   Accommodating a Maximum Transit Unit/Maximum Receive Unit (MTU/MRU)
                        Greater Than 1492 in the
              Point-to-Point Protocol over Ethernet (PPPoE)

On Sat, 23 Sep 2006, mostrows@earthlink.net wrote:
> PPPoE must advertise the underlying device's MTU via the ppp channel
> descriptor structure, as multilink functionality depends on it.
>
> __pppoe_xmit must free any skb it allocates if there is an error
> submitting the skb downstream.
>
> Signed-off-by: Michal Ostrowski <mostrows@earthlink.net>
> ---
> drivers/net/pppoe.c |    5 ++++-
> 1 files changed, 4 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/net/pppoe.c b/drivers/net/pppoe.c
> index 475dc93..b4dc516 100644
> --- a/drivers/net/pppoe.c
> +++ b/drivers/net/pppoe.c
> @@ -600,6 +600,7 @@ static int pppoe_connect(struct socket *
> 		po->chan.hdrlen = (sizeof(struct pppoe_hdr) +
> 				   dev->hard_header_len);
>
> +		po->chan.mtu = dev->mtu - sizeof(struct pppoe_hdr);
> 		po->chan.private = sk;
> 		po->chan.ops = &pppoe_chan_ops;
>
> @@ -831,7 +832,7 @@ static int __pppoe_xmit(struct sock *sk,
> 	struct pppoe_hdr *ph;
> 	int headroom = skb_headroom(skb);
> 	int data_len = skb->len;
> -	struct sk_buff *skb2;
> +	struct sk_buff *skb2 = NULL;
>
> 	if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED))
> 		goto abort;
> @@ -887,6 +888,8 @@ static int __pppoe_xmit(struct sock *sk,
> 	return 1;
>
> abort:
> +	if (skb2)
> +		kfree_skb(skb2);
> 	return 0;
> }
>
>

-- 
Pekka Savola                 "You each name yourselves king, yet the
Netcore Oy                    kingdom bleeds."
Systems. Networks. Security. -- George R.R. Martin: A Clash of Kings

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

* Re: [PATCH] Advertise PPPoE MTU / avoid memory leak.
  2006-09-26  6:32 ` Pekka Savola
@ 2006-09-27 13:53   ` Michal Ostrowski
  0 siblings, 0 replies; 7+ messages in thread
From: Michal Ostrowski @ 2006-09-27 13:53 UTC (permalink / raw)
  To: Pekka Savola; +Cc: netdev, ppp-bugs

This is not currently supported.

Looking at the RFC, this is an issue that must be solved in the pppoe
plugin that performs the PPPoE negotiation/discovery.  The kernel code
that runs the regular session traffic should be able to adjust (with
minimal or no changes) as it does not depend on a hardcoded MTU.



-- 
Michal Ostrowski <mostrows@earthlink.net>

On Tue, 2006-09-26 at 09:32 +0300, Pekka Savola wrote:
> Speaking of PPPoE and MTU, does Linux support recently-published RFC 
> 4638:
> 
>    Accommodating a Maximum Transit Unit/Maximum Receive Unit (MTU/MRU)
>                         Greater Than 1492 in the
>               Point-to-Point Protocol over Ethernet (PPPoE)
> 
> On Sat, 23 Sep 2006, mostrows@earthlink.net wrote:
> > PPPoE must advertise the underlying device's MTU via the ppp channel
> > descriptor structure, as multilink functionality depends on it.
> >
> > __pppoe_xmit must free any skb it allocates if there is an error
> > submitting the skb downstream.
> >
> > Signed-off-by: Michal Ostrowski <mostrows@earthlink.net>
> > ---
> > drivers/net/pppoe.c |    5 ++++-
> > 1 files changed, 4 insertions(+), 1 deletions(-)
> >
> > diff --git a/drivers/net/pppoe.c b/drivers/net/pppoe.c
> > index 475dc93..b4dc516 100644
> > --- a/drivers/net/pppoe.c
> > +++ b/drivers/net/pppoe.c
> > @@ -600,6 +600,7 @@ static int pppoe_connect(struct socket *
> > 		po->chan.hdrlen = (sizeof(struct pppoe_hdr) +
> > 				   dev->hard_header_len);
> >
> > +		po->chan.mtu = dev->mtu - sizeof(struct pppoe_hdr);
> > 		po->chan.private = sk;
> > 		po->chan.ops = &pppoe_chan_ops;
> >
> > @@ -831,7 +832,7 @@ static int __pppoe_xmit(struct sock *sk,
> > 	struct pppoe_hdr *ph;
> > 	int headroom = skb_headroom(skb);
> > 	int data_len = skb->len;
> > -	struct sk_buff *skb2;
> > +	struct sk_buff *skb2 = NULL;
> >
> > 	if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED))
> > 		goto abort;
> > @@ -887,6 +888,8 @@ static int __pppoe_xmit(struct sock *sk,
> > 	return 1;
> >
> > abort:
> > +	if (skb2)
> > +		kfree_skb(skb2);
> > 	return 0;
> > }
> >
> >
> 


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

end of thread, other threads:[~2006-09-27 13:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-23 17:30 [PATCH] Advertise PPPoE MTU / avoid memory leak mostrows
2006-09-23 21:56 ` David Miller
2006-09-24 12:29   ` Michal Ostrowski
2006-09-25  1:41     ` David Miller
2006-09-25 18:16       ` Michal Ostrowski
2006-09-26  6:32 ` Pekka Savola
2006-09-27 13:53   ` Michal Ostrowski

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