From patchwork Mon Jun 22 19:31:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11618829 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 EA91F14B7 for ; Mon, 22 Jun 2020 19:32:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AE12820776 for ; Mon, 22 Jun 2020 19:32:00 +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="DooZtDOK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AE12820776 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 C781E6B002B; Mon, 22 Jun 2020 15:31:55 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B83F26B002E; Mon, 22 Jun 2020 15:31:55 -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 897CD6B002C; Mon, 22 Jun 2020 15:31:55 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0243.hostedemail.com [216.40.44.243]) by kanga.kvack.org (Postfix) with ESMTP id 604B06B002B for ; Mon, 22 Jun 2020 15:31:55 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 210738248068 for ; Mon, 22 Jun 2020 19:31:55 +0000 (UTC) X-FDA: 76957842990.24.coast02_5400bd126e35 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin24.hostedemail.com (Postfix) with ESMTP id DD29D1A295E for ; Mon, 22 Jun 2020 19:31:54 +0000 (UTC) X-Spam-Summary: 50,0,0,faf5a36aa4aaaeef,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:2568:2628:2682:2685:2740:2859: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:4362:4605:5007:6117:6119:6261:6653:6742:7594:7875:8531:8603:9025:9040:9389:10004:11026:11658:11914:12043:12291:12297:12438:12517:12519:12555:12679:12683:12740:12895:12903:12986:13161:13180:13229:13845: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.68:@chromium.org:.lbl8.mailshell.net-62.2.0.100 66.100.201.201,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_SUMM ARY:none X-HE-Tag: coast02_5400bd126e35 X-Filterd-Recvd-Size: 5895 Received: from mail-pj1-f68.google.com (mail-pj1-f68.google.com [209.85.216.68]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Mon, 22 Jun 2020 19:31:54 +0000 (UTC) Received: by mail-pj1-f68.google.com with SMTP id u8so314345pje.4 for ; Mon, 22 Jun 2020 12:31:54 -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=dNG40zysheY5oB4//u6Wgw3XPF1EPVf4SWmTm1L7IBk=; b=DooZtDOKEbuL4Lmq0EjvgBqtOhkWAVzaD4OoBh35ywAVTh+8jjPlVrIL5pPZ1PCtVX +7Qt9x93Bf6jWHUSYtMRAfTERsAnE8XlcUxfZu12iJaw18sHA1rR1SQN279dsa6bQ3wr FyhdWobCP/rLa3NIoSLGX9JY/N9OLOfKVoKSc= 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=dNG40zysheY5oB4//u6Wgw3XPF1EPVf4SWmTm1L7IBk=; b=HtXKuW09uDSkZxWYr2yACu72d5AQ5rWaycyc8dc795D0gRUxKka2a8DZTPV6XpaqHx 25rQzHPidP7dKiGUkzbioihVanG98tUY7nLTfxeJzwX1JUd0cHZgO9A2wfGUlIvJ4q9h zZvzEXDQPBdIvV2rLLdRW7MhRSbZHjXdLklgLLCd6kU5fuSDCAfGhIO3xHZsXMFam36M jwoKVQDeQl9b50EvrSf4ejP5EqdbBv1SuRo2LdbgmorQwNj2wjmzlLRsEnfOqUEzYkaT VtTdhps18Yb+ho/0NO/uqVyh0/cnroa7X1TWPpbn/vNa1SSC2oQheWE3MA8pA7633NaB Tn+w== X-Gm-Message-State: AOAM532aqif2ElEZmNbFY/Zf3ODsLrAR9rrWV6NZmNiYufp/vvuf5Hr9 fi3kSUPrK5OOFOizvZmoUx3snw== X-Google-Smtp-Source: ABdhPJwzvg0AysINBE9mrBB80x8GFaUJiCmnxanMRMBRbZ6JfPpnLr9CRvHSZ2l6hQg9n7Rg0F4HWg== X-Received: by 2002:a17:90a:9f81:: with SMTP id o1mr19808289pjp.139.1592854313385; Mon, 22 Jun 2020 12:31:53 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id q129sm13899450pfc.60.2020.06.22.12.31.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 12:31:50 -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 0/5] Optionally randomize kernel stack offset each syscall Date: Mon, 22 Jun 2020 12:31:41 -0700 Message-Id: <20200622193146.2985288-1-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: DD29D1A295E X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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: v4: - rebase to v5.8-rc2 v3: https://lore.kernel.org/lkml/20200406231606.37619-1-keescook@chromium.org/ v2: https://lore.kernel.org/lkml/20200324203231.64324-1-keescook@chromium.org/ rfc: https://lore.kernel.org/kernel-hardening/20190329081358.30497-1-elena.reshetova@intel.com/ 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, and addresses some surprise performance issues due to the stack canary[3]. Note that for v5.8, this depends on this fix (due to how x86 changed its stack protector removal for syscall entry): https://lore.kernel.org/lkml/202006221201.3641ED037E@keescook/ Thanks! -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 [3] https://lore.kernel.org/lkml/202003281520.A9BFF461@keescook/ 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 | 23 ++++++++++++++++++ arch/arm64/Kconfig | 1 + arch/arm64/kernel/Makefile | 5 ++++ arch/arm64/kernel/syscall.c | 10 ++++++++ arch/x86/Kconfig | 1 + arch/x86/entry/common.c | 11 +++++++++ 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 ++-------- 12 files changed, 145 insertions(+), 22 deletions(-) create mode 100644 include/linux/randomize_kstack.h