Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp9347726rwp; Thu, 20 Jul 2023 03:40:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlHqawLAKrdGAEfQmQYKAOYmhbJE7jSvPdzY5dzcqN37L3I+Ktf04xOm7JzaVysaK9SFExu6 X-Received: by 2002:a05:6402:3453:b0:51d:9362:5060 with SMTP id l19-20020a056402345300b0051d93625060mr5213996edc.1.1689849643096; Thu, 20 Jul 2023 03:40:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689849643; cv=none; d=google.com; s=arc-20160816; b=kUyX5tCI9D32kAlAnPYlImgiN6kLuqva/CWrU67se791wrCWkh2w7LNdIyTTasVoi3 58DCpH8h8Ce0SpDaie2sYLBWhbk8JYjiuDaPDbZTYlJdYiLFYGCWMtFoLVMThjuyxWs3 YbvXdrtw+1QYh3rXSGZXRjcZG3W188ejMAH0PUAWAZhJG9YSpwhizw/mxdJG6e5c8V8o HNF6KtB7k9/HWU1Va98OAeHXIsdAYvVt4wGYDvT1zdoPZ2VZzxPAi2xtFQPbIhl05z0U xtMA9qTZG+3Sn9FTJYS+X/yyBNh3rM9Ztx2wChyPTn68aOaOk15hp5OxFRt2+MeqOP6x /nwQ== 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=RZvdXjx1hZtcZSf74NvFvf8MQ6mexnlAJnPNEN00Cyo=; fh=sLr9i3UKTg/E1bxeYGHva8pnlb4gD81vLxtpnD8i5rU=; b=yOYk+C2NUdgRkY5/SwaY4Kqn5Xy7zVvsRHFyA31PnogRqyH0XzKbSRF8fGmh8AEoqc mpVBeBtUn7S9+yZ8U+olsEwmWprSaixpbOxxng6iJy06rJxTzvsW40NoHu7z0y60gR0k 6Qv/QHB+J6laveX5hMP9GJ9nza44856zcHPJgQXVn5QSUMUHtoqef7KNxt/S26Zlgqv+ GtQZHd2FB4WQFgmlTjXRGGDPR8Dis9YMEwhuglgQMf0M6FefdIA7SbmpqSwkNKttSCcE Nq3xVSjE7nuXSXxh5goWt/MounkNHi7H1OSNf4D3AAadncmUF0HxhVFipMPt/kvW1TLK 8iLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=DKTvOeHt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r1-20020aa7da01000000b0051e2cc05ba9si591639eds.306.2023.07.20.03.40.19; Thu, 20 Jul 2023 03:40:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=DKTvOeHt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230492AbjGTJhK (ORCPT + 99 others); Thu, 20 Jul 2023 05:37:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230140AbjGTJgt (ORCPT ); Thu, 20 Jul 2023 05:36:49 -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 2228C3A8D; Thu, 20 Jul 2023 02:32:02 -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=RZvdXjx1hZtcZSf74NvFvf8MQ6mexnlAJnPNEN00Cyo=; b=DKTvOeHtImBp0sx+QDcm4M4JsL qsSH7Thf3bOAZW38uH+7ZGk+wggvENeAqtgEkqneCUryBAV60eSBqQAQFjBwVc37JLdR7zSULLWbF 9Y/7Jph8JzC9EpjTCGE1t/Jkris7QZt1pmKUndRam9oV4FcykVnINIbdkfUHbc2As82dvadGGUrDM cLWcgSuHODpWt6eHikxFd4RWgMVeEMfbLmZsU5hO5ek+nsWjK5VCPcvLl4VVcXtPuiO74k3YixW3l UqCRth0P1jmjFA2WpHeR9sAlifdsFwZmQKF1ijbxZClRfhWefrt8AsKrsraucwvRK9UBsnJopP40i StxTQzYg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qMPxB-00FSy1-1K; Thu, 20 Jul 2023 09:30:09 +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 (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 699A5300342; Thu, 20 Jul 2023 11:28:07 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 44F092B32666E; Thu, 20 Jul 2023 11:28:07 +0200 (CEST) Date: Thu, 20 Jul 2023 11:28:07 +0200 From: Peter Zijlstra To: Josh Poimboeuf Cc: Petr Mladek , Brian Gerst , linux-kernel@vger.kernel.org, x86@kernel.org, Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Sami Tolvanen , alyssa.milburn@linux.intel.com, keescook@chromium.org, joao@overdrivepizza.com, tim.c.chen@linux.intel.com, live-patching@vger.kernel.org Subject: Re: [PATCH v2 2/2] x86: Rewrite ret_from_fork() in C Message-ID: <20230720092807.GB3570477@hirez.programming.kicks-ass.net> References: <20230623225529.34590-1-brgerst@gmail.com> <20230623225529.34590-3-brgerst@gmail.com> <20230719200222.GD3529734@hirez.programming.kicks-ass.net> <20230719201538.GA3553016@hirez.programming.kicks-ass.net> <20230719205050.GG3529734@hirez.programming.kicks-ass.net> <20230719233111.kqafaqect4v2ehu6@treble> <20230720052208.GO4253@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230720052208.GO4253@hirez.programming.kicks-ass.net> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 20, 2023 at 07:22:08AM +0200, Peter Zijlstra wrote: > > I'm not sure that would be worth the trouble / cleverness. The hint is > > straightforward IMO. > > I tried, it doesn't work, clearly I missed something. FWIW, I tried the below. That should make user_mode() true for the kernel thread regset, and while the kernel did boot, it still fails the livepatch self-test. The difference seems to be that END_OF_STACK terminates it right there, while REGS thinks its a valid frame and only terminates on user_mode() when unwinding one more frame. The frame at REGS clearly isn't very sane. diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index 72015dba72ab..45a400b16b80 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -232,6 +232,7 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) * It does the same kernel frame setup to return to a kernel * function that a kernel thread does. */ + childregs->cs = 3; childregs->sp = 0; childregs->ip = 0; kthread_frame_init(frame, args->fn, args->fn_arg);