From patchwork Mon Jun 22 19:31:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11618833 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 53FDB912 for ; Mon, 22 Jun 2020 19:32:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 186CC20776 for ; Mon, 22 Jun 2020 19:32:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="BKy23l2w" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 186CC20776 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 E19F66B002F; Mon, 22 Jun 2020 15:31:56 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DC9016B0030; Mon, 22 Jun 2020 15:31:56 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C6BDF6B0032; Mon, 22 Jun 2020 15:31:56 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0124.hostedemail.com [216.40.44.124]) by kanga.kvack.org (Postfix) with ESMTP id 8A12D6B0030 for ; Mon, 22 Jun 2020 15:31:56 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 5873B1A2951 for ; Mon, 22 Jun 2020 19:31:56 +0000 (UTC) X-FDA: 76957843032.24.van67_0f013d126e35 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin24.hostedemail.com (Postfix) with ESMTP id 3E0C71A295A for ; Mon, 22 Jun 2020 19:31:56 +0000 (UTC) X-Spam-Summary: 2,0,0,49e78ed4c0d86ec8,d41d8cd98f00b204,keescook@chromium.org,,RULES_HIT:41:355:379:541:800:960:968:973:981:988:989:1260:1311:1314:1345:1359:1431:1437:1515:1535:1542:1711:1730:1747:1777:1792:2198:2199:2393:2559:2562:2731:3138:3139:3140:3141:3142:3353:3865:3866:3867:3870:4117:4250:4605:5007:6261:6653:6742:10004:11026:11473:11658:11914:12043:12114:12296:12297:12438:12517:12519:12555:12895:13894:14181:14394:14721:14877:21080:21444:21451:21627:21740:30054,0,RBL:209.85.215.195:@chromium.org:.lbl8.mailshell.net-66.100.201.201 62.2.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: van67_0f013d126e35 X-Filterd-Recvd-Size: 6145 Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by imf39.hostedemail.com (Postfix) with ESMTP for ; Mon, 22 Jun 2020 19:31:55 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id e9so8654194pgo.9 for ; Mon, 22 Jun 2020 12:31:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zcPQ3teAeONtZCSjASMvWQH+0FGked91D84DWb3cnhA=; b=BKy23l2w1m43ZpBXQM2fDRryt6KkrHZIrILWSDueLTLg7JkO/xXIBdrpxBtpXqG8Eo C+whcf+rw091oqysj+R7yNmqCI48ZtM7rhgZGnobI7SE5xNIel15JCPoNXr8RLA/8gKA FUXw0i2C4M8kbA9Vh9+15Qvp6mVOpj0mucLag= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zcPQ3teAeONtZCSjASMvWQH+0FGked91D84DWb3cnhA=; b=mFElwufXc6FwPQi0vjygTqMYHlM7og1h+o1krfoMbN+nSQa00w0ma/vh2A9QADwP4P IOIPpJqFm2+1qM1BnVHmK3Y8j95gWm6yCM1zugYedusEo/bqzXcF6vYJMLtvCmUaC5bj hvYq2NTb9UY9HJEt3lt5VSeeEhMUpFgCV9sCfY1OJ65HihvTcISoi1wUUs1lV6p9mIZn 5S/EZ/d9MEs5AhF9nEXu/cLilN6K3TaVqE11E9+0vGKRc5g4ksk3knMhw+MsgFs9drAt bWOqFEzhHSHvHGouC69tFjytLfaMasos+ABd4QRXjqEPTJ0mIA3kHtrJ4cz4epQBd472 07WQ== X-Gm-Message-State: AOAM532SkD9pVvCwwWdY2h9/iZ2qUOZ1B+azrrwWBWUYl6WwaoINszOW laVaf77o5vFgBHOrxE+llpztBg== X-Google-Smtp-Source: ABdhPJwITrbj7E83VXsf9fWrxu//1aHMGodlvPkjapka8zNgM+eZ+A/1KAwdust7T+yhFUZyNvTBXw== X-Received: by 2002:a63:3f42:: with SMTP id m63mr14501829pga.310.1592854314990; Mon, 22 Jun 2020 12:31:54 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id n189sm14916252pfn.108.2020.06.22.12.31.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 12:31:54 -0700 (PDT) From: Kees Cook To: Thomas Gleixner Cc: Kees Cook , Elena Reshetova , x86@kernel.org, Andy Lutomirski , Peter Zijlstra , Catalin Marinas , Will Deacon , Mark Rutland , Alexander Potapenko , Alexander Popov , Ard Biesheuvel , Jann Horn , kernel-hardening@lists.openwall.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 5/5] arm64: entry: Enable random_kstack_offset support Date: Mon, 22 Jun 2020 12:31:46 -0700 Message-Id: <20200622193146.2985288-6-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200622193146.2985288-1-keescook@chromium.org> References: <20200622193146.2985288-1-keescook@chromium.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 3E0C71A295A X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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: Allow for a randomized stack offset on a per-syscall basis, with roughly 5 bits of entropy. In order to avoid unconditional stack canaries on syscall entry, also downgrade from -fstack-protector-strong to -fstack-protector to avoid triggering checks due to alloca(). Examining the resulting syscall.o, sees no changes in canary coverage (none before, none now). Signed-off-by: Kees Cook --- arch/arm64/Kconfig | 1 + arch/arm64/kernel/Makefile | 5 +++++ arch/arm64/kernel/syscall.c | 10 ++++++++++ 3 files changed, 16 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index a4a094bedcb2..2902e5316e1a 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -135,6 +135,7 @@ config ARM64 select HAVE_ARCH_MMAP_RND_BITS select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT select HAVE_ARCH_PREL32_RELOCATIONS + select HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET select HAVE_ARCH_SECCOMP_FILTER select HAVE_ARCH_STACKLEAK select HAVE_ARCH_THREAD_STRUCT_WHITELIST diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 151f28521f1e..39fc23d3770b 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -11,6 +11,11 @@ CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_insn.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_return_address.o = $(CC_FLAGS_FTRACE) +# Downgrade to -fstack-protector to avoid triggering unneeded stack canary +# checks due to randomize_kstack_offset. +CFLAGS_REMOVE_syscall.o += -fstack-protector-strong +CFLAGS_syscall.o += $(subst -fstack-protector-strong,-fstack-protector,$(filter -fstack-protector-strong,$(KBUILD_CFLAGS))) + # Object file lists. obj-y := debug-monitors.o entry.o irq.o fpsimd.o \ entry-common.o entry-fpsimd.o process.o ptrace.o \ diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c index 5f5b868292f5..00d3c84db9cd 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -42,6 +43,8 @@ static void invoke_syscall(struct pt_regs *regs, unsigned int scno, { long ret; + add_random_kstack_offset(); + if (scno < sc_nr) { syscall_fn_t syscall_fn; syscall_fn = syscall_table[array_index_nospec(scno, sc_nr)]; @@ -51,6 +54,13 @@ static void invoke_syscall(struct pt_regs *regs, unsigned int scno, } regs->regs[0] = ret; + + /* + * Since the compiler chooses a 4 bit alignment for the stack, + * let's save one additional bit (9 total), which gets us up + * near 5 bits of entropy. + */ + choose_random_kstack_offset(get_random_int() & 0x1FF); } static inline bool has_syscall_work(unsigned long flags)