From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6172C35E15 for ; Tue, 25 Feb 2020 21:22:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9D8DD20714 for ; Tue, 25 Feb 2020 21:22:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="er2wAeec" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9D8DD20714 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4B80C6B0003; Tue, 25 Feb 2020 16:22:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4685E6B0005; Tue, 25 Feb 2020 16:22:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 37F106B0006; Tue, 25 Feb 2020 16:22:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0007.hostedemail.com [216.40.44.7]) by kanga.kvack.org (Postfix) with ESMTP id 216FA6B0003 for ; Tue, 25 Feb 2020 16:22:51 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id BC2E8181AC9CB for ; Tue, 25 Feb 2020 21:22:50 +0000 (UTC) X-FDA: 76529924100.22.town10_7011f21cd5121 X-HE-Tag: town10_7011f21cd5121 X-Filterd-Recvd-Size: 6814 Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by imf42.hostedemail.com (Postfix) with ESMTP for ; Tue, 25 Feb 2020 21:22:49 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id h8so164652pgs.9 for ; Tue, 25 Feb 2020 13:22:49 -0800 (PST) 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:in-reply-to; bh=2zye8CzKnlnL3hA+RUHlbvvqNNCO2c7gcM4lHhCQD7I=; b=er2wAeecxK4UnrRNkC9cYYNiionMSp5Smjcbl6UiT0KNH69ScSdC7Jsx08Dy0furLI jWCR/e8g60UHKVgZgkBWxWKRSwhcOEQym0+qXug/oVndKzvKxq60+XOxqdlr0IwaMYKC OiAkSi9GgJSOqn1fDGi9cbYAWXPsC7HlVh27E= 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:in-reply-to; bh=2zye8CzKnlnL3hA+RUHlbvvqNNCO2c7gcM4lHhCQD7I=; b=gPAA/vnKe1+20Hhxm4fHSU+xISV4pXKzKeXO1XRf+0z8ZU0NO69yCm7FJzYYFgEne5 dlUO2DhWEncQXvQQZD3HjiPVGfnuCajXiNptJ0yY5e7+DwALpkbg7Z3lrC5SmtzSyWZG mtZ58I7FUrdnTYj2IUtiPWXUWhbtUAQXdsngiaeKEUO0LFZpLe/qj6v+bITrpA0vjVQ9 6GkjlGi11vzNw2YlM1BBQ7b55ezZ4Gb1ZITh/k+fBYU2b9hDuFh0lQ2QuBOKh91SIba1 okOIVAORR+RyuZ84f8dNRYN4L5j0NL+Yo+M4b+E/ejZ459w1gc863s/bkFVm5dLjyusC PHug== X-Gm-Message-State: APjAAAW5YMcC+LmrsrRNkITqPQWCGo25IO49QvZx0DI0AKtxqic5dBf7 I+hYTKjlumuz+SzKLQtXACwxlA== X-Google-Smtp-Source: APXvYqxxA9M2zklRloHbo/iqZPq+qupQCqxsxip0cOp0qvCs8wbLa9ELHMTKt7NR8+CPB8YZDGuC8A== X-Received: by 2002:a63:e4d:: with SMTP id 13mr433732pgo.343.1582665769122; Tue, 25 Feb 2020 13:22:49 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id s7sm17525973pgp.44.2020.02.25.13.22.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 13:22:48 -0800 (PST) Date: Tue, 25 Feb 2020 13:22:47 -0800 From: Kees Cook To: Yu-cheng Yu Cc: x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue , Dave Martin , x86-patch-review@intel.com Subject: Re: [RFC PATCH v9 24/27] x86/cet/shstk: ELF header parsing for Shadow Stack Message-ID: <202002251321.6C21B71F@keescook> References: <20200205181935.3712-1-yu-cheng.yu@intel.com> <20200205181935.3712-25-yu-cheng.yu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200205181935.3712-25-yu-cheng.yu@intel.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Feb 05, 2020 at 10:19:32AM -0800, Yu-cheng Yu wrote: > Check an ELF file's .note.gnu.property, and setup Shadow Stack if the > application supports it. > > v9: > - Change cpu_feature_enabled() to static_cpu_has(). > > Signed-off-by: Yu-cheng Yu > --- > arch/x86/Kconfig | 2 ++ > arch/x86/include/asm/elf.h | 13 +++++++++++++ > arch/x86/kernel/process_64.c | 31 +++++++++++++++++++++++++++++++ > 3 files changed, 46 insertions(+) > > diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig > index 6c34b701c588..d1447380e02e 100644 > --- a/arch/x86/Kconfig > +++ b/arch/x86/Kconfig > @@ -1987,6 +1987,8 @@ config X86_INTEL_SHADOW_STACK_USER > select ARCH_USES_HIGH_VMA_FLAGS > select X86_INTEL_CET > select ARCH_HAS_SHSTK > + select ARCH_USE_GNU_PROPERTY > + select ARCH_BINFMT_ELF_STATE > ---help--- > Shadow Stack (SHSTK) provides protection against program > stack corruption. It is active when the kernel has this > diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h > index 69c0f892e310..fac79b621e0a 100644 > --- a/arch/x86/include/asm/elf.h > +++ b/arch/x86/include/asm/elf.h > @@ -367,6 +367,19 @@ extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm, > int uses_interp); > #define compat_arch_setup_additional_pages compat_arch_setup_additional_pages > > +#ifdef CONFIG_ARCH_BINFMT_ELF_STATE > +struct arch_elf_state { > + unsigned int gnu_property; > +}; > + > +#define INIT_ARCH_ELF_STATE { \ > + .gnu_property = 0, \ > +} > + > +#define arch_elf_pt_proc(ehdr, phdr, elf, interp, state) (0) > +#define arch_check_elf(ehdr, interp, interp_ehdr, state) (0) > +#endif > + > /* Do not change the values. See get_align_mask() */ > enum align_flags { > ALIGN_VA_32 = BIT(0), > diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c > index 506d66830d4d..99548cde0cc6 100644 > --- a/arch/x86/kernel/process_64.c > +++ b/arch/x86/kernel/process_64.c > @@ -732,3 +732,34 @@ unsigned long KSTK_ESP(struct task_struct *task) > { > return task_pt_regs(task)->sp; > } > + > +#ifdef CONFIG_ARCH_USE_GNU_PROPERTY > +int arch_parse_elf_property(u32 type, const void *data, size_t datasz, > + bool compat, struct arch_elf_state *state) > +{ > + if (type != GNU_PROPERTY_X86_FEATURE_1_AND) > + return 0; > + > + if (datasz != sizeof(unsigned int)) > + return -ENOEXEC; > + > + state->gnu_property = *(unsigned int *)data; > + return 0; > +} > + > +int arch_setup_elf_property(struct arch_elf_state *state) > +{ > + int r = 0; > + > + memset(¤t->thread.cet, 0, sizeof(struct cet_status)); > + > + if (static_cpu_has(X86_FEATURE_SHSTK)) { > + if (state->gnu_property & GNU_PROPERTY_X86_FEATURE_1_SHSTK) > + r = cet_setup_shstk(); > + if (r < 0) > + return r; This test is redundant; there's no loop. This can just fall through to the final return. -Kees > + } > + > + return r; > +} > +#endif > -- > 2.21.0 > -- Kees Cook