From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7BD0C433E0 for ; Fri, 15 Jan 2021 17:07:46 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 79E7A222B3 for ; Fri, 15 Jan 2021 17:07:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 79E7A222B3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=SmH5tFLMBH2QwqQged+dqT0Ce3a8WQzJgk3lEzGAAko=; b=pJ4dH6o7jmhlefX3tVWmByytR Zi0cDxbd2nUQ6EhhoxcLK+LcxJc6sJ6GuLne7rYcGjItrwxAuMCFPOz1P0Q6X6MbvlkBDWM9j0JkM J1kMICzJBqO6YITJYpqsnnbNlzXR2pwT1xrE3XktBMq6Xg6ZoPodBJoOw9quvon4jmFfCIVT3Zjct 4VfghLfDSf9z5gMyuai3R7Ks+9bzAqXYgD8HdZscm/y/krWfqT9mnnO3g7+qOedo3uShgmFcYr5Q4 S34Lyv5a9drw3xScFLDiHnLTr2D+GaS2YCyDy+eUy7h7Ab8KBki2gZl6gW61afSmeKpXoZER+XJcf RiBnKDd4g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l0SY2-00080P-8c; Fri, 15 Jan 2021 17:06:06 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l0SXy-0007zO-Cd for linux-arm-kernel@lists.infradead.org; Fri, 15 Jan 2021 17:06:03 +0000 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 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-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210115_120602_600200_D414CA09 X-CRM114-Status: GOOD ( 28.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Linux ARM , Marco Elver , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev , LKML , Linux Memory Management List , Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Peter Collingbourne , Dmitry Vyukov Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel