From patchwork Tue Mar 24 20:32:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11456449 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 37608913 for ; Tue, 24 Mar 2020 20:32:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 04D4520735 for ; Tue, 24 Mar 2020 20:32:51 +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="RCCVIU1g" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 04D4520735 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 AF6696B0032; Tue, 24 Mar 2020 16:32:43 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A590B6B0037; Tue, 24 Mar 2020 16:32:43 -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 80C1A6B0074; Tue, 24 Mar 2020 16:32:43 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0062.hostedemail.com [216.40.44.62]) by kanga.kvack.org (Postfix) with ESMTP id 6A47F6B0032 for ; Tue, 24 Mar 2020 16:32:43 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 21D7493696 for ; Tue, 24 Mar 2020 20:32:43 +0000 (UTC) X-FDA: 76631404206.03.cows51_8c0fc84e0c43e X-Spam-Summary: 50,0,0,760727f693b1efc2,d41d8cd98f00b204,keescook@chromium.org,,RULES_HIT:41:355:379:541:800:967:973:988:989:1260:1311:1314:1345:1437:1515:1535:1542:1711:1730:1747:1777:1792:1801:2198:2199:2393:2525:2560:2565:2682:2685:2740:2859:2897:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4184:4321:4605:5007:6117:6119:6261:6653:6742:7594:7875:8531:8603:9025:10004:11026:11232:11658:11914:12043:12291:12297:12438:12517:12519:12555:12679:12683:12740:12895:12903:12986:13894:14093:14096:14180:14181:14394:14721:14819:21060:21080:21121:21212:21444:21451:21611:21627:21740:21749:21788:21811:30045:30054:30055:30056,0,RBL:209.85.216.65:@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:24,LUA_SUMMARY:none X-HE-Tag: cows51_8c0fc84e0c43e X-Filterd-Recvd-Size: 5583 Received: from mail-pj1-f65.google.com (mail-pj1-f65.google.com [209.85.216.65]) by imf20.hostedemail.com (Postfix) with ESMTP for ; Tue, 24 Mar 2020 20:32:42 +0000 (UTC) Received: by mail-pj1-f65.google.com with SMTP id np9so39784pjb.4 for ; Tue, 24 Mar 2020 13:32:42 -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:mime-version :content-transfer-encoding; bh=xoyjnNIvkg+j3q/lUm3mcx/meHvti0L2223SyWgmbLU=; b=RCCVIU1gaUOt7SSOHOlSQWbk/wc0LVSYDRbdbvf7vkkrVHHkcc9wzrGS12OmXt54kW 5eS34P5AROrJupwvYUnpBnA0SF51uAHA8is60V059MtkeksLPUZ0uD4HhT+sfHelhrx7 6p/n0PbpIF84rBwBLyiZ4/znqUhgn9YMLGiuY= 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:mime-version :content-transfer-encoding; bh=xoyjnNIvkg+j3q/lUm3mcx/meHvti0L2223SyWgmbLU=; b=p0Nj/RYfA14w3BtvCr4mme2C0+efotoKRHJj3Z5bI4B8nZVq+AdOg/ciOyHXwqvd33 XpWpCUYlAoi/VUUEAPHFsoKL47jjzwhxgaCvkKcbDmwYW9fE88h5IpbT6wsfrFXh3Bdz nFCAyiemRUH41yDiq10+mEb96vAZ0ZYSNhCE3w5PJVOJ2jb02WbI3p62cKdVPnNnD2cT /f03OTwQiddcytia8aBbdtWrYAXUDgIflbeDZOdqzujoArvyS/BrygfHs6gpu1joTPca O3geJRkbHoITXGQbbcql+i6jw81h0Bd51myygGsZqQfPFKPwpjnSm46y66j+ICatXdLM 9AlA== X-Gm-Message-State: ANhLgQ3f5r/6jisnI+O46rNur18O0Z2oxCUr+VZ9qZVvLlKwXgJ/3zws 59UJRIK0V/w+Kl6p96L1F9R2uw== X-Google-Smtp-Source: ADFU+vsamiDb3vxQG8SScPpA98WBrw9+0joaymji73ZXk2ZhJ8zsjRiNpylOVu8a2158RuDNslMFDQ== X-Received: by 2002:a17:902:82c5:: with SMTP id u5mr12381681plz.254.1585081960653; Tue, 24 Mar 2020 13:32:40 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id t60sm3175485pjb.9.2020.03.24.13.32.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 13:32:37 -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 , Ard Biesheuvel , Jann Horn , "Perla, Enrico" , kernel-hardening@lists.openwall.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 0/5] Optionally randomize kernel stack offset each syscall Date: Tue, 24 Mar 2020 13:32:26 -0700 Message-Id: <20200324203231.64324-1-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 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: Hi, This is a continuation and refactoring of Elena's earlier effort to add kernel stack base offset randomization. In the time since the previous discussions, two attacks[1][2] were made public that depended on stack determinism, so we're no longer in the position of "this is a good idea but we have no examples of attacks". :) Earlier discussions also devolved into debates on entropy sources, which is mostly a red herring, given the already low entropy available due to stack size. Regardless, entropy can be changed/improved separately from this series as needed. Earlier discussions also got stuck debating how much syscall overhead was too much, but this is also a red herring since the feature itself needs to be selectable at boot with no cost for those that don't want it: this is solved here with static branches. So, here is an improved version, made as arch-agnostic as possible, with usage added for x86 and arm64. It also includes some small static branch clean ups. -Kees [1] https://a13xp0p0v.github.io/2020/02/15/CVE-2019-18683.html [2] https://repositorio-aberto.up.pt/bitstream/10216/125357/2/374717.pdf v2: - move to per-cpu rdtsc() saved on syscall exit - add static branches for zero-cost dynamic enabling - Kconfig just selects the default state of static branch - __builtin_alloca() produces ugly asm without -fno-stack-clash-protection - made arch agnostic rfc: https://lore.kernel.org/kernel-hardening/20190329081358.30497-1-elena.reshetova@intel.com/ Kees Cook (5): jump_label: Provide CONFIG-driven build state defaults init_on_alloc: Unpessimize default-on builds stack: Optionally randomize kernel stack offset each syscall x86/entry: Enable random_kstack_offset support arm64: entry: Enable random_kstack_offset support Makefile | 4 ++++ arch/Kconfig | 19 +++++++++++++++ arch/arm64/Kconfig | 1 + arch/arm64/kernel/syscall.c | 10 ++++++++ arch/x86/Kconfig | 1 + arch/x86/entry/common.c | 12 +++++++++- include/linux/jump_label.h | 19 +++++++++++++++ include/linux/mm.h | 18 +++++--------- include/linux/randomize_kstack.h | 40 ++++++++++++++++++++++++++++++++ init/main.c | 23 ++++++++++++++++++ mm/page_alloc.c | 12 ++-------- 11 files changed, 136 insertions(+), 23 deletions(-) create mode 100644 include/linux/randomize_kstack.h