Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp7031870pxv; Fri, 30 Jul 2021 08:25:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwF827ADvl9vKDJsD5/Dx8f85AtRsLKZSbKAdSKMB1a7nBfKQalgul+OZEriZO7eqLW9hVw X-Received: by 2002:a05:6e02:96a:: with SMTP id q10mr1155170ilt.235.1627658742002; Fri, 30 Jul 2021 08:25:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627658741; cv=none; d=google.com; s=arc-20160816; b=AXDz+t4OCTm0cME0AirO//D0NzDqsqKKJgubRGKfLfi00VbCwKGGppMkCE6N1Y+NtT BRacYCmhADRWiLMlEBF0qd7azUrKLX4kqsrDjZNsMMCMsX/V+vqgIEf0H1gp+kcrQIrh Vfowf3/Sszp7Ia36bpa8sHs/tH/B/gv3Y/ujwc+XEgZ7SWHSzsNVMjkaq8K3sN+2s4zZ KQeGfscgrz03v0LX+H4RTDqxzbgq4ccBILOPnN0D8zFJmVprHlOqOgABzbvhiyothQNr IgzaZ41D1MEXj7va3gxuAsF+hMpBqPhW8gkYfyIus1wOWZsgZDaaZiglvUrWm9M3vSkO S++A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=13avQRiQubdP72K/fSFTr5Bfht9EwiRMW9GGBl3Hg/Q=; b=OMkvxIRGEt70JZK1kBAhpAEuiUPBwvCGHr3XoX6MqKepqfVD1m1hif5DuON1Sz84vy /ck60wItQseXzBrZKxdEp+miQFBPHVATV2LdJy1Yki9MaLBxjjq0tBVX7zyaZ4buSgK4 KrRtI6pWplgKdiFx2k6XQHegaM62FFCInT/EG3o4ZTgXqEirvplJDV9etx1p+2l2OWE5 ScU4JoMCoC7xt7cNpEh9hqD9OqUC9N4lFx0hfClChrHf71a0zBlZ2bNGExl72p5OwOAk YV7jfZjakkmXxc4zLOmSIVPsinl63V0MwauXpwp72G3ZdKc3Ux91dDy8zjNVl4XsQns6 2WGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o8si1860894jap.10.2021.07.30.08.25.30; Fri, 30 Jul 2021 08:25:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239440AbhG3PYt (ORCPT + 99 others); Fri, 30 Jul 2021 11:24:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:60600 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239398AbhG3PYs (ORCPT ); Fri, 30 Jul 2021 11:24:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F2A2260F46; Fri, 30 Jul 2021 15:24:41 +0000 (UTC) Date: Fri, 30 Jul 2021 16:24:39 +0100 From: Catalin Marinas To: Andrey Konovalov Cc: Kuan-Ying Lee , 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" Subject: Re: [PATCH 1/2] kasan, mm: reset tag when access metadata Message-ID: <20210730152438.GA2690@arm.com> References: <20210727040021.21371-1-Kuan-Ying.Lee@mediatek.com> <20210727040021.21371-2-Kuan-Ying.Lee@mediatek.com> <20210727192217.GV13920@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 30, 2021 at 04:57:20PM +0200, Andrey Konovalov wrote: > 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. Thanks for the explanation, the patch makes sense. FWIW: Acked-by: Catalin Marinas