Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp297873pxk; Thu, 24 Sep 2020 06:08:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw40VTtHxdYDhnCpFm4gd4sfjCPYsFljQ3bB3+SpQZRUZmc5yvK69p/hJR3n2ayUSggDpRA X-Received: by 2002:a17:906:f1cf:: with SMTP id gx15mr899167ejb.241.1600952888648; Thu, 24 Sep 2020 06:08:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600952888; cv=none; d=google.com; s=arc-20160816; b=KQuXEIOlHtWj/nmWiLQKCy8TCPpbZy52ymQ3OayKRMaPGqLf1wH/eaUosAG7kuQjK+ RFu6OdPe8d1AbUltFDQErHSTBRRyMjDnG4a4ja4FEhLp96j9lUnsJFfBnjCkoEuZsENw kKy2qvyt+8k1/1uj85oIrrtckY2XsVlBlgEUQQK+TDQ6lTlRJ7SkKu2cddllYT1WYIC9 pWBycMaberVnH9/MHrdSY1pGsGErPr3tHuN2kMbq4BGUnu8+l4Q4QcxwbAus/y7R4W4u NFBqWfixr/kbUe+rUrgdHm8Y+gYMh56KdFL3kjNe83Jt7LXnX4g/QAt4ncQOjJBMCUD4 RsoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date; bh=4nqGzjZKwtA396r/cTcnPVOtA4QGz4wRg5rDzulS9X4=; b=RrKcNqiN96b1gwwusEzP/Pz+l7kZ1Idn82f0qcMfh2MfCukwZCo3DfNFjMUhUKIHtP vl2TDmYDwCbkw52WpgZ481BKe1YQZw0/JnWklnZRBh2oj6/exaUD1mfZnjg1EOtwzlMs QWxMMAZmYKNGsZAU/JFZLet+/uxbJN+EriBeycMLzPyqrDys3tZ267U7C+vXfhbU2lIs yd19uAFoLLil0qKIJ/1MB7ovUyD4dL+7XGD4/m6dQJHz/e4S221dHsi869lRhxhDC8Fb uORvjcIHQKuKlvqx7EpxiHqYtKkN4wcJD0FTEpkUuTW1SW6CSiqv+zyvzsGxtk/0D6Ns ulYg== ARC-Authentication-Results: i=1; mx.google.com; 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 h7si1865794ejl.266.2020.09.24.06.07.43; Thu, 24 Sep 2020 06:08:08 -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; 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 S1727869AbgIXNGJ (ORCPT + 99 others); Thu, 24 Sep 2020 09:06:09 -0400 Received: from mx2.suse.de ([195.135.220.15]:33410 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727704AbgIXNGJ (ORCPT ); Thu, 24 Sep 2020 09:06:09 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A1692AD5F; Thu, 24 Sep 2020 13:06:07 +0000 (UTC) Date: Thu, 24 Sep 2020 15:06:06 +0200 (CEST) From: Miroslav Benes To: Kristen Carlson Accardi cc: keescook@chromium.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, Josh Poimboeuf , Jiri Kosina , Petr Mladek , Joe Lawrence , arjan@linux.intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, rick.p.edgecombe@intel.com, live-patching@vger.kernel.org Subject: Re: [PATCH v5 10/10] livepatch: only match unique symbols when using fgkaslr In-Reply-To: <20200923173905.11219-11-kristen@linux.intel.com> Message-ID: References: <20200923173905.11219-1-kristen@linux.intel.com> <20200923173905.11219-11-kristen@linux.intel.com> User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Wed, 23 Sep 2020, Kristen Carlson Accardi wrote: > If any type of function granular randomization is enabled, the sympos > algorithm will fail, as it will be impossible to resolve symbols when > there are duplicates using the previous symbol position. > > Override the value of sympos to always be zero if fgkaslr is enabled for > either the core kernel or modules, forcing the algorithm > to require that only unique symbols are allowed to be patched. > > Signed-off-by: Kristen Carlson Accardi > --- > kernel/livepatch/core.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c > index f76fdb925532..da08e40f2da2 100644 > --- a/kernel/livepatch/core.c > +++ b/kernel/livepatch/core.c > @@ -170,6 +170,17 @@ static int klp_find_object_symbol(const char *objname, const char *name, > kallsyms_on_each_symbol(klp_find_callback, &args); > mutex_unlock(&module_mutex); > > + /* > + * If any type of function granular randomization is enabled, it > + * will be impossible to resolve symbols when there are duplicates > + * using the previous symbol position (i.e. sympos != 0). Override > + * the value of sympos to always be zero in this case. This will > + * force the algorithm to require that only unique symbols are > + * allowed to be patched. > + */ > + if (IS_ENABLED(CONFIG_FG_KASLR) || IS_ENABLED(CONFIG_MODULE_FG_KASLR)) > + sympos = 0; This should work, but I wonder if we should make it more explicit. With the change the user will get the error with "unresolvable ambiguity for symbol..." if they specify sympos and the symbol is not unique. It could confuse them. So, how about it making it something like if (IS_ENABLED(CONFIG_FG_KASLR) || IS_ENABLED(CONFIG_MODULE_FG_KASLR)) if (sympos) { pr_err("fgkaslr is enabled, specifying sympos for symbol '%s' in object '%s' does not work.\n", name, objname); *addr = 0; return -EINVAL; } ? (there could be goto to the error out at the end of the function). In that case, if sympos is not specified, the user will get the message which matches the reality. If the user specifies it, they will get the error in case of fgkaslr. Thanks for dealing with it Miroslav