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: 11618857 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 4F1C0912 for ; Mon, 22 Jun 2020 19:34:48 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 27DEC20706 for ; Mon, 22 Jun 2020 19:34:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="1SbbOwCG"; 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 27DEC20706 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=Rt+nZavF05qAU4/0ZERc6VlMwigu9c6aUeGVLtKx8WM=; b=1SbbOwCGCOzyelDYdDEKmRbGiD YnlAVXnjQed08tbGR/Prs2uvX3r4DFz9/hkEDjwIZbp1UB6U+UFoFLJ7wQxoQ0BBjN0uviqdc1Tc8 /q/NL1ONvUxppXI/zTtCTGPpXNao4s11D9rKyAGGEeHZJC2KAoyoK0AOeeKRHm7Psi46j15Q04yxY RI+7lXLaVeh1GsR9pvrxw18HizVYASCKLj7HTPGG/27qfDXNBcvBMC5EMW53B/HFD5j6FPUGfhTOj JC/ttTSqzjIxbieuv6EMF4WJcEpJup2tSzlAmtjy/BbUki2X45toubXrm81f4dSpZT9C/SboF4CjO GVw2WWoA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jnSBe-0002JW-Ds; Mon, 22 Jun 2020 19:32:58 +0000 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jnSBb-0002Hu-Pe for linux-arm-kernel@lists.infradead.org; Mon, 22 Jun 2020 19:32:56 +0000 Received: by mail-pj1-x1044.google.com with SMTP id ne5so313193pjb.5 for ; Mon, 22 Jun 2020 12:32: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: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=cb0qzN/ffHdRO0SkshGX/VfG181xqdCY/uYXSFQCBajabfW3BkH+Z18iiDtxEWhbhi 4dvjr2z79cVi+VgQCpfUzWgPjOhAlxxGvyJJx3VOBich75zXxLYe70/jTV7Z+jOtdQC6 hH0ssoGi7rqtOaN3emV63dS35WKa1k8d+vGvpgLw2ODiFZgncLUtEkYM880rtKKYYW8F mE4n8MMn1CGC/5+WIkoFeQGeLPBgWcs//+o7Zc/sozUY1VEBsaa+nBeIL6XihSqrtsDM QV/rUye5ifqzoJSbk9jNGik5Cpc1i329m4rrIPcFzOSuw5TcG3MTsi1OZntNtb7Rbgul eM3w== X-Gm-Message-State: AOAM530HQ5NhTXk1C7UeoiePhTTckE6isUv6lHePh+GbmMHgSlro7cKz 1T+K/Yh0OVYE86h/0bOs5nljBg== 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 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-Spam-Note: CRM114 invocation failed X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:1044 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Kees Cook , Jann Horn , Ard Biesheuvel , Peter Zijlstra , Catalin Marinas , x86@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , linux-arm-kernel@lists.infradead.org, Andy Lutomirski , kernel-hardening@lists.openwall.com, Will Deacon , Elena Reshetova , Alexander Popov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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