From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DCB5C4338F for ; Fri, 30 Jul 2021 14:57:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3BFA0604D7 for ; Fri, 30 Jul 2021 14:57:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3BFA0604D7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id C05898D0003; Fri, 30 Jul 2021 10:57:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B8D948D0001; Fri, 30 Jul 2021 10:57:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA4288D0003; Fri, 30 Jul 2021 10:57:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0196.hostedemail.com [216.40.44.196]) by kanga.kvack.org (Postfix) with ESMTP id 8C2C08D0001 for ; Fri, 30 Jul 2021 10:57:33 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 1DFE218488BC9 for ; Fri, 30 Jul 2021 14:57:33 +0000 (UTC) X-FDA: 78419557986.13.9D202FA Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) by imf01.hostedemail.com (Postfix) with ESMTP id D832450347D0 for ; Fri, 30 Jul 2021 14:57:32 +0000 (UTC) Received: by mail-ed1-f43.google.com with SMTP id f13so13516318edq.13 for ; Fri, 30 Jul 2021 07:57:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/FskvzB/Uu7kITCTpEs9Kzb0h3ZTsKYWrhXodwFjiIk=; b=qdwGk32T8LIniVGMFzFAJe6RX68qQNMkrxYLkZOSF0T3vabQA/oH99TgvDLAWpUnVw EMBEBrTyyu0bszCCLjMP+rMRob7mlE+AovtCZo27qSMkPTfe3g4yfg3QDpcCqjJ89AuG 5iZit8yuHeSIYaG0jTc9sVQLYXBZw3Oj72RnERwCr0dEmHLBHAXxmyrR6JdjEoMnNvM2 oy8pFEKMaJ0In9p6GeDe3RQvqg0ySFCkiFuMb0Me2Voz97GzdR0EOgdUS19VKNUiQBYH 8vYVD3AOWJfaGfatwjNQbmUH4uofJCPG5u97wjWpuM3UV+70caNlBUULFH5JOjXfwi1q iRbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/FskvzB/Uu7kITCTpEs9Kzb0h3ZTsKYWrhXodwFjiIk=; b=bpT0Ox5IXDl5y+GFSL+wu2E2137r7ioBIY1Iwz5FLXunu9cJ+RHU+seBUE2ql3CGtx FzGlu7vTP6gw7T+ilYOs4UkfQ4JWhvu99OmAAwHrWAxlWY6e61ZroVeDhCP78ckJAPJb QKEEWUePGyNITma5ojmTIWlxCKeXpm0RgUov7nO2kFt5ih9vi6ugow4/JCEcGSltbLzS 8qHBkKTbPogeZll5VJrLDYYdWdRibHAbkpW9ZNOc+L0O1LrDjyQb7f1X9Izo0scpBs9C /kmcGt0Jv/1glEurW8v3rMRExVBa87JNOUuhKNhlZtZKG2YuXDl5mgqFZEoCZAqwKI+8 Xpkg== X-Gm-Message-State: AOAM533ZdnfPerxXSmJAjo/PdBwAMDgnr3HY20GmeykEJShWvHvVD+UT N5S8y5yzM3/Urgks0oZpA1pd9+gUFQaQSjmnuPg= X-Google-Smtp-Source: ABdhPJwSaMVLnatukbBUZ5bbG5wTLiLIbZNXBz6UHbZ62TjHZpcXELPVn/H+RxE5RRcBCR7Zb+SxC2GibF9zBMAwoE0= X-Received: by 2002:a50:eb88:: with SMTP id y8mr3436558edr.70.1627657051382; Fri, 30 Jul 2021 07:57:31 -0700 (PDT) MIME-Version: 1.0 References: <20210727040021.21371-1-Kuan-Ying.Lee@mediatek.com> <20210727040021.21371-2-Kuan-Ying.Lee@mediatek.com> <20210727192217.GV13920@arm.com> In-Reply-To: <20210727192217.GV13920@arm.com> From: Andrey Konovalov Date: Fri, 30 Jul 2021 16:57:20 +0200 Message-ID: Subject: Re: [PATCH 1/2] kasan, mm: reset tag when access metadata To: Catalin Marinas , Kuan-Ying Lee Cc: Marco Elver , Nicholas Tang , Andrew Yang , Andrey Ryabinin , Alexander Potapenko , Chinwen Chang , Andrew Morton , kasan-dev , Linux Memory Management List , LKML , Linux ARM , "moderated list:ARM/Mediatek SoC support" Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: D832450347D0 Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=qdwGk32T; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf01.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.208.43 as permitted sender) smtp.mailfrom=andreyknvl@gmail.com X-Stat-Signature: en3guxpiippgzqp18uowdcqi9ebrnaq1 X-HE-Tag: 1627657052-595162 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Jul 27, 2021 at 9:22 PM Catalin Marinas wrote: > > On Tue, Jul 27, 2021 at 04:32:02PM +0800, Kuan-Ying Lee wrote: > > On Tue, 2021-07-27 at 09:10 +0200, Marco Elver wrote: > > > +Cc Catalin > > > > > > On Tue, 27 Jul 2021 at 06:00, Kuan-Ying Lee < > > > Kuan-Ying.Lee@mediatek.com> wrote: > > > > > > > > Hardware tag-based KASAN doesn't use compiler instrumentation, we > > > > can not use kasan_disable_current() to ignore tag check. > > > > > > > > Thus, we need to reset tags when accessing metadata. > > > > > > > > Signed-off-by: Kuan-Ying Lee > > > > > > This looks reasonable, but the patch title is not saying this is > > > kmemleak, nor does the description say what the problem is. What > > > problem did you encounter? Was it a false positive? > > > > kmemleak would scan kernel memory to check memory leak. > > When it scans on the invalid slab and dereference, the issue > > will occur like below. > > > > So I think we should reset the tag before scanning. > > > > # echo scan > /sys/kernel/debug/kmemleak > > [ 151.905804] > > ================================================================== > > [ 151.907120] BUG: KASAN: out-of-bounds in scan_block+0x58/0x170 > > [ 151.908773] Read at addr f7ff0000c0074eb0 by task kmemleak/138 > > [ 151.909656] Pointer tag: [f7], memory tag: [fe] > > It would be interesting to find out why the tag doesn't match. Kmemleak > should in principle only scan valid objects that have been allocated and > the pointer can be safely dereferenced. 0xfe is KASAN_TAG_INVALID, so it > either goes past the size of the object (into the red zone) or it still > accesses the object after it was marked as freed but before being > released from kmemleak. > > With slab, looking at __cache_free(), it calls kasan_slab_free() before > ___cache_free() -> kmemleak_free_recursive(), so the second scenario is > possible. With slub, however, slab_free_hook() first releases the object > from kmemleak before poisoning it. Based on the stack dump, you are > using slub, so it may be that kmemleak goes into the object red zones. > > I'd like this clarified before blindly resetting the tag. AFAIK, kmemleak scans the whole object including the leftover redzone for kmalloc-allocated objects. Looking at the report, there are 11 0xf7 granules, which amounts to 176 bytes, and the object is allocated from the kmalloc-256 cache. So when kmemleak accesses the last 256-176 bytes, it causes faults, as those are marked with KASAN_KMALLOC_REDZONE == KASAN_TAG_INVALID == 0xfe. Generally, resetting tags in kasan_disable/enable_current() section should be fine to suppress MTE faults, provided those sections had been added correctly in the first place.