Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CBB5C54E94 for ; Wed, 25 Jan 2023 17:27:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235339AbjAYR1x (ORCPT ); Wed, 25 Jan 2023 12:27:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235311AbjAYR1u (ORCPT ); Wed, 25 Jan 2023 12:27:50 -0500 Received: from mail.zytor.com (unknown [IPv6:2607:7c80:54:3::138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DE3A35AB; Wed, 25 Jan 2023 09:27:48 -0800 (PST) Received: from [127.0.0.1] ([73.223.250.219]) (authenticated bits=0) by mail.zytor.com (8.17.1/8.17.1) with ESMTPSA id 30PHPOXR3191416 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NO); Wed, 25 Jan 2023 09:25:24 -0800 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 30PHPOXR3191416 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2023010601; t=1674667525; bh=VnoyFUy9dOE00kCz07pDoYxTfplcGaca5G+hnmBxs+s=; h=Date:From:To:CC:Subject:In-Reply-To:References:From; b=QbTpX7nL7CyyJ6yfVZ8M5fweKYAIjwNmBEApgktVaVlmfH/soztuowedAJ8+WjIiX iSpsQMM7fnHKUvAmeTaL6eg6/Nofmklx+0YI1wlZ0fFsF/XrQ7bevAgERPeKdL/1t6 vaTDilZR2MNcpuqkJFPZNkSTmmbAJwxih+Qocs6A8M7l35tqonA5/NqutwBG/d137l jDkL4F/Dw3WrpbQkqbEcrlVj0UY25F79iDf634NXBaufOG0DsdH9Og5BNDV7IZcmRF 0xUPYQC1M2bqWt+YNGdtObPYqufufCQb7p/bxgIt3OlEgw3oVjrRwdqtrZgHnpoxFm xICw+ZEgkjS5w== Date: Wed, 25 Jan 2023 09:25:21 -0800 From: "H. Peter Anvin" To: Ammar Faizi CC: Xin Li , Dave Hansen , Dave Hansen , Thomas Gleixner , Andrew Cooper , Brian Gerst , Ingo Molnar , Borislav Petkov , Peter Zijlstra , Shuah Khan , Ingo Molnar , Andy Lutomirski , x86 Mailing List , "Kirill A. Shutemov" , Linux Kselftest Mailing List , Linux Kernel Mailing List Subject: =?US-ASCII?Q?Re=3A_=5BRFC_PATCH_v5_1/2=5D_selftests/x86=3A_sy?= =?US-ASCII?Q?sret=5Frip=3A_Handle_syscall_in_a_FRED_system?= User-Agent: K-9 Mail for Android In-Reply-To: References: <20230124022729.596997-3-ammarfaizi2@gnuweeb.org> <20230125034958.734527-1-ammarfaizi2@gnuweeb.org> <20230125034958.734527-2-ammarfaizi2@gnuweeb.org> <8770815f-0f23-d0c5-e56a-d401827842c9@zytor.com> Message-ID: <13EFEDBA-3BC2-4654-BFDD-53E79178107B@zytor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On January 25, 2023 3:37:23 AM PST, Ammar Faizi = wrote: >On Wed, Jan 25, 2023 at 02:17:41AM -0800, H=2E Peter Anvin wrote: >> I guess it would depend on what they "normally" are=2E My #1 impulse wo= uld be to leave them both unchanged=2E > >Ah okay=2E=2E=2E I think I understand now=2E My confusion came from a com= ment >in that code=2E > >The current SIGUSR1 handler has a comment: > > /* Set IP and CX to match so that SYSRET can happen=2E */ > ctx->uc_mcontext=2Egregs[REG_RIP] =3D rip; > ctx->uc_mcontext=2Egregs[REG_RCX] =3D rip; > >So I thought if we leave them both unchanged, then SYSRET can happen >too, because IP and CX match=2E My initial confusion about that was: > > Where do we actually exercise IRET if the SIGUSR2 handler > exercises SYSRET then? > >I realized my assumption was wrong=2E The current SIGUSR1 handler >actually forces the kernel to use IRET, not SYSRET=2E Because the %rip >is set to a non-canonical address=2E So that's the place where it >exercises IRET=2E > >IOW, my understanding now: > >The current SIGUSR1 handler exercises the SYSRET-appropriate condition >detector in the kernel=2E It doesn't actually go to the SYSRET path >despite the comment saying "SYSRET can happen"=2E That detector must take >us to the IRET path or we will #GP in kernel space on Intel CPUs=2E > >In short, the SIGUSR1 handler asserts that "SYSRET must *not* happen"=2E > >The expected SIGUSR2 handler addition exercises the SYSRET path by >leaving REG_IP and REG_CX unchanged=2E > >Am I correct? > That's the idea=2E