Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2757349ybl; Mon, 19 Aug 2019 07:08:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqzXOIzprmrkgbkctIRjGhgG2a7zjFHX0VZbvr7ET8Y6fa+GYyiCpelxG2VrOho2hx6Q9gVd X-Received: by 2002:a63:c1c:: with SMTP id b28mr20109974pgl.354.1566223683972; Mon, 19 Aug 2019 07:08:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566223683; cv=none; d=google.com; s=arc-20160816; b=ShcPicC+FjUQItCEq+pEx01QL9Gx0vpCn49Na8TPO/1C4UbpsrWh6iDpVi0uty6+bb gN3MPCNGKssnefZ+sxWKkXMtAYqug5gz254Mlhf3iwMXOJ+nWTQsJNom5OavENzyT21V Y0ZGZpbjGStKDSMgErthxlvHOraNo+7yznZFTP114Of1nlC21g1UhsTb715yT/FlBELo uzJVFL5cWYdgy2x69alKmmTw4Xv18KBhGPeehlEx3zi0mHj9x1SFTs5Ti11kTAKiyUT5 fV25CXIqthZgmM1ut4TCvFCOFdPyhDv8w0u4Hg6ZCYod4ZUaHX/WjpUChP5GBdBwjvPO o9JA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=MqRZppYTRbLh5KhLJ3SwBGItLRn3iwBBy4hz7jq9+rY=; b=fD3c2d50FUlylNrZjkLS7yesjuFTUS6ObGaJtmUXiDnj3MaAUhzRkBpoMOB5A4h265 AOOBqY0k6ECQIiMkahuGbZExqcdKNhIm0/9WLK5iUezePN/U2FMavCR/61W3b/CrxG5Z J+YYO+OMZe7hIvF/ia8SZvkUCvmeN2iT/FSnjIXJQYeeOm5QKe4Cv0e+8kHzFOT8HT1k Vgx+Y32z/AvzJPXRH0S3jZkJKBRKVZWJDrg2m3lDfz6ewkC9xa8/xMGEyrbWPN2+8ff4 kjsCujg+bX8zHI95Vrjm8Bbu/Njqj4i/QHrtApLAFfaO6LLSJpfINYwmfFYD1IyUM1L1 +z8w== 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=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k9si10297054pfk.285.2019.08.19.07.07.43; Mon, 19 Aug 2019 07:08:03 -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=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726736AbfHSOGc (ORCPT + 99 others); Mon, 19 Aug 2019 10:06:32 -0400 Received: from relay.sw.ru ([185.231.240.75]:58664 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726028AbfHSOGc (ORCPT ); Mon, 19 Aug 2019 10:06:32 -0400 Received: from [172.16.25.5] by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hziIi-0001H7-Gd; Mon, 19 Aug 2019 17:06:24 +0300 Subject: Re: [PATCH] arm64: kasan: fix phys_to_virt() false positive on tag-based kasan To: Will Deacon , Mark Rutland Cc: Walter Wu , Alexander Potapenko , Dmitry Vyukov , Catalin Marinas , Will Deacon , Matthias Brugger , Andrew Morton , Andrey Konovalov , wsd_upstream@mediatek.com, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org 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> From: Andrey Ryabinin Message-ID: <8df7ec20-2fd2-8076-9a34-ac4c9785e91a@virtuozzo.com> Date: Mon, 19 Aug 2019 17:06:33 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190819133441.ejomv6cprdcz7hh6@willie-the-truck> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, -- 2.21.0