Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2756617ybl; Mon, 19 Aug 2019 07:07:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqxQNalDBKjgFNPZu45FAnJbSZoTmhBRop1oBUmG+gArzHA5PPSPPv8IRpxv52PMRdij1Sk4 X-Received: by 2002:a17:902:9689:: with SMTP id n9mr23072946plp.241.1566223650604; Mon, 19 Aug 2019 07:07:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566223650; cv=none; d=google.com; s=arc-20160816; b=MHdGxn0TuKcWt2ZhrpPnGnOm+Eo1P9T+x90ie6VjLXb62y9mQPu75zXAWCjpuxysJX Mp8FuhdQTBdy/6AyPElG5zC/YFiflryTzBRT5No1POp1rSLrVg7Xi5E9huPBWkORZmEr 4LCxB5uKqwmsDntNUhhWjV1SOXm2zJYIpmdUg2zOm47v9pM5No/N0J59sco2DnYnbMbd 4xnvEX+39PpyE0JEZvGB9hkBFJzJq1Zr0g7MnnYg4VubSbZxXwf+49SXTggkfTxMYMqk Nrv37FVUFOtMAZtM9lvPl3pY06uK9JpuT8lBY35wgvFT9Wnx6UwxjhmcCI8AaUUnqs+h uS/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=T3UxKUOZ72VWnnQkB3XywWd1zjsE0svXI0cagmUyoZs=; b=mWm/grcb7aCv5i8FHjulM2xpARMISteEyaM86vTHqpqkh25reYYLmZBToPpd1lJYwM 07x5cxxJhdyyky5OiP36fvBtwTS46EBgxpPW9NuwJzc1fYWzs2hNaBwN0N6YcVm/ns8m FMFCpiqTczehb0FeQJXG2kFS3sgt95/uusbIHcbeDg//WEqHRaem888S1G2ytXq1Wtf+ Rf/MjZhxC9HCUbnKkThxk+Z/5j9zNF/k7qn/YsybFDzEJiBiTAoSWOQyu0+dcxztNz72 f3Cuef8PYfooFAlNwiI43PkvXqBlSvkaIatXR3ylbid1ZBhELImRLqsvYjP5hqma8dU6 +VQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=NdMgf9Mv; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l6si9935529pgg.489.2019.08.19.07.07.11; Mon, 19 Aug 2019 07:07:30 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=NdMgf9Mv; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727843AbfHSOFk (ORCPT + 99 others); Mon, 19 Aug 2019 10:05:40 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:39966 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727770AbfHSOFe (ORCPT ); Mon, 19 Aug 2019 10:05:34 -0400 Received: by mail-pf1-f193.google.com with SMTP id w16so1232868pfn.7 for ; Mon, 19 Aug 2019 07:05:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=T3UxKUOZ72VWnnQkB3XywWd1zjsE0svXI0cagmUyoZs=; b=NdMgf9Mvh/iqzzLFR9x9Aa7SMVofRb6bFd1a7mU0I+5Bl878oLfmmuWz7zgmMymQNH HE/V62KfSHt3cADSjza/dXKtyTsdQxsi6srm1SR2FzQSZoYkC6ZN53f1M56K+kwHqjK/ nUtCHhui1nDMmHS3a3EzZmX7bm4JrpGwgIqsEcpc72o2sCuTgWgbqXvdOovloYYnQs6W yugyH0T81fx5aBwnJlHeJU81YjjhdnWMjuW/vSEoyuoU6gTHGLjs7Z+F8LU/annLcJxw Pr2ktzgLX9TGWDFEzOd1iVKz33xu+TF+JT74tnb2H24/SySDOdXcTbeNNBqJsTl15iq4 UzuQ== 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=T3UxKUOZ72VWnnQkB3XywWd1zjsE0svXI0cagmUyoZs=; b=RKscTNI9p37i6E6CtvhuF/uHRAVYPXp2rox5ZKLFztz/Y/W/JpUzKdjFspMThuJ7nc un+9h+Lvaioga5uXSDDArLRtCcC7R++80E3U+OYXCeGTUY4R8Gajf8j/q71mInXt/yli yGObeuTHKnNZ9pPgy6O3mStuPaBvjwePPofgGvDK3GJcKzotjXNh3w4YUJQtHaOV12OG m6lYrPp0dQ6aLWhgP0o2/FRMDKwFqByZCIv825Tnioe4Je1OQw6ln8eDxP15wUhEOgsW 2uxFB0PJMxZcK8vIvX+pzMmInaNmZHzVZMjfsWEJAzVh8hBmbhUXAtP+Kry8ceh7tUbp L+Nw== X-Gm-Message-State: APjAAAUTKWQporKIC9JN+3wjlOc6wSOMk3fqIbjxSxgZitu8dd8P/6M9 sJfCMEcNFJF4sb8fkXI0kwlhS+lN0rLTB7+28UrmQA== X-Received: by 2002:a17:90a:c20f:: with SMTP id e15mr20524366pjt.123.1566223533317; Mon, 19 Aug 2019 07:05:33 -0700 (PDT) MIME-Version: 1.0 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> In-Reply-To: <20190819133441.ejomv6cprdcz7hh6@willie-the-truck> From: Andrey Konovalov Date: Mon, 19 Aug 2019 16:05:22 +0200 Message-ID: Subject: Re: [PATCH] arm64: kasan: fix phys_to_virt() false positive on tag-based kasan To: Will Deacon Cc: Mark Rutland , Walter Wu , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Catalin Marinas , Will Deacon , Matthias Brugger , Andrew Morton , wsd_upstream@mediatek.com, LKML , kasan-dev , linux-mediatek@lists.infradead.org, Linux ARM Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 19, 2019 at 3: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? > > If we end up having to check the KASAN shadow for *_to_virt(), then why > do we need to store anything in the page flags at all? Andrey? As per 2813b9c0 ("kasan, mm, arm64: tag non slab memory allocated via pagealloc") we should only save a non-0xff tag in page flags for non slab pages. Could you share your .config so I can reproduce this?