Received: by 10.213.65.68 with SMTP id h4csp401001imn; Tue, 13 Mar 2018 07:58:03 -0700 (PDT) X-Google-Smtp-Source: AG47ELurlKX34pABJDkF5ncW873q89jzzqzXUj7NQ8K6RbjFzw3VWPVPScB3vBp76TNdG00J6MaM X-Received: by 2002:a17:902:4222:: with SMTP id g31-v6mr836161pld.335.1520953083283; Tue, 13 Mar 2018 07:58:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520953083; cv=none; d=google.com; s=arc-20160816; b=mLW8zwT94Yi01f1KlXjU5zTIgAGPmajoz9A6UZQ8CfMtDld/5v73kDSw1CHprIUpkF JDBSY5Kky6uF4fy41pBrqHk7CEjzEl9z0noRwsJn4pB9Mlc7ulrgdoE2O6HxqoETNvDP 1MyJ2j/qJx7HJ7/f6MfGNyRPGJ1v0tuTWveNu1pJflwciP/dwvIPGxQCoY3RDQ6CUOo3 ibMBrfdLU20xo6XR385soMkLH1gnKxKdOxHoFMeP048waHtbTAuZwRpjs2lO1uyI2LVb bmi3XDfO4GuM0tmHf3HOLam2vzumcYwDkfEXRXT4hKuxnqix2AstDOtsvWsAS2KKMxcJ 7kxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=tYcDdLRbtgupyLNBiXwII9todZKPXJ3jpeGRH5ktp10=; b=N71F4FXYhFKx7q7HsJ1b9NAkdTe3Zu2ICXwPrvKwa6A0Pqsi3LtNlRV5AOx9D+0UIX ylEofHiJ8MRBc4Fzo9cq/HEb+tB7/TRFJz6UNDER++Pq4o0oyzDv780IMZ8gfnr+fzCl QOM/x0JCTEkFFbDG1sPvFFQjkOre/z197ejD+Tf2SQClHLmDT3ueQhJAP5qC20Ew5/Et cutj4/6sbmt4podK2UDSVHywSsLKKy54cnSCQZWOaPHjeQ6C1Sln0iqFcw/ddSnQRUIx nX3lkfouthauxwYVS7w0dtbkhQvT4spPELxvdafkI+n9VagHsHs1RL33vEQHs5bLC3oI F3lg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i7-v6si211983plt.374.2018.03.13.07.57.48; Tue, 13 Mar 2018 07:58:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752351AbeCMOzk (ORCPT + 99 others); Tue, 13 Mar 2018 10:55:40 -0400 Received: from mx2.suse.de ([195.135.220.15]:33164 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751720AbeCMOzi (ORCPT ); Tue, 13 Mar 2018 10:55:38 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 63B7DAF1E; Tue, 13 Mar 2018 14:55:37 +0000 (UTC) Date: Tue, 13 Mar 2018 15:55:36 +0100 From: Petr Mladek To: Jiri Kosina , Josh Poimboeuf , Miroslav Benes Cc: Jason Baron , Joe Lawrence , Jessica Yu , Evgenii Shatokhin , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v10 07/10] livepatch: Correctly handle atomic replace for not yet loaded modules Message-ID: <20180313145536.t55ogbwumaub7nqu@pathway.suse.cz> References: <20180307082039.10196-1-pmladek@suse.com> <20180307082039.10196-8-pmladek@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180307082039.10196-8-pmladek@suse.com> User-Agent: NeoMutt/20170421 (1.8.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 2018-03-07 09:20:36, Petr Mladek wrote: > The atomic replace feature uses dynamically allocated struct klp_func to > handle functions that will no longer be patched. These structures are > of the type KLP_FUNC_NOP. They cause the ftrace handler to jump to > the original code. But the address of the original code is not known > until the patched module is loaded. > > This patch allows the late initialization. Also it adds a sanity check > into the ftrace handler. > > diff --git a/kernel/livepatch/patch.c b/kernel/livepatch/patch.c > index 54b3c379bb0f..1f5c3eea9ee1 100644 > --- a/kernel/livepatch/patch.c > +++ b/kernel/livepatch/patch.c > @@ -118,7 +118,12 @@ static void notrace klp_ftrace_handler(unsigned long ip, > } > } > > + /* Survive ugly mistakes, for example, when handling NOPs. */ > + if (WARN_ON_ONCE(!func->new_func)) > + goto unlock; JFYI, this is not enough. We really have to skip klp_arch_set_pc() for NOPs. Otherwise, we end up in an infinite loop. NOPs cause that we go back to the beginning of the original function, enter the ftrace handler again, ... I am going to fix this in v11. > + > klp_arch_set_pc(regs, (unsigned long)func->new_func); > + > unlock: > preempt_enable_notrace(); Kudos to Mirek for testing and hitting the problem. Best Regards, Petr