linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vasiliy Kulikov <segoon@openwall.com>
To: Christoph Lameter <cl@linux.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	kernel-hardening@lists.openwall.com,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	x86@kernel.org, Arnd Bergmann <arnd@arndb.de>,
	Pekka Enberg <penberg@kernel.org>, Matt Mackall <mpm@selenic.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org,
	linux-mm@kvack.org
Subject: Re: [RFC v2] implement SL*B and stack usercopy runtime checks
Date: Tue, 19 Jul 2011 10:53:22 +0400	[thread overview]
Message-ID: <20110719065322.GA3228@albatros> (raw)
In-Reply-To: <alpine.DEB.2.00.1107181610350.31576@router.home>

On Mon, Jul 18, 2011 at 16:18 -0500, Christoph Lameter wrote:
> On Mon, 18 Jul 2011, Vasiliy Kulikov wrote:
> 
> > --- a/mm/slab.c
> > +++ b/mm/slab.c
> > @@ -3844,6 +3844,40 @@ unsigned int kmem_cache_size(struct kmem_cache *cachep)
> >  EXPORT_SYMBOL(kmem_cache_size);
> >
> >  /*
> > + * Returns false if and only if [ptr; ptr+len) touches the slab,
> > + * but breaks objects boundaries.  It doesn't check whether the
> > + * accessed object is actually allocated.
> > + */
> > +bool slab_access_ok(const void *ptr, unsigned long len)
> > +{
> > +	struct page *page;
> > +	struct kmem_cache *cachep = NULL;
> 
> Why = NULL?

Indeed, redundant.

> > +	struct slab *slabp;
> > +	unsigned int objnr;
> > +	unsigned long offset;
> > +
> > +	if (!len)
> > +		return true;
> > +	if (!virt_addr_valid(ptr))
> > +		return true;
> > +	page = virt_to_head_page(ptr);
> > +	if (!PageSlab(page))
> > +		return true;
> > +
> > +	cachep = page_get_cache(page);
> > +	slabp = page_get_slab(page);
> > +	objnr = obj_to_index(cachep, slabp, (void *)ptr);
> > +	BUG_ON(objnr >= cachep->num);
> > +	offset = (const char *)ptr - obj_offset(cachep) -
> > +	    (const char *)index_to_obj(cachep, slabp, objnr);
> > +	if (offset <= obj_size(cachep) && len <= obj_size(cachep) - offset)
> > +		return true;
> > +
> > +	return false;
> > +}
> > +EXPORT_SYMBOL(slab_access_ok);
> > +
> > +/*
> >   * This initializes kmem_list3 or resizes various caches for all nodes.
> >   */
> >  static int alloc_kmemlist(struct kmem_cache *cachep, gfp_t gfp)
> 
> > --- a/mm/slub.c
> > +++ b/mm/slub.c
> > @@ -2623,6 +2623,34 @@ unsigned int kmem_cache_size(struct kmem_cache *s)
> >  }
> >  EXPORT_SYMBOL(kmem_cache_size);
> >
> > +/*
> > + * Returns false if and only if [ptr; ptr+len) touches the slab,
> > + * but breaks objects boundaries.  It doesn't check whether the
> > + * accessed object is actually allocated.
> > + */
> > +bool slab_access_ok(const void *ptr, unsigned long len)
> > +{
> > +	struct page *page;
> > +	struct kmem_cache *s = NULL;
> 
> No need to assign NULL.

Ditto.

> > +	unsigned long offset;
> > +
> > +	if (len == 0)
> > +		return true;
> > +	if (!virt_addr_valid(ptr))
> > +		return true;
> > +	page = virt_to_head_page(ptr);
> > +	if (!PageSlab(page))
> > +		return true;
> > +
> > +	s = page->slab;
> > +	offset = ((const char *)ptr - (const char *)page_address(page)) % s->size;
> 
> Are the casts necessary? Both are pointers to void *

Is it normal kernel style to use void* pointer arithmetic?

> > +	if (offset <= s->objsize && len <= s->objsize - offset)
> 
> If offset == s->objsize then we access the first byte after the object.

Well, then objsize - offset == 0 and len can be 0 only to pass the right
part of && check.  But (len == 0) case is already handled above.

But yes, for better readability it should be "<".


Thank you,

-- 
Vasiliy Kulikov
http://www.openwall.com - bringing security into open computing environments

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

      reply	other threads:[~2011-07-19  6:53 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-03 11:10 [RFC v1] implement SL*B and stack usercopy runtime checks Vasiliy Kulikov
2011-07-03 18:27 ` Linus Torvalds
2011-07-03 18:57   ` Vasiliy Kulikov
2011-07-03 19:10     ` Linus Torvalds
2011-07-03 19:24       ` [kernel-hardening] " Vasiliy Kulikov
2011-07-03 19:37         ` Joe Perches
2011-07-03 19:53           ` Vasiliy Kulikov
2011-07-06  3:39   ` Jonathan Hawthorne
2011-07-18 18:39   ` [RFC v2] " Vasiliy Kulikov
2011-07-18 18:52     ` Andrew Morton
2011-07-18 19:33       ` [kernel-hardening] " Vasiliy Kulikov
2011-07-19  7:40       ` Vasiliy Kulikov
2011-07-18 19:08     ` Matt Mackall
2011-07-18 19:24       ` Vasiliy Kulikov
2011-07-18 21:18     ` Christoph Lameter
2011-07-19  6:53       ` Vasiliy Kulikov [this message]

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=20110719065322.GA3228@albatros \
    --to=segoon@openwall.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=cl@linux.com \
    --cc=hpa@zytor.com \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mingo@redhat.com \
    --cc=mpm@selenic.com \
    --cc=penberg@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=x86@kernel.org \
    /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 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).