Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp348068ybt; Wed, 24 Jun 2020 00:23:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLrUiy+EEQ7SHs8qfWNb02IxbN4wFt2Mi0hZGxHex1pg1rHO+gCEO+XYfcbC93ZM0jLqZD X-Received: by 2002:a17:906:7813:: with SMTP id u19mr19701233ejm.471.1592983384326; Wed, 24 Jun 2020 00:23:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592983384; cv=none; d=google.com; s=arc-20160816; b=nFSuM9INY7kkptWdnmwOa6Q1JTWFyQ9Q1O47HDrCBGPT5arzxqoVGQxvY/jnur9WCj LUl/+spa8PqhFLmdKntzxshRTwISVJSKIyjmupnIL+TaATD5oOklAgMyy1ayJN4RZzkz 85MiSKnaF/Obs1SxjdnuHSjHTwDZh+MlVhJna8X3DtkyKsO1Sdz4zWjRI/6x6Bx5ax68 9CX/V9pjvnxDhVw0sRxgQ+XJ/6PLQDZcsMq74buS0s+pxrjm++Gidt+PI3KoJgP6mD/s x2txGh9O3SSoOGdBVAjp8v9ttyP8gMMaf8S6jjmGoitV0bf/T37kB6UEXa82M1gQTpqO OAyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=pjnQ7WBzCOByclYff5fag1J6k77rRFjTJeOwwIhXIsI=; b=gNld3Hq+7lyYdmqAZQiC9mlL3SeFwpYa31PZKpP1azjz9diKuS1z0dhrVQTBljYcdO PpYpVseYoDUpzWVadY2COukEmufo7svZFyzlpBGaFNj+cGyzC5uGD/HFe3e9xc46HTeb iy1B3pNjtez75WplTVhZjuksIeSBP04iR22Dt2OunyCSRAWbgYmeiGrhNybvYTJDoAE5 7EiAPGSn9UllVM7zvLxGcEH6qDiYdzPMf+fSXh1ITLMjyTojc7sPOwJHqDqT2aldNq7L as/oQhyoAkU4dqaMPZqd42wIEux5G9BG7TnSXrRDtNnBB3MNfclDAhOeqP3x2+pnw+8D DWQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=LM+9Emsg; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g6si4488254edl.330.2020.06.24.00.22.41; Wed, 24 Jun 2020 00:23:04 -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; dkim=pass header.i=@chromium.org header.s=google header.b=LM+9Emsg; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389639AbgFXHVB (ORCPT + 99 others); Wed, 24 Jun 2020 03:21:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728360AbgFXHVA (ORCPT ); Wed, 24 Jun 2020 03:21:00 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DEEAC061573 for ; Wed, 24 Jun 2020 00:20:59 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id d6so784733pjs.3 for ; Wed, 24 Jun 2020 00:20:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=pjnQ7WBzCOByclYff5fag1J6k77rRFjTJeOwwIhXIsI=; b=LM+9Emsg/Bnt9ZPqcCtr1BIO53wrwaXkstgGZO8mwi6wqv0h60blnansku5od/fTJN owpxS2UsG0aNQ+ZThFnv5sjD8qtDr2g6ICUJoExlIp4x+ifOT9hyUOwAARo7C4YxFk1b ruSfG+DQPOplV5fZHpAsmSK1cGDsDRMt9v2fw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=pjnQ7WBzCOByclYff5fag1J6k77rRFjTJeOwwIhXIsI=; b=cVycf/9A7CT+Pwa9UuHK8B9jlLtkG28zWKCBmaEds2hy10pp+bOIJ1+PyMcIGS5q8c M0J/ylDZe+GUAzHEXWI8sA4LQ0+vTrNgfGuHFNvCIUgGPwCXfMGwJYeIvn9sFc5jS9hR q1+AE5hqcModHylhlcvaVExylUh91+16e/SMvdXOrdSwcZ2Tzd1vknb5YDeYHz046HgV pZ08CEHveDblcG1o3NGjy2mYObZ3pzGc4dM3UUTHDzeiA4hYqObMKYaeOQ3TntXEgA51 DA6NAYpiGQjR2R5+dUrtnukaRl/1ZBuUqXKlRUGtUlvjXeq7Sct7MdLe5VEAOby8GbwX 8zCQ== X-Gm-Message-State: AOAM530ldXOUOUiVwplvR5XmhYk/PPcpMsr9zhUbWDdcyof4rxIw5gSB g2odCCxkNhj5Uc+pRCvVNeLfvQ== X-Received: by 2002:a17:902:bd0b:: with SMTP id p11mr26994367pls.91.1592983258898; Wed, 24 Jun 2020 00:20:58 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id u20sm1917349pfm.152.2020.06.24.00.20.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2020 00:20:58 -0700 (PDT) Date: Wed, 24 Jun 2020 00:20:57 -0700 From: Kees Cook To: Kristen Carlson Accardi Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, arjan@linux.intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, rick.p.edgecombe@intel.com, Tony Luck Subject: Re: [PATCH v3 09/10] kallsyms: Hide layout Message-ID: <202006240013.7806A28435@keescook> References: <20200623172327.5701-1-kristen@linux.intel.com> <20200623172327.5701-10-kristen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200623172327.5701-10-kristen@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 23, 2020 at 10:23:26AM -0700, Kristen Carlson Accardi wrote: > This patch makes /proc/kallsyms display alphabetically by symbol > name rather than sorted by address in order to hide the newly > randomized address layout. > > Signed-off-by: Kristen Carlson Accardi > Reviewed-by: Tony Luck > Tested-by: Tony Luck > --- > kernel/kallsyms.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 128 insertions(+) > > diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c > index 16c8c605f4b0..df2b20e1b7f2 100644 > --- a/kernel/kallsyms.c > +++ b/kernel/kallsyms.c > @@ -25,6 +25,7 @@ > #include > #include > #include > +#include > > /* > * These will be re-linked against their real values > @@ -446,6 +447,11 @@ struct kallsym_iter { > int show_value; > }; > > +struct kallsyms_iter_list { > + struct kallsym_iter iter; > + struct list_head next; > +}; > + > int __weak arch_get_kallsym(unsigned int symnum, unsigned long *value, > char *type, char *name) > { > @@ -660,6 +666,127 @@ int kallsyms_show_value(void) > } > } The #ifdef can be moved up to here: #ifdef CONFIG_FG_KASLR Otherwise without CONFIG_FG_KASLR, I get: kernel/kallsyms.c:714:12: warning: ‘kallsyms_list_cmp’ defined but not used [-Wunused-function] 714 | static int kallsyms_list_cmp(void *priv, struct list_head *a, | ^~~~~~~~~~~~~~~~~ > > +static int sorted_show(struct seq_file *m, void *p) > +{ > + struct list_head *list = m->private; > + struct kallsyms_iter_list *iter; > + int rc; > + > + if (list_empty(list)) > + return 0; > + > + iter = list_first_entry(list, struct kallsyms_iter_list, next); > + > + m->private = iter; > + rc = s_show(m, p); > + m->private = list; > + > + list_del(&iter->next); > + kfree(iter); > + > + return rc; > +} > + > +static void *sorted_start(struct seq_file *m, loff_t *pos) > +{ > + return m->private; > +} > + > +static void *sorted_next(struct seq_file *m, void *p, loff_t *pos) > +{ > + struct list_head *list = m->private; > + > + (*pos)++; > + > + if (list_empty(list)) > + return NULL; > + > + return p; > +} > + > +static const struct seq_operations kallsyms_sorted_op = { > + .start = sorted_start, > + .next = sorted_next, > + .stop = s_stop, > + .show = sorted_show > +}; > + > +static int kallsyms_list_cmp(void *priv, struct list_head *a, > + struct list_head *b) > +{ > + struct kallsyms_iter_list *iter_a, *iter_b; > + > + iter_a = list_entry(a, struct kallsyms_iter_list, next); > + iter_b = list_entry(b, struct kallsyms_iter_list, next); > + > + return strcmp(iter_a->iter.name, iter_b->iter.name); > +} > + > +int get_all_symbol_name(void *data, const char *name, struct module *mod, > + unsigned long addr) This can be static too. Otherwise, looks good! Reviewed-by: Kees Cook -- Kees Cook