Received: by 10.223.185.116 with SMTP id b49csp2393419wrg; Thu, 22 Feb 2018 13:02:08 -0800 (PST) X-Google-Smtp-Source: AH8x2254RBhNgOwAirvehLGSkMwY+Mg9jhIuCQ6k/1SI1aamOskJq2G1NsINao1INzdy8S1J98wP X-Received: by 10.98.252.22 with SMTP id e22mr8129676pfh.235.1519333328681; Thu, 22 Feb 2018 13:02:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519333328; cv=none; d=google.com; s=arc-20160816; b=AwduqY2ftD7158r0CPFvh5wSr9JOpM1zg0kDJsVzIBxZl3AA6MWfmi8X6cpiDkT6Fw xJNeRA8ODabfZvVpvOzMw7JwD8l3SczRTAsvL6o+ljstexziYsW8DmDH8WHt61yKtRFg YtYccjcQZGgvAbzcCUoTgUILqHauM+YhAh0xzGAZMMjS0u5dLC5fD+DyFuHP48Jsm8Gs 8NVLTOE5X9QNM7IsBeSTVAiohAdnPIBsEKyRoEyK+GjlL7Jf/tjx3ONlB80+P41Ld/2o 5WWAB5mSngLkSFgpjzpBmyhkdLOXfaYMnjAPiOewekoYETsbTe8RqWN/sQ1uLvVdJ/aK cOuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=gyNwxRrL77OWnDAAkI5HmZ+dgbxcZLXMLsZf6iHrTWI=; b=rweeH1SzYQBpJn6FGO/xyJYroSrp6p6iEAIzVBYgUFeQ2xPzL4QNJj5G6ymBaVESO5 cRgzha5thiDOgxVIBBvtD3oxzMRlvx2m1YIndQwSgG4ra3j0pLN7FNsHEPFkOSLF0f/X hnljynwpQmVIigFsBMbS2tQ9LQid9CuY24bRxflZrl7EP4umCsVF0meNv/20BCWl3sZo MM6BJOG0KuDdVJ4H9G5WRCCqTOGqe6i6EkexrvNzuEzJDyoXCzZ+AWth6EIwdZK5sbCn B9uZ5iOyv9l1cVyrk4H1eBhB1iNJbSihvP91Dp0Z6Mlh/Ju2YLbIvkL2oGm77F6eeQdE r//Q== 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 g23si204644pfg.341.2018.02.22.13.01.42; Thu, 22 Feb 2018 13:02:08 -0800 (PST) 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 S1751366AbeBVVAd (ORCPT + 99 others); Thu, 22 Feb 2018 16:00:33 -0500 Received: from mx2.suse.de ([195.135.220.15]:36747 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751119AbeBVVAc (ORCPT ); Thu, 22 Feb 2018 16:00:32 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E884DAF33; Thu, 22 Feb 2018 21:00:30 +0000 (UTC) Date: Thu, 22 Feb 2018 22:00:28 +0100 (CET) From: Miroslav Benes To: Petr Mladek cc: Jiri Kosina , Josh Poimboeuf , Jason Baron , Joe Lawrence , Jessica Yu , Evgenii Shatokhin , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v8 7/8] livepatch: Correctly handle atomic replace for not yet loaded modules In-Reply-To: <20180221132914.4809-8-pmladek@suse.com> Message-ID: References: <20180221132914.4809-1-pmladek@suse.com> <20180221132914.4809-8-pmladek@suse.com> User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 21 Feb 2018, Petr Mladek wrote: > The atomic replace feature uses dynamically allocated struct klp_func to > handle functions that will not longer be patched. These structures are s/not longer/no longer/, but "handle functions that will not be patched any longer" may be even better. > 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. > > Alternative solution would be to do not set the address at all. The ftrace "Alternative solution would be not to set the address at all." ? > handler could just return to the original code when NOP struct klp_func > is used. But this would require another changes. For example, in the stack > checking. Note that NOP structures might be available even when the patch > is being disabled. This would happen when the patch enable transition is > reverted. > > Signed-off-by: Petr Mladek > --- > kernel/livepatch/core.c | 16 ++++++++++++++-- > kernel/livepatch/patch.c | 5 +++++ > 2 files changed, 19 insertions(+), 2 deletions(-) > > diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c > index ad508a86b2f9..da1438d47d83 100644 > --- a/kernel/livepatch/core.c > +++ b/kernel/livepatch/core.c > @@ -945,8 +945,12 @@ static void klp_free_object_loaded(struct klp_object *obj) > > obj->mod = NULL; > > - klp_for_each_func(obj, func) > + klp_for_each_func(obj, func) { > func->old_addr = 0; > + > + if (klp_is_func_type(func, KLP_FUNC_NOP)) > + func->new_func = NULL; > + } > } > > /* > @@ -984,7 +988,12 @@ static void klp_free_patch(struct klp_patch *patch) > > static int klp_init_func(struct klp_object *obj, struct klp_func *func) > { > - if (!func->old_name || !func->new_func) > + if (!func->old_name) > + return -EINVAL; > + > + /* NOPs do not know the address until the patched module is loaded. */ > + if (!func->new_func && > + (!klp_is_func_type(func, KLP_FUNC_NOP) || klp_is_object_loaded(obj))) > return -EINVAL; If we changed the order of klp_init_func() and klp_init_object_loaded() calls in klp_init_object(), the hunk would not be needed. Is that correct? But that would require more changes elsewhere, so it's not worth it, I think. > INIT_LIST_HEAD(&func->stack_node); > @@ -1039,6 +1048,9 @@ static int klp_init_object_loaded(struct klp_patch *patch, > return -ENOENT; > } > > + if (klp_is_func_type(func, KLP_FUNC_NOP)) > + func->new_func = (void *)func->old_addr; Is there a reason why you left the same assignment in klp_alloc_func_nop()? This one is enough, no? Miroslav