Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp36075pxb; Fri, 15 Jan 2021 05:16:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJwxIGmLGt6z60alaLymhROHllj3JEvuExIWyk8xHiUwB9hJuOrTEaj2o8Tq0LsHhUIKFpYK X-Received: by 2002:a17:906:495b:: with SMTP id f27mr8947043ejt.338.1610716573635; Fri, 15 Jan 2021 05:16:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610716573; cv=none; d=google.com; s=arc-20160816; b=jlVGzsOORNkk+VwcEzpNGaI0l6NMHJUwJ8hJZkt0wEBsMCTQOHnaWNegIR995XV+MD 6J1QqtG8Vd97s5BM65GMlRmiWlprxBcSYhE9IFpsqT82rWNkN4JNBK7Srfn2UEMEgyO4 os7PoWxnKTpiicJir+W567fBP4o8UVvBfV5bRA/LFdxvzsW9W4Slkv5pLkTViBEPpSEe glRcPV1SLVuuwSLaDXLURzK/1rBC6oZ946L5yggo3IlaMLyNOrzHGLf3DpyJhGEWcrmy 7I6MiJtf578E5zj0w0TKhn515/17Ze49gVJ0ShoR2RLIZOzr+unus+PFs0p4tJ2g3sTU CnKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Y3t7IOxf9Vkdfiy1MFmpsGSvvf/wDyt1mm0FiJiJHkU=; b=Ch+qMSnQ5uGAnH8GXgZa7Ng7YaBWUiWMDoqKGBIdrExFVwftRCf7JYNUbW1tXWLnMk 7XU/giaeylzSzI/qy0zMs0vLkF0el1O5vNZx8xYPRrcXzmP3essQcIU5aD97JOFp+JTK dQQ0rm4o6dIdkOcxu+O6y9yrAMPObSWz097LdqQeg9dGdF95mkNxaKLpU6JzMsgEWvNI ktrKEhPOntV1d4BHceP/zGG9WZW6xkHc/TWHG5WVs+AOaOzmthVskgSJfFdZzzqYr3l/ 840MMRNOUke2LgDlGW+2C/e7qahtDkz480X7h0Tos8nUDitWCVBFZ90m70jB13vx5Zx1 RQtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=TgoQzblg; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j7si3780580edk.67.2021.01.15.05.15.49; Fri, 15 Jan 2021 05:16: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; dkim=pass header.i=@google.com header.s=20161025 header.b=TgoQzblg; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732030AbhAONNQ (ORCPT + 99 others); Fri, 15 Jan 2021 08:13:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731154AbhAONNQ (ORCPT ); Fri, 15 Jan 2021 08:13:16 -0500 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22AB6C061757 for ; Fri, 15 Jan 2021 05:12:36 -0800 (PST) Received: by mail-pf1-x432.google.com with SMTP id c79so5479103pfc.2 for ; Fri, 15 Jan 2021 05:12:36 -0800 (PST) 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=Y3t7IOxf9Vkdfiy1MFmpsGSvvf/wDyt1mm0FiJiJHkU=; b=TgoQzblgqtKn/uwL88l5pcnNltSdtUN3pNbr/lY71Do+YJQPensFiSR5/ah564m4QF Zdm8BQVTAFN8Zh+B5QtZJuyQ422wG3Bs/TfwzQQGuci398KLfOCKGeioJ41Hz2z0mdPF k5J3sqENcm3poD3aY3WT6X1rbtlhXUZczU80YMiNMEK1qXfJCXYtvwtFDMwP4vQjXLG2 Hf+R43rSGYBomq0cT4yigyNQG78jPO+4Bi5/7S2Zog/mtUW+lDE+89EYw5qhwnxmsKSh vQouaFKrGzDNQwoiUcRyc7dYpjUmzZqHVJyYvgXaWDWel8dz4Xx9hTrtG4KXM/kLXtp2 VVsQ== 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=Y3t7IOxf9Vkdfiy1MFmpsGSvvf/wDyt1mm0FiJiJHkU=; b=Zvfv19Ak9wdBHgb3Zs0BGUbLeqJJbvbHnUbW4+KI8+FbQjsVyr45nxK7+tRwhNgyyb 0lg2XpWKMxKT2KnTY8MQIcRuCMtUVWiATEltD0zUrZWiOEREhA34qbRspGrDYJBSNxnA PhDI5fMMJLo4G8hTzNMGNc5PeXNhnwKA2PP+qyDRUXRvxNeNxlNniatotaEenOnMJrDf fYJ60Hw5nUAeFFuZiCll+lvArIE34rj1d3/jNfHU4UnBnFsGmVw3qEtvGy9b5o3IdyxE P41BK3ibm4gxbQcfK8gxjpo2Pd4e9UYoUwQX42uGDpB9/hdUfTl3WUfeU99kNDHgUKmU EqdA== X-Gm-Message-State: AOAM530KV7NQ51rglCeW8YsEr7NkWRG+N/cKLIlXXey6Hlf3kX+UuRjM mML7rbvZ7ryc57v+znPVMEhj6bsBl5YGTPW1lbd8BA== X-Received: by 2002:a62:115:0:b029:1b4:c593:acd4 with SMTP id 21-20020a6201150000b02901b4c593acd4mr289508pfb.2.1610716355514; Fri, 15 Jan 2021 05:12:35 -0800 (PST) MIME-Version: 1.0 References: <1965508bcbec62699715d32bef91628ef55b4b44.1610553774.git.andreyknvl@google.com> <20210113165441.GC27045@gaia> In-Reply-To: <20210113165441.GC27045@gaia> From: Andrey Konovalov Date: Fri, 15 Jan 2021 14:12:24 +0100 Message-ID: Subject: Re: [PATCH 2/2] kasan, arm64: fix pointer tags in KASAN reports To: Catalin Marinas 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; > } Sounds good, will do in v3, thanks!