Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp133600pxb; Fri, 15 Jan 2021 09:11:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJyAGci4TvtJJyC0tsqsz/3LdDUZ4WYz+JvuhVen+TOxB/AUq3qFlahQNaOlXxsMvCejCMzg X-Received: by 2002:a17:906:bce3:: with SMTP id op3mr5611503ejb.485.1610730673985; Fri, 15 Jan 2021 09:11:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610730673; cv=none; d=google.com; s=arc-20160816; b=z6RRoReVsaxPWK1XBdUk+5TKGhQTL9GNdZWVrXqhn8oykZAJ/UIE2Jtu4LlUhf3y0S FPpBO+sqGch0J508PBBXOY449cGmpcXE4dg+qK6/2o9cyE5Dxkp268Ime9dG3XVRmSkO 9Pzev9cFbhVPw5/I68SkbjpnSlnQ++5MQyQXwIWaUEKFYg9Ev6VW9PKduevX+v/BXw4S 4VknFGqV8Rmg/M84STI7BnUFcO5qeY1/ekL41ArOcbt4mFiBlUns/SnQU3gCLDOx+hyZ 6jAdqmftW+7knNWRn7GoHT0Ag8eKx4yeMY0CZvKioN9Zis3eNZGrYz266ocrbAfH+axk fVqA== 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=hvPX2SImHvJ1W0hULLoXCX4XjHtKmdt+nT/p2qXObik=; b=Cu6xwUtLoSj4twXXnUczUFidYH4FbqxQB5SCYZ5U4CnWkZpGKAmhtepl4gEPJokL6y jC6bHNrpmIrh+K5yzVoenwpYv4gfMhB+t6dUxAzs6gfibyC5nkLleGSMJTLosIAxej61 RwU2aNpl59H5HTlUznsBsMufBISVKHfFoPv+aTWmNv4tppyJTIG6hamyfTECfbbLYkEh WIp2x5rsKmPtotAgCon6KytGgSeBGbHp2TG21pKoGl4M5XqISWEJByy+eYgSsIIxelVf dqFQEx9y0DLQW69RGO7uRZBDtGrTRuj6jOZe4fUxcLntMiVsfSJp9IqCxMONjLsa3Xl7 Pclw== 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 z23si4765837edr.334.2021.01.15.09.10.49; Fri, 15 Jan 2021 09:11:13 -0800 (PST) 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 S1729353AbhAORGm (ORCPT + 99 others); Fri, 15 Jan 2021 12:06:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:46096 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726136AbhAORGm (ORCPT ); Fri, 15 Jan 2021 12:06:42 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2CB0E222B3; Fri, 15 Jan 2021 17:05:59 +0000 (UTC) Date: Fri, 15 Jan 2021 17:05:56 +0000 From: Catalin Marinas To: Andrey Konovalov Cc: Vincenzo Frascino , Dmitry Vyukov , Alexander Potapenko , Marco Elver , Andrew Morton , Will Deacon , Andrey Ryabinin , Peter Collingbourne , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , kasan-dev , Linux ARM , Linux Memory Management List , LKML Subject: Re: [PATCH 2/2] kasan, arm64: fix pointer tags in KASAN reports Message-ID: <20210115170556.GG16707@gaia> References: <1965508bcbec62699715d32bef91628ef55b4b44.1610553774.git.andreyknvl@google.com> <20210113165441.GC27045@gaia> <20210115165558.GF16707@gaia> 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, Jan 15, 2021 at 06:00:36PM +0100, Andrey Konovalov wrote: > On Fri, Jan 15, 2021 at 5:56 PM Catalin Marinas wrote: > > > > On Fri, Jan 15, 2021 at 05:30:40PM +0100, Andrey Konovalov wrote: > > > On Wed, Jan 13, 2021 at 5:54 PM Catalin Marinas wrote: > > > > On Wed, Jan 13, 2021 at 05:03:30PM +0100, Andrey Konovalov wrote: > > > > > As of the "arm64: expose FAR_EL1 tag bits in siginfo" patch, the address > > > > > that is passed to report_tag_fault has pointer tags in the format of 0x0X, > > > > > while KASAN uses 0xFX format (note the difference in the top 4 bits). > > > > > > > > > > Fix up the pointer tag before calling kasan_report. > > > > > > > > > > Link: https://linux-review.googlesource.com/id/I9ced973866036d8679e8f4ae325de547eb969649 > > > > > Fixes: dceec3ff7807 ("arm64: expose FAR_EL1 tag bits in siginfo") > > > > > Fixes: 4291e9ee6189 ("kasan, arm64: print report from tag fault handler") > > > > > Signed-off-by: Andrey Konovalov > > > > > --- > > > > > arch/arm64/mm/fault.c | 2 ++ > > > > > 1 file changed, 2 insertions(+) > > > > > > > > > > diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c > > > > > index 3c40da479899..a218f6f2fdc8 100644 > > > > > --- a/arch/arm64/mm/fault.c > > > > > +++ b/arch/arm64/mm/fault.c > > > > > @@ -304,6 +304,8 @@ static void report_tag_fault(unsigned long addr, unsigned int esr, > > > > > { > > > > > bool is_write = ((esr & ESR_ELx_WNR) >> ESR_ELx_WNR_SHIFT) != 0; > > > > > > > > > > + /* The format of KASAN tags is 0xF. */ > > > > > + addr |= (0xF0UL << MTE_TAG_SHIFT); > > > > > > > > Ah, I see, that top 4 bits are zeroed by do_tag_check_fault(). When this > > > > was added, the only tag faults were generated for user addresses. > > > > > > > > Anyway, I'd rather fix it in there based on bit 55, something like (only > > > > compile-tested): > > > > > > > > diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c > > > > index 3c40da479899..2b71079d2d32 100644 > > > > --- a/arch/arm64/mm/fault.c > > > > +++ b/arch/arm64/mm/fault.c > > > > @@ -709,10 +709,11 @@ static int do_tag_check_fault(unsigned long far, unsigned int esr, > > > > struct pt_regs *regs) > > > > { > > > > /* > > > > - * The architecture specifies that bits 63:60 of FAR_EL1 are UNKNOWN for tag > > > > - * check faults. Mask them out now so that userspace doesn't see them. > > > > + * The architecture specifies that bits 63:60 of FAR_EL1 are UNKNOWN > > > > + * for tag check faults. Set them to the corresponding bits in the > > > > + * untagged address. > > > > */ > > > > - far &= (1UL << 60) - 1; > > > > + far = (untagged_addr(far) & ~MTE_TAG_MASK) | (far & MTE_TAG_MASK) ; > > > > do_bad_area(far, esr, regs); > > > > return 0; > > > > } > > > > > > BTW, we can do "untagged_addr(far) | (far & MTE_TAG_MASK)" here, as > > > untagged_addr() doesn't change kernel pointers. > > > > untagged_addr() does change tagged kernel pointers, it sign-extends from > > bit 55. So the top byte becomes 0xff and you can no longer or the tag > > bits in. > > That's __untagged_addr(), untagged_addr() keeps the bits for kernel > pointers as of 597399d0cb91. Ah, you are right. In this case I think we should use __untagged_addr() above. Even if the tag check fault happened on a kernel address, bits 63:60 are still unknown. -- Catalin