From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by sourceware.org (Postfix) with ESMTPS id 9930D3858D37 for ; Wed, 5 Oct 2022 02:07:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9930D3858D37 Received: by mail-lf1-x129.google.com with SMTP id y5so3999034lfl.4 for ; Tue, 04 Oct 2022 19:07:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=C8aKBMQAfzJ1g1KRqSMF93NhhkDweHYpNSO1+3xCxPw=; b=2F2tMNdWzVzLktp+tZvJw6yCO70woz3uau7WH6zdkxBaORPHc61kgrLBoackDOeB2V 9neYMs6vHkeeFM4/hCLBze4+QhIGJm2das7bjIBM0r5sNxZnqzTEOEsAI+IEXuqVNW9w FaCyyIVuVyxMGUvSc3CIYsNeQWVe+QH3TNd1rLrmACwKgkBqFleYWXn6oURFHA718Edm e21NdMayVPGH5YEtxutETirFCR06JDEwPZKtFlHYYOPYZq/jtFYosn6B4Gi9IpcDqYdK 0xwuyGByoZlcHbf/LpSzTNy8QdSiHHLdl7sU0KslVwA8EXydh0H7D616AyzhMZEXBn52 ZEAw== X-Gm-Message-State: ACrzQf0Vl87LbvVsYxkwKbY442nPu6XngdNqMCSC/xFTq1+nAnwMflMW V/nuyGzM4OKeREzS2vmK5Gx1E5OYAc7IvM2GZPMHO1+YgBc= X-Google-Smtp-Source: AMsMyM6acNJMKewqbebpLn03ecoOv4J3FATeMYtobqbQk0m15oSK1cwDc7b53tM5s9gI6xoT4mrAiJC3dnERss0T7uQ= X-Received: by 2002:a05:6512:3b9b:b0:499:b2b7:c3c1 with SMTP id g27-20020a0565123b9b00b00499b2b7c3c1mr9673999lfv.54.1664935667150; Tue, 04 Oct 2022 19:07:47 -0700 (PDT) MIME-Version: 1.0 References: <20220928025909.190260-1-koudai@google.com> In-Reply-To: From: Koudai Iwahori Date: Wed, 5 Oct 2022 10:07:35 +0800 Message-ID: Subject: Re: [PATCH] AArch64 pauth: Support backtrace in EL1 (kernel space) To: Luis Machado Cc: gdb-patches@sourceware.org X-Spam-Status: No, score=-25.6 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH, GIT_PATCH_0, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Oct 2022 02:07:51 -0000 Hi Luis, Got it, thank you! On Tue, Oct 4, 2022 at 5:24 PM Luis Machado wrote: > Hi, > > On 9/28/22 03:59, Koudai Iwahori via Gdb-patches wrote: > > The way to remove the signature bits from the address depends on the > > 55th bit of the address. If 55th bit is zero, the signature bits should > > be all cleared. If the 55th bit is one, the signature bits should be all > > set. > > --- > > I found very similar patches after fixing this issue: > > https://sourceware.org/pipermail/gdb-patches/2022-July/190507.html > > https://sourceware.org/pipermail/gdb-patches/2021-October/182859.html > > If this issue will be fixed in the near future, I can wait for it > > Yes, it should be fixed by the first link above. It is pending approval > from maintainers, which should > hopefully happen soon. > > I also have an upcoming patch (that relies on the above patch) to support > pauth for user-mode QEMU. > > See https://sourceware.org/bugzilla/show_bug.cgi?id=29421. > > > > > gdb/aarch64-tdep.c | 16 +++++++++++++++- > > 1 file changed, 15 insertions(+), 1 deletion(-) > > > > diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c > > index d0387044934..16d1e44e903 100644 > > --- a/gdb/aarch64-tdep.c > > +++ b/gdb/aarch64-tdep.c > > @@ -244,6 +244,20 @@ class instruction_reader : public > abstract_instruction_reader > > > > } // namespace > > > > +/* removes the pauth signature bits from the address. */ > > + > > +static CORE_ADDR > > +aarch64_remove_pauth_signature (CORE_ADDR addr, CORE_ADDR mask) > > +{ > > + /* 55th bit in address determines whether the address comes from the > top > > + address range or the bottom address range. */ > > + constexpr CORE_ADDR pauth_va_range_select_mask = CORE_ADDR(1) << 55; > > + if (addr & pauth_va_range_select_mask) > > + return addr | mask; > > + else > > + return addr & ~mask; > > +} > > + > > /* If address signing is enabled, mask off the signature bits from the > link > > register, which is passed by value in ADDR, using the register > values in > > THIS_FRAME. */ > > @@ -258,7 +272,7 @@ aarch64_frame_unmask_lr (aarch64_gdbarch_tdep *tdep, > > { > > int cmask_num = AARCH64_PAUTH_CMASK_REGNUM > (tdep->pauth_reg_base); > > CORE_ADDR cmask = frame_unwind_register_unsigned (this_frame, > cmask_num); > > - addr = addr & ~cmask; > > + addr = aarch64_remove_pauth_signature(addr, cmask); > > > > /* Record in the frame that the link register required > unmasking. */ > > set_frame_previous_pc_masked (this_frame); > > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by sourceware.org (Postfix) with ESMTPS id 9930D3858D37 for ; Wed, 5 Oct 2022 02:07:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9930D3858D37 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=google.com Received: by mail-lf1-x129.google.com with SMTP id y5so3999034lfl.4 for ; Tue, 04 Oct 2022 19:07:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=C8aKBMQAfzJ1g1KRqSMF93NhhkDweHYpNSO1+3xCxPw=; b=oJ9+sDz2k+AXE73rV70Ljrh3oZG9SYk1zal7qjDrpslT3xH4krG8Q9O2xWi1JC5iIq lS3IaIiOXnY7CsH5mhCaCthyZz6X+FreV9llpc88p0eVA1vAiPsgHqTA2BFSF51eRzlf meQutosTsUaevVNHbJ+q7vaVC26+IyLA5FVp4e4yex95GYeUUTom2ACqY+9/tnx7Fviz eawvP72UwfVgvuUrwqCcOjh0C+Lm9rn6QFcdFnq4fWOpVoorCcpR3X36mm1aCrNg3DD8 7Exr2TgkAWmNqyk8rLtOJORZan9CbnRLZY6IJM7/uqQ1FCYP5IlMy/jqE2hylo5vvjQd mW9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=C8aKBMQAfzJ1g1KRqSMF93NhhkDweHYpNSO1+3xCxPw=; b=2F2tMNdWzVzLktp+tZvJw6yCO70woz3uau7WH6zdkxBaORPHc61kgrLBoackDOeB2V 9neYMs6vHkeeFM4/hCLBze4+QhIGJm2das7bjIBM0r5sNxZnqzTEOEsAI+IEXuqVNW9w FaCyyIVuVyxMGUvSc3CIYsNeQWVe+QH3TNd1rLrmACwKgkBqFleYWXn6oURFHA718Edm e21NdMayVPGH5YEtxutETirFCR06JDEwPZKtFlHYYOPYZq/jtFYosn6B4Gi9IpcDqYdK 0xwuyGByoZlcHbf/LpSzTNy8QdSiHHLdl7sU0KslVwA8EXydh0H7D616AyzhMZEXBn52 ZEAw== X-Gm-Message-State: ACrzQf0Vl87LbvVsYxkwKbY442nPu6XngdNqMCSC/xFTq1+nAnwMflMW V/nuyGzM4OKeREzS2vmK5Gx1E5OYAc7IvM2GZPMHO1+YgBc= X-Google-Smtp-Source: AMsMyM6acNJMKewqbebpLn03ecoOv4J3FATeMYtobqbQk0m15oSK1cwDc7b53tM5s9gI6xoT4mrAiJC3dnERss0T7uQ= X-Received: by 2002:a05:6512:3b9b:b0:499:b2b7:c3c1 with SMTP id g27-20020a0565123b9b00b00499b2b7c3c1mr9673999lfv.54.1664935667150; Tue, 04 Oct 2022 19:07:47 -0700 (PDT) MIME-Version: 1.0 References: <20220928025909.190260-1-koudai@google.com> In-Reply-To: From: Koudai Iwahori Date: Wed, 5 Oct 2022 10:07:35 +0800 Message-ID: Subject: Re: [PATCH] AArch64 pauth: Support backtrace in EL1 (kernel space) To: Luis Machado Cc: gdb-patches@sourceware.org Content-Type: multipart/alternative; boundary="00000000000003eca405ea400b0b" X-Spam-Status: No, score=-25.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,ENV_AND_HDR_SPF_MATCH,GIT_PATCH_0,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Message-ID: <20221005020735.VlWvFLlwobNy1A0FG37LVnr3euKRnVUCJ9P5iTkPArs@z> --00000000000003eca405ea400b0b Content-Type: text/plain; charset="UTF-8" Hi Luis, Got it, thank you! On Tue, Oct 4, 2022 at 5:24 PM Luis Machado wrote: > Hi, > > On 9/28/22 03:59, Koudai Iwahori via Gdb-patches wrote: > > The way to remove the signature bits from the address depends on the > > 55th bit of the address. If 55th bit is zero, the signature bits should > > be all cleared. If the 55th bit is one, the signature bits should be all > > set. > > --- > > I found very similar patches after fixing this issue: > > https://sourceware.org/pipermail/gdb-patches/2022-July/190507.html > > https://sourceware.org/pipermail/gdb-patches/2021-October/182859.html > > If this issue will be fixed in the near future, I can wait for it > > Yes, it should be fixed by the first link above. It is pending approval > from maintainers, which should > hopefully happen soon. > > I also have an upcoming patch (that relies on the above patch) to support > pauth for user-mode QEMU. > > See https://sourceware.org/bugzilla/show_bug.cgi?id=29421. > > > > > gdb/aarch64-tdep.c | 16 +++++++++++++++- > > 1 file changed, 15 insertions(+), 1 deletion(-) > > > > diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c > > index d0387044934..16d1e44e903 100644 > > --- a/gdb/aarch64-tdep.c > > +++ b/gdb/aarch64-tdep.c > > @@ -244,6 +244,20 @@ class instruction_reader : public > abstract_instruction_reader > > > > } // namespace > > > > +/* removes the pauth signature bits from the address. */ > > + > > +static CORE_ADDR > > +aarch64_remove_pauth_signature (CORE_ADDR addr, CORE_ADDR mask) > > +{ > > + /* 55th bit in address determines whether the address comes from the > top > > + address range or the bottom address range. */ > > + constexpr CORE_ADDR pauth_va_range_select_mask = CORE_ADDR(1) << 55; > > + if (addr & pauth_va_range_select_mask) > > + return addr | mask; > > + else > > + return addr & ~mask; > > +} > > + > > /* If address signing is enabled, mask off the signature bits from the > link > > register, which is passed by value in ADDR, using the register > values in > > THIS_FRAME. */ > > @@ -258,7 +272,7 @@ aarch64_frame_unmask_lr (aarch64_gdbarch_tdep *tdep, > > { > > int cmask_num = AARCH64_PAUTH_CMASK_REGNUM > (tdep->pauth_reg_base); > > CORE_ADDR cmask = frame_unwind_register_unsigned (this_frame, > cmask_num); > > - addr = addr & ~cmask; > > + addr = aarch64_remove_pauth_signature(addr, cmask); > > > > /* Record in the frame that the link register required > unmasking. */ > > set_frame_previous_pc_masked (this_frame); > > --00000000000003eca405ea400b0b--