Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
  • L linux-dm
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • linux-arm
  • linux-dm
  • Repository
Switch branch/tag
  • linux-dm
  • mm
  • kasan
  • common.c
Find file BlameHistoryPermalink
  • Andrey Ryabinin's avatar
    mm/kasan: fix false positive invalid-free reports with CONFIG_KASAN_SW_TAGS=y · 00fb24a4
    Andrey Ryabinin authored Aug 24, 2019
    The code like this:
    
    	ptr = kmalloc(size, GFP_KERNEL);
    	page = virt_to_page(ptr);
    	offset = offset_in_page(ptr);
    	kfree(page_address(page) + offset);
    
    may produce false-positive invalid-free reports on the kernel with
    CONFIG_KASAN_SW_TAGS=y.
    
    In the example above we lose the original tag assigned to 'ptr', so
    kfree() gets the pointer with 0xFF tag.  In kfree() we check that 0xFF
    tag is different from the tag in shadow hence print false report.
    
    Instead of just comparing tags, do the following:
    
    1) Check that shadow doesn't contain KASAN_TAG_INVALID.  Otherwise it's
       double-free and it doesn't matter what tag the pointer have.
    
    2) If pointer tag is different from 0xFF, make sure that tag in the
       shadow is the same as in the pointer.
    
    Link: http://lkml.kernel.org/r/20190819172540.19581-1-aryabinin@virtuozzo.com
    Fixes: 7f94ffbc
    
     ("kasan: add hooks implementation for tag-based mode")
    Signed-off-by: default avatarAndrey Ryabinin <aryabinin@virtuozzo.com>
    Reported-by: default avatarWalter Wu <walter-zh.wu@mediatek.com>
    Reported-by: Mark Rutland's avatarMark Rutland <mark.rutland@arm.com>
    Reviewed-by: default avatarAndrey Konovalov <andreyknvl@google.com>
    Cc: Alexander Potapenko <glider@google.com>
    Cc: Dmitry Vyukov <dvyukov@google.com>
    Cc: Catalin Marinas <catalin.marinas@arm.com>
    Cc: Will Deacon <will.deacon@arm.com>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    00fb24a4