Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp795579ybi; Thu, 30 May 2019 06:56:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqwJ2hvLTU4FXA6S2WdLsmdk18oCpa6qzORIknUKJ+EqxRYGOSkhpGpukjNVNiMNQUQelNYk X-Received: by 2002:a17:90a:9bc4:: with SMTP id b4mr3898380pjw.100.1559224605722; Thu, 30 May 2019 06:56:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559224605; cv=none; d=google.com; s=arc-20160816; b=Dvr4p2gsx92nVtYeR5L3nQBtfu/tcEM1aCd+cop2BvRgfNnzDsGEHLfAQeAumPziKB 0OFb1ZQ3KDRbeoBHhILZEi2FKItYUgMGPLFGcRDAvT22CO56yVsMTqN8hFxOlhliBqhi JFjfhawTE2bwNk2ICR48ZD3P5fxCDZIZjEtmgN0k3qPuVFWc0slkP0K5tDB3E1NGNNkL oJsUayyXsd9PPJ+g7MDfwqC4Ni8qWw6DzxWkUauyBjNhH7zsGC/o4nJiMr0QUVQS+KGf 45+/sHoI7gV2XIva9596LoTHryHJjO3fi8KQDpic+DzkIRuV3/MpYRwgweAUExvsOcgy ywCA== 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; bh=4n4B5wKPsg0+g9lQnS6GIWzlWMIoRSCZQgMACFqEk0Q=; b=aaLYjoy8Frdl+q+y8/nHjU6FcBaClx/F8ymdFkXkwaHgNOYoZOuDfO6L5w102179bg dqtMonTNOiNW8W1H+GlKID0jN/7fgiRK4i1bslhnce+UA46qD5Lirop9io5rK9+P2vII SYUYQLjjrOox/TXiWJopTblJFW+uk2t+9f9lM01BikO0N71I5XrvTcAR9dohpY5H+p3j F6kKACsG2iyuRTPGjguwIdfAUlF6bk0BSmAltq+Mv/oh9ScfkQ3iMznZOylWVWOgfsyR g7inglBht/n76YoHf9hqrPQOMPX6NBpgtIMcqsW9yQGHGHfcs2gsU4wPVHhgV0C4ZkhR X3Vw== 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 y12si3118885pgc.97.2019.05.30.06.56.29; Thu, 30 May 2019 06:56:45 -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 S1726831AbfE3NyR (ORCPT + 99 others); Thu, 30 May 2019 09:54:17 -0400 Received: from mx2.suse.de ([195.135.220.15]:40772 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725870AbfE3NyR (ORCPT ); Thu, 30 May 2019 09:54:17 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id F04F9ADD9; Thu, 30 May 2019 13:54:15 +0000 (UTC) Date: Thu, 30 May 2019 15:54:14 +0200 From: Petr Mladek To: Josh Poimboeuf Cc: Steven Rostedt , Jiri Kosina , Miroslav Benes , Jessica Yu , Joe Lawrence , linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, Johannes Erdfelt , Ingo Molnar Subject: Re: [PATCH] livepatch: Fix ftrace module text permissions race Message-ID: <20190530135414.taftuprranwtowry@pathway.suse.cz> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170912 (1.9.0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 2019-05-29 14:02:24, Josh Poimboeuf wrote: > The above panic occurs when loading two modules at the same time with > ftrace enabled, where at least one of the modules is a livepatch module: > > CPU0 CPU1 > klp_enable_patch() > klp_init_object_loaded() > module_disable_ro() > ftrace_module_enable() > ftrace_arch_code_modify_post_process() > set_all_modules_text_ro() > klp_write_object_relocations() > apply_relocate_add() > *patches read-only code* - BOOM This patch looks fine and fixes the race: Reviewed-by: Petr Mladek That said, the semantic of text_mutex is a bit unclear: + It serializes RO/RW setting but not NX + Nothing prevents manipulation of the access rights by external code before the module is ready-enough. I mean before the sections are set RO by the module loader itself. Most sections are ready in MODULE_STATE_COMMING state. Only ro_after_init sections need to stay RW longer, see my question below. > diff --git a/kernel/module.c b/kernel/module.c > index 6e6712b3aaf5..3c056b56aefa 100644 > --- a/kernel/module.c > +++ b/kernel/module.c > @@ -3519,7 +3534,7 @@ static noinline int do_init_module(struct module *mod) > /* Switch to core kallsyms now init is done: kallsyms may be walking! */ > rcu_assign_pointer(mod->kallsyms, &mod->core_kallsyms); > #endif > - module_enable_ro(mod, true); > + __module_enable_ro(mod, true); The "true" parameter causes that also ro_after_init section is set read only. What is the purpose of this section, please? I ask because module_enable_ro(mod, true) can be called earlier from klp_init_object_loaded() from do_one_initcall(). For example, it could some MODULE_STATE_LIVE notifier when it requires write access to ro_after_init section. Anyway, the above is a separate problem. This patch looks fine for the original problem. Best Regards, Petr