• Jann Horn's avatar
    slub: Introduce CONFIG_SLUB_RCU_DEBUG · b8c8ba73
    Jann Horn authored
    Currently, KASAN is unable to catch use-after-free in SLAB_TYPESAFE_BY_RCU
    slabs because use-after-free is allowed within the RCU grace period by
    design.
    
    Add a SLUB debugging feature which RCU-delays every individual
    kmem_cache_free() before either actually freeing the object or handing it
    off to KASAN, and change KASAN to poison freed objects as normal when this
    option is enabled.
    
    For now I've configured Kconfig.debug to default-enable this feature in the
    KASAN GENERIC and SW_TAGS modes; I'm not enabling it by default in HW_TAGS
    mode because I'm not sure if it might have unwanted performance degradation
    effects there.
    
    Note that this is mostly useful with KASAN in the quarantine-based GENERIC
    mode; SLAB_TYPESAFE_BY_RCU slabs are basically always also slabs with a
    ->ctor, and KASAN's assign_tag() currently has to assign fixed tags for
    those, reducing the effectiveness of SW_TAGS/HW_TAGS mode.
    (A possible future extension of this work would be to also let SLUB call
    the ->ctor() on every allocation instead of only when the slab page is
    allocated; then tag-based modes would be able to assign new tags on every
    reallocation.)
    
    Tested-by: syzbot+263726e59eab6b442723@syzkaller.appspotmail.com
    Reviewed-by: default avatarAndrey Konovalov <andreyknvl@gmail.com>
    Acked-by: default avatarMarco Elver <elver@google.com>
    Acked-by: Vlastimil Babka <vbabka@suse.cz> #slab
    Signed-off-by: default avatarJann Horn <jannh@google.com>
    Signed-off-by: default avatarVlastimil Babka <vbabka@suse.cz>
    b8c8ba73
common.c 14.7 KB