lkml.org 
[lkml]   [2018]   [Jul]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] radix-tree: avoid NULL dereference
On Fri, Jul 06, 2018 at 02:41:44PM +0100, Mark Rutland wrote:
> When idr_alloc() is called for the first time on an IDR (which has no
> nodes in its radix tree), we end up with calculate_count() calling
> get_slot_offset() with a NULL node, leading to a NULL pointer
> dereference caught by UBSAN:

Thanks!

> The result of the load is passed into node_tag_get(), which ignores the
> value when node is NULL. Typically, the compiler inlines both
> get_slot_offset() and node_tag_get() into calculate_count(), optimizing
> away the NULL-pointer dereference, and hence this doesn't typically
> result in a boot failure.
>
> We can't rely on the compiler always doing this, and must avoid
> dereferencing fields from node when it is potentially NULL.
>
> To do so, this patch folds the generation of offset into tag_get(), such
> that this only happens when node is not NULL. Callers are updated to
> pass the relevant slot, rather than the offset derived from it.

I did think about this ... honest! My reasoning clearly glitched at some
point. I think this is the right way to fix the problem.

Acked-by: Matthew Wilcox <willy@infradead.org>

\
 
 \ /
  Last update: 2018-07-06 16:26    [W:0.085 / U:0.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site