Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4640043pxv; Tue, 27 Jul 2021 12:23:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0A2o9U0JHnxGDUoIX4tECyYfbCmsD/lduHL4CLfQFaIUhV6QgYb1jeP2Rnci0AApCU2Xo X-Received: by 2002:a02:4b04:: with SMTP id q4mr23075358jaa.89.1627413807463; Tue, 27 Jul 2021 12:23:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627413807; cv=none; d=google.com; s=arc-20160816; b=ai0tL+iOVRv0U/5NtLn21TL+aYUK9BmcJh6gCXjoYfR4k8RS1pB8bmhCLhF1ww78+v 4egoShXuEQZpd+q7Owshna1DCY1rIWU39UneerDZ+CuXOUjm9n/rtG+i3k2l2s5L+IWs NiSpsgomGXDO1R/GjB5IPY6DQKvPCGOiuY9S0/MFFnq3EYQxeDVqLEgVUIueKUyFZtdh 3En7uA0VusfwvyHh4EGoo501UZbmMuhOykmWktK59QzXt+8gNkyV/pZfgQifQfc9XLK7 VjmoxW7qVDpI9Sy2osiRyQHFZx84efuag9EH7L2p+fO/FGRAdvULa2KNbTXmQamYM8zV 2R1Q== 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=Qfr/Ueg7NHSh4CuTTl26GluZ/zS5hmB53ASIMGCTviE=; b=ctK1T0skpZyFVcTdEz3QENYJkWVlDdYCIQggI3EXREG54ihcBMvKsJurHJ4budOy4O eVmUFF8fBym0i2gqJGMJximckq+AdwMI+UbpSWIMytlIa6J6LOp0GwR5ubyB4JsrW2YK TiFvb0mZPXW3fU19576feaGlkRvNOV5rO7M/wmv3jFRRyEi4d8FQAr8G+hljCHsoye4Q tVSRAtBQ8astNws4mnunoly3gjsMcjjt5QUqVQA0Yi9zktrs4QrxRngmePhP86rR4QOJ PlSKUePLoUpKk5rijWc4qcmk5GpoZUiTdEMGC7e5X5+OaPlxe+MiTm4CitOb+aNYFFrG ssjQ== 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 d187si4539634iog.56.2021.07.27.12.23.16; Tue, 27 Jul 2021 12:23:27 -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 S230329AbhG0TWY (ORCPT + 99 others); Tue, 27 Jul 2021 15:22:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:57882 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229737AbhG0TWY (ORCPT ); Tue, 27 Jul 2021 15:22:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9A76E60F6E; Tue, 27 Jul 2021 19:22:21 +0000 (UTC) Date: Tue, 27 Jul 2021 20:22:18 +0100 From: Catalin Marinas To: Kuan-Ying Lee Cc: Marco Elver , Nicholas Tang , Andrew Yang , Andrey Konovalov , Andrey Ryabinin , Alexander Potapenko , Chinwen Chang , Andrew Morton , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: Re: [PATCH 1/2] kasan, mm: reset tag when access metadata Message-ID: <20210727192217.GV13920@arm.com> References: <20210727040021.21371-1-Kuan-Ying.Lee@mediatek.com> <20210727040021.21371-2-Kuan-Ying.Lee@mediatek.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 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. -- Catalin