Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1030209pxb; Sat, 17 Apr 2021 04:38:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrjlq4B2tyUpIA0PRgRQ/3PIe6lH1Enx1z49v1D7XqI2r/gHowVbmSw7VGFkJTuk9/IFn1 X-Received: by 2002:aa7:8dd2:0:b029:247:c334:5e6f with SMTP id j18-20020aa78dd20000b0290247c3345e6fmr11417878pfr.57.1618659496041; Sat, 17 Apr 2021 04:38:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618659496; cv=none; d=google.com; s=arc-20160816; b=SHI/ITfbMurxUI/K6yzQESIuNWrtw5SpJTVCsU+xcPb2iaQqsFulwnq4m6HXc0x+r2 Vgc4+qPvxxt+4AFsoz00sZ5ezEEZAbn7M1b2IxShnUAXl7dZk9b1leGT3VQLBLNjZpr6 sp+dg+SovNgJ3dm2WD15sJ0QHwU+6zoNfGobAGzEwR9oqqxbCUJpv8eHyG085E0dZ6p+ OihM08fZxKSRAdzeI7myJxUgT730KEX1R7YpgFoVeIDA/dYi3fXK5/KYMYqpWV2jMUQj snGR+6xrd8VaeCiJLsVKs6TkbeyHNzIWMYUXgCvnvojKqFxUWITq4SIYAFdhrKv563zj qhVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=La4K9Hxv90PEzdP4s04b75vImRFep6ZDy8BSpr4Z3TU=; b=yOMQ4AWImdds1PXT2cHhVyce1zEBYkffsFPMdalmQjwp14weePpVwAxIdh3LXsSxAq HvTb1iPdl6pHRQtwO0IQMSWgd4/CI/g4H7zez+HJFm26wgxzGrimL1rXOu2ojbkz+dMc KZjISJ6udV7As5FeHrXXCgKPDHaoEXJIYaVcjGXt8QmplXfTDLeNa760d8MblVYhCSmN fVA/n+FoIBmSWJ5W/ZteWJ9YwCiCOSYbE1lfBm1qNyfv/8pp+6Ydj5StKeZDjxsCubdi 79C9J9BgXUL1EjInkDNIjLak5u71JgXMqBHA/+aiY19ceg+zLUeatsWQnxd+AlVbWdkB mDJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=CqzfOhgP; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e5si9489242pfc.160.2021.04.17.04.38.03; Sat, 17 Apr 2021 04:38:16 -0700 (PDT) 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=@infradead.org header.s=desiato.20200630 header.b=CqzfOhgP; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236078AbhDQLiB (ORCPT + 99 others); Sat, 17 Apr 2021 07:38:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231387AbhDQLiB (ORCPT ); Sat, 17 Apr 2021 07:38:01 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFD15C061574; Sat, 17 Apr 2021 04:37:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=La4K9Hxv90PEzdP4s04b75vImRFep6ZDy8BSpr4Z3TU=; b=CqzfOhgP0hN9dlahV60EMckVBX XYB8SJZUJ+Jjjx7wvCIyJvU66An/eIJy+4L3gsg0bSh8H17LQ11f6zLxd8mISkOEhL7PBTTbJ4eMn SGLkvymcS9NLU9u3ysgR/0cCjN2XVFKnfoh7K6cAaorUM/6waIRURtzhzoA8heavyPnPswGVEJ6Er N+oqwCwnNxNYoRGiLAsGCw9lRu4JV8JWbT+fxm1vRs6TRKGUaLuHkGg/yvKRhev31UV5mnPOJ2b2O vlusG1fIQIIHG+AIuePpAl358FHVGgf1g16n+OhmpDQr+BBI3w7SiIcyPwzi0WdeC1xbNdZIGVROU 9CVkyr8g==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lXjGO-005BXG-D2; Sat, 17 Apr 2021 11:37:26 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id CA636300212; Sat, 17 Apr 2021 13:37:23 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id A53742D2112CE; Sat, 17 Apr 2021 13:37:23 +0200 (CEST) Date: Sat, 17 Apr 2021 13:37:23 +0200 From: Peter Zijlstra To: Sami Tolvanen Cc: x86@kernel.org, Kees Cook , Josh Poimboeuf , Nathan Chancellor , Nick Desaulniers , Sedat Dilek , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com Subject: Re: [PATCH 09/15] x86/alternatives: Use C int3 selftest but disable KASAN Message-ID: References: <20210416203844.3803177-1-samitolvanen@google.com> <20210416203844.3803177-10-samitolvanen@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210416203844.3803177-10-samitolvanen@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 16, 2021 at 01:38:38PM -0700, Sami Tolvanen wrote: > From: Kees Cook > > Instead of using inline asm for the int3 selftest (which confuses the > Clang's ThinLTO pass), this restores the C function but disables KASAN > (and tracing for good measure) to keep the things simple and avoid > unexpected side-effects. This attempts to keep the fix from commit > ecc606103837 ("x86/alternatives: Fix int3_emulate_call() selftest stack > corruption") without using inline asm. > > Signed-off-by: Kees Cook > Signed-off-by: Sami Tolvanen > --- > arch/x86/kernel/alternative.c | 21 ++++----------------- > 1 file changed, 4 insertions(+), 17 deletions(-) > > diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c > index 6974b5174495..669a23454c09 100644 > --- a/arch/x86/kernel/alternative.c > +++ b/arch/x86/kernel/alternative.c > @@ -496,23 +496,10 @@ extern struct paravirt_patch_site __start_parainstructions[], > * > * See entry_{32,64}.S for more details. > */ > - > -/* > - * We define the int3_magic() function in assembly to control the calling > - * convention such that we can 'call' it from assembly. > - */ > - > -extern void int3_magic(unsigned int *ptr); /* defined in asm */ > - > -asm ( > -" .pushsection .init.text, \"ax\", @progbits\n" > -" .type int3_magic, @function\n" > -"int3_magic:\n" > -" movl $1, (%" _ASM_ARG1 ")\n" > -" ret\n" > -" .size int3_magic, .-int3_magic\n" > -" .popsection\n" > -); > +static void __init __no_sanitize_address notrace int3_magic(unsigned int *ptr) > +{ > + *ptr = 1; > +} I really don't like this. the compiler is free to mess this up in all sorts of ways. The problem is that the call-site does not respect the regular calling convention, so calling a regular C function is just asking for trouble, which is why it ended up being asm, then we fully control the calling convention.