Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp817020ybg; Tue, 9 Jun 2020 13:41:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJ644g1pniu76Bth7nrt8c461AazbAzDrvL9GfKfp19MpZtPujMRce+Lm0GJubWW/9l4// X-Received: by 2002:a05:6402:a4d:: with SMTP id bt13mr23755917edb.338.1591735275179; Tue, 09 Jun 2020 13:41:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591735275; cv=none; d=google.com; s=arc-20160816; b=uveyE95rbHY9Pwz9rIXObjuDcCg+FVQ//j67IbZBwJ85dWa44uRr6mtdPliIob0t5C mV3fWxoRRCHnqAYaTiHggl68eMzq1gQZtQw82XRqGPYSWGkNhOfThK9QlLp6VphYTlfD 4JHzdPXO+/CSFC1giacVzLiYCb5nHXZKBSYuaoJW/4t81dl5qDcyMuLkhkl8RAT0uNHn Ig9swFHmJd8r42OZ7YxiOQLwIQb8czdJ6beQlRlIiYw/W37YdMrXOWwQpmRZG9VMSrw7 yBjK1TrReUxB7E+YXWOZweixzTkvPEheW+fqQ4k3a1vIbsCpTOf9o/ckj8AMCC5Jk3WS /d7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:ironport-sdr:ironport-sdr; bh=Fb3AtjM1yukwzWzNP1od44gQGy3tn61LU9otg28Tk+s=; b=bexb8x6zOe9ReAk5fs5K7Q28X8URSiTqXPc1q2pScckhh/VZnhRvWi0wBG8ubb1Gbp 5RAjU2gJx6oKRY8H/A3zqQ0COYsMt5zjqf8mqv0XgVtf8PdmuwZ2NnpXLkxXyPKrKsCv bV1zmi7x1AauZmK8nnLpgQR/PWWDQtTRJyU8borNnyP4S8Q6L81LzgHxIpVT7NRRHzs+ ix+/TuJk8Ld8P+xYemfiL+qfqtX/OKFEjhTkuTf11MTVUy3OUqkye4RXF5cdKpPF/nSq Aj1U45nl6GmEr2TjVh+iR/xN9lwJzcSV1cRhvA5vxftUs9bUbpTlQpFmbNWi7qnmQx4q FbpA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ha1si11398281ejb.67.2020.06.09.13.40.50; Tue, 09 Jun 2020 13:41:15 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389435AbgFIUOJ (ORCPT + 99 others); Tue, 9 Jun 2020 16:14:09 -0400 Received: from mga02.intel.com ([134.134.136.20]:46624 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732949AbgFIUOI (ORCPT ); Tue, 9 Jun 2020 16:14:08 -0400 IronPort-SDR: pJjQmQ7rYVIqJHZ7M3dROX4oRMjFbvAqWtbNTBufvcA/TptP61OB3x5KUahfBAybOLUAUUcOFW dFiQetWm5oPA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2020 13:14:08 -0700 IronPort-SDR: uPlyW+8nDixVNiEUxdlfEfyekV6D7tF/zCK1DQBiWjoZFvVDLqrUlA2S24HrpGgJM10qZS9E/t /u1+3pILi+tw== X-IronPort-AV: E=Sophos;i="5.73,493,1583222400"; d="scan'208";a="349628061" Received: from kcaccard-mobl.amr.corp.intel.com (HELO kcaccard-mobl1.jf.intel.com) ([10.209.86.25]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2020 13:14:06 -0700 Message-ID: <9fdea0bc0008eccd6dfcad496b37930cf5bd364a.camel@linux.intel.com> Subject: Re: [PATCH v2 9/9] module: Reorder functions From: Kristen Carlson Accardi To: Kees Cook Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, "H. Peter Anvin" , Jessica Yu , arjan@linux.intel.com, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, rick.p.edgecombe@intel.com, Ard Biesheuvel , Tony Luck Date: Tue, 09 Jun 2020 13:14:04 -0700 In-Reply-To: <202005211415.5A1ECC638@keescook> References: <20200521165641.15940-1-kristen@linux.intel.com> <20200521165641.15940-10-kristen@linux.intel.com> <202005211415.5A1ECC638@keescook> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.30.5 (3.30.5-1.fc29) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2020-05-21 at 14:33 -0700, Kees Cook wrote: > Oh! And I am reminded suddenly about CONFIG_FG_KASLR needing to > interact > correctly with CONFIG_LD_DEAD_CODE_DATA_ELIMINATION in that we do NOT > want the sections to be collapsed at link time: sorry - I'm a little confused and was wondering if you could clarify something. Does this mean you expect CONFIG_FG_KASLR=y and CONFIG_LD_DEAD_CODE_DATA_ELIMINATION=y to be a valid config? I am not familiar with the option, but it seems like you are saying that it requires sections to be collapsed, in which case both of these options as yes would not be allowed? Should I actively prevent this in the Kconfig? Thanks. Kristen > > #ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION > #define TEXT_MAIN .text .text.[0-9a-zA-Z_]* > > (I think I had fixed this in some earlier version?) > > I think you want this (untested): > > > diff --git a/Makefile b/Makefile > index 04f5662ae61a..a0d9acd3b900 100644 > --- a/Makefile > +++ b/Makefile > @@ -853,8 +853,11 @@ ifdef CONFIG_DEBUG_SECTION_MISMATCH > KBUILD_CFLAGS += $(call cc-option, -fno-inline-functions-called- > once) > endif > > +ifneq ($(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION)$(CONFIG_FG_KASLR),) > +KBUILD_CFLAGS_KERNEL += -ffunction-sections > +endif > ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION > -KBUILD_CFLAGS_KERNEL += -ffunction-sections -fdata-sections > +KBUILD_CFLAGS_KERNEL += -fdata-sections > LDFLAGS_vmlinux += --gc-sections > endif > > diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm- > generic/vmlinux.lds.h > index 71e387a5fe90..5f5c692751dd 100644 > --- a/include/asm-generic/vmlinux.lds.h > +++ b/include/asm-generic/vmlinux.lds.h > @@ -93,20 +93,31 @@ > * sections to be brought in with rodata. > */ > #ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION > -#define TEXT_MAIN .text .text.[0-9a-zA-Z_]* > #define DATA_MAIN .data .data.[0-9a-zA-Z_]* .data..LPBX* > #define SDATA_MAIN .sdata .sdata.[0-9a-zA-Z_]* > #define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]* > #define BSS_MAIN .bss .bss.[0-9a-zA-Z_]* > #define SBSS_MAIN .sbss .sbss.[0-9a-zA-Z_]* > #else > -#define TEXT_MAIN .text > #define DATA_MAIN .data > #define SDATA_MAIN .sdata > #define RODATA_MAIN .rodata > #define BSS_MAIN .bss > #define SBSS_MAIN .sbss > #endif > +/* > + * Both LD_DEAD_CODE_DATA_ELIMINATION and CONFIG_FG_KASLR options > enable > + * -ffunction-sections, which produces separately named .text > sections. In > + * the case of CONFIG_FG_KASLR, they need to stay distinct so they > can be > + * separately randomized. Without CONFIG_FG_KASLR, the separate > .text > + * sections can be collected back into a common section, which makes > the > + * resulting image slightly smaller. > + */ > +#if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) && > !defined(CONFIG_FG_KASLR) > +#define TEXT_MAIN .text .text.[0-9a-zA-Z_]* > +#else > +#define TEXT_MAIN .text > +#endif