All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: johnpol@2ka.mipt.ru
Cc: paul.moore@hp.com, kaber@trash.net, netdev@vger.kernel.org,
	acme@ghostprotocols.net
Subject: Re: [NET]: Fix kfree(skb)
Date: Tue, 27 Feb 2007 10:24:52 -0800 (PST)	[thread overview]
Message-ID: <20070227.102452.102574618.davem@davemloft.net> (raw)
In-Reply-To: <20070227182001.GA4278@2ka.mipt.ru>

From: Evgeniy Polyakov <johnpol@2ka.mipt.ru>
Date: Tue, 27 Feb 2007 21:20:01 +0300

> On Tue, Feb 27, 2007 at 09:14:25PM +0300, Evgeniy Polyakov (johnpol@2ka.mipt.ru) wrote:
> > On Tue, Feb 27, 2007 at 10:00:52AM -0800, David Miller (davem@davemloft.net) wrote:
> > > It's unfortunately an easy mistake to make since kfree() accepts any
> > > pointer type without warning.
> > > 
> > > What would be really nice is if someone could come up with a way for
> > > kfree() to disallow being passed objects that are meant to be released
> > > via some other mechanism.  So that, for example:
> > > 
> > > 	kfree(skb);
> > > 
> > > would warn or fail to compile, but the kfree_skb() code could go:
> > > 
> > > 	kmem_cache_free_I_KNOW_WHAT_I_AM_DOING(skbuff_head_cache, skb);
> > > 
> > > :-)
> > 
> > Something like that? (not tested, will do if starting point looks
> > correct - it checks if requested to be freed size is equal to one of the 
> > kmalloc() size, and warns if kmalloc cache is not that one where 
> > we are going to free an object):
> > 
> > diff --git a/mm/slab.c b/mm/slab.c
> > index c610062..bcb29df 100644
> > --- a/mm/slab.c
> > +++ b/mm/slab.c
> > @@ -3757,6 +3757,15 @@ void kfree(const void *objp)
> >  	local_irq_save(flags);
> >  	kfree_debugcheck(objp);
> >  	c = virt_to_cache(objp);
> > +
> > +	{
> > +		int size = kmem_cache_size(c);
> > +		struct cache_sizes *csizep = malloc_sizes;
> > +		while (size != csizep->cs_size)
> 
> that needs a check for csizep != NULL too obviously.
> Proof of concept, what do you expect? :)

It's a great run-time check, for sure, and definitely something
that we should add when SLAB_DEBUG is enabled.

A compile-time check would be "really neat" :-)

  reply	other threads:[~2007-02-27 18:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-27 17:06 [NET]: Fix kfree(skb) Patrick McHardy
2007-02-27 17:35 ` Paul Moore
2007-02-27 18:00   ` David Miller
2007-02-27 18:14     ` Evgeniy Polyakov
2007-02-27 18:20       ` Evgeniy Polyakov
2007-02-27 18:24         ` David Miller [this message]
2007-02-27 22:24           ` Arnaldo Carvalho de Melo
2007-02-28  9:02           ` Run-time kfree check for correct cache [was Re: [NET]: Fix kfree(skb)] Evgeniy Polyakov
2007-02-28 10:10             ` Eric Dumazet
2007-02-28 14:16               ` Run-time kfree check for correct cache [plus x86_64 APIC troubles] Evgeniy Polyakov
2007-03-01 16:17                 ` Additional run-tme check [Run-time kfree check for correct cache] Evgeniy Polyakov
2007-02-27 18:01 ` [NET]: Fix kfree(skb) David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070227.102452.102574618.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=acme@ghostprotocols.net \
    --cc=johnpol@2ka.mipt.ru \
    --cc=kaber@trash.net \
    --cc=netdev@vger.kernel.org \
    --cc=paul.moore@hp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.