Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2776741ybl; Mon, 19 Aug 2019 07:23:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqxV05dqlPvItZey5Tqse/4TRiwEVQU26Ecs7ZS5twqI0TiVJiSKj8HBMPeDVjvmGH5EM0mc X-Received: by 2002:a65:48c3:: with SMTP id o3mr5616538pgs.372.1566224593113; Mon, 19 Aug 2019 07:23:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566224593; cv=none; d=google.com; s=arc-20160816; b=XsWl1IBWWPLIuNf/63bUs/o7ubCFZu415cuOsGzCUIDW2BOsouSXxjGO2O69fnKFYL jAZ1Ar6IIEThFItA7Em5saMAlZJAug1oFgX03fdoU2a5Y+m/O0/zY1IBVr+4mO5M3raf 9v4lyiY/APu+IytSMnMWFFPpc9+ZXd+tWs3qSDjPhgwS7jbqfNYH+PulHpU7JpRKsanm a5Ne7Vm5N2I4YmtaDiBI9tHZjM3rfLklcLOKVtRmUWYIHo+9obM8sndtMT1pLZRt4WAh aTSKHYDSA84G+T4DhD1MopTdN+2yCExMCo6CbKWXxnifIznLLZO9wySCG/Ughfyowq3M sQFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :references:in-reply-to:date:cc:to:from:subject:message-id; bh=4cMpTZ16GOk/C43E6VA9WSr5CJh+d5BfID7frTiEBlY=; b=ckA37q2H5zq8pdAFlumdOGIAqwdqYb1BD3m3oUdPfgE5xlklVLNWlzybTnzkqxH0QK FcN4zMVmZfFRM4Nlq25ZG+b9gh6zbx3HmVoZVrMI3R+1N0GV/NOCwF1cjMScftNpFDCv k8UGwwXKrqgexhLccnEq0aHCwHDrLDMk1lcR6MS0jSLjWJd0TqKXSvXmSnjKZm5lbI3d 35HsmrJ++1MkCjQ3JTvY5PF9zmOA3ZD9Y3sZ+akS6gRe0B30yhOYvhKDYVziyzifRbOc zb+9WWpdkcBkcQWIeplL520PvR9UDmZZNNtjD/ClxKltN1mRCVf88bLVaCtCabQV//yx tfQA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bg1si9369203plb.210.2019.08.19.07.22.57; Mon, 19 Aug 2019 07:23:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726627AbfHSOWF (ORCPT + 99 others); Mon, 19 Aug 2019 10:22:05 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:6772 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726028AbfHSOWF (ORCPT ); Mon, 19 Aug 2019 10:22:05 -0400 X-UUID: 8c89e3d18e8d4292afa7d8bd1e6b4842-20190819 X-UUID: 8c89e3d18e8d4292afa7d8bd1e6b4842-20190819 Received: from mtkcas08.mediatek.inc [(172.21.101.126)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0707 with TLS) with ESMTP id 42098201; Mon, 19 Aug 2019 22:21:54 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 19 Aug 2019 22:21:56 +0800 Received: from [172.21.84.99] (172.21.84.99) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Mon, 19 Aug 2019 22:21:56 +0800 Message-ID: <1566224517.9993.6.camel@mtksdccf07> Subject: Re: [PATCH] arm64: kasan: fix phys_to_virt() false positive on tag-based kasan From: Walter Wu To: Andrey Ryabinin CC: Will Deacon , Mark Rutland , Alexander Potapenko , Dmitry Vyukov , Catalin Marinas , "Will Deacon" , Matthias Brugger , Andrew Morton , Andrey Konovalov , , , , , Date: Mon, 19 Aug 2019 22:21:57 +0800 In-Reply-To: <8df7ec20-2fd2-8076-9a34-ac4c9785e91a@virtuozzo.com> References: <20190819114420.2535-1-walter-zh.wu@mediatek.com> <20190819125625.bu3nbrldg7te5kwc@willie-the-truck> <20190819132347.GB9927@lakrids.cambridge.arm.com> <20190819133441.ejomv6cprdcz7hh6@willie-the-truck> <8df7ec20-2fd2-8076-9a34-ac4c9785e91a@virtuozzo.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.2.3-0ubuntu6 Content-Transfer-Encoding: 7bit MIME-Version: 1.0 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2019-08-19 at 17:06 +0300, Andrey Ryabinin wrote: > > On 8/19/19 4:34 PM, Will Deacon wrote: > > On Mon, Aug 19, 2019 at 02:23:48PM +0100, Mark Rutland wrote: > >> On Mon, Aug 19, 2019 at 01:56:26PM +0100, Will Deacon wrote: > >>> On Mon, Aug 19, 2019 at 07:44:20PM +0800, Walter Wu wrote: > >>>> __arm_v7s_unmap() call iopte_deref() to translate pyh_to_virt address, > >>>> but it will modify pointer tag into 0xff, so there is a false positive. > >>>> > >>>> When enable tag-based kasan, phys_to_virt() function need to rewrite > >>>> its original pointer tag in order to avoid kasan report an incorrect > >>>> memory corruption. > >>> > >>> Hmm. Which tree did you see this on? We've recently queued a load of fixes > >>> in this area, but I /thought/ they were only needed after the support for > >>> 52-bit virtual addressing in the kernel. > >> > >> I'm seeing similar issues in the virtio blk code (splat below), atop of > >> the arm64 for-next/core branch. I think this is a latent issue, and > >> people are only just starting to test with KASAN_SW_TAGS. > >> > >> It looks like the virtio blk code will round-trip a SLUB-allocated pointer from > >> virt->page->virt, losing the per-object tag in the process. > >> > >> Our page_to_virt() seems to get a per-page tag, but this only makes > >> sense if you're dealing with the page allocator, rather than something > >> like SLUB which carves a page into smaller objects giving each object a > >> distinct tag. > >> > >> Any round-trip of a pointer from SLUB is going to lose the per-object > >> tag. > > > > Urgh, I wonder how this is supposed to work? > > > > We supposed to ignore pointers with 0xff tags. We do ignore them when memory access checked, > but not in kfree() path. > This untested patch should fix the issue: > > > > --- > mm/kasan/common.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/mm/kasan/common.c b/mm/kasan/common.c > index 895dc5e2b3d5..0a81cc328049 100644 > --- a/mm/kasan/common.c > +++ b/mm/kasan/common.c > @@ -407,7 +407,7 @@ static inline bool shadow_invalid(u8 tag, s8 shadow_byte) > return shadow_byte < 0 || > shadow_byte >= KASAN_SHADOW_SCALE_SIZE; > else > - return tag != (u8)shadow_byte; > + return (tag != KASAN_TAG_KERNEL) && (tag != (u8)shadow_byte); > } > > static bool __kasan_slab_free(struct kmem_cache *cache, void *object, Hi, Andrey, Does it miss the double-free case after ignore pointer tag 0xff ? and please help review my another patch about memory corruption identification. Thanks your respondence Walter