From patchwork Wed May 24 15:57:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rik van Riel X-Patchwork-Id: 9746299 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BE6EA601C2 for ; Wed, 24 May 2017 15:58:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD9BA2899B for ; Wed, 24 May 2017 15:58:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A0DB5289B5; Wed, 24 May 2017 15:58:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 593262899B for ; Wed, 24 May 2017 15:58:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936245AbdEXP6F (ORCPT ); Wed, 24 May 2017 11:58:05 -0400 Received: from shelob.surriel.com ([96.67.55.147]:42251 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933797AbdEXP6D (ORCPT ); Wed, 24 May 2017 11:58:03 -0400 Received: from [2603:3005:d05:2b00:224:e8ff:fe38:995c] (helo=annuminas.surriel.com) by shelob.surriel.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1dDYfc-0004jx-R9; Wed, 24 May 2017 11:57:56 -0400 Received: from annuminas.surriel.com (localhost.localdomain [127.0.0.1]) by annuminas.surriel.com (8.15.2/8.14.5) with ESMTP id v4OFvuXx000740; Wed, 24 May 2017 11:57:56 -0400 Received: (from riel@localhost) by annuminas.surriel.com (8.15.2/8.15.2/Submit) id v4OFvuhV000739; Wed, 24 May 2017 11:57:56 -0400 X-Authentication-Warning: annuminas.surriel.com: riel set sender to riel@redhat.com using -f From: riel@redhat.com To: linux-kernel@vger.kernel.org Cc: danielmicay@gmail.com, tytso@mit.edu, keescook@chromium.org, hpa@zytor.com, luto@amacapital.net, mingo@kernel.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, linux-sh@vger.kernel.org, ysato@users.sourceforge.jp, kernel-hardening@lists.openwall.com Subject: [PATCH 3/5] x86: ascii armor the x86_64 boot init stack canary Date: Wed, 24 May 2017 11:57:49 -0400 Message-Id: <20170524155751.424-4-riel@redhat.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170524155751.424-1-riel@redhat.com> References: <20170524155751.424-1-riel@redhat.com> Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Rik van Riel Use the ascii-armor canary to prevent unterminated C string overflows from being able to successfully overwrite the canary, even if they somehow obtain the canary value. Inspired by execshield ascii-armor and Daniel Micay's linux-hardened tree. Signed-off-by: Rik van Riel Acked-by: Kees Cook --- arch/x86/include/asm/stackprotector.h | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h index dcbd9bcce714..8abedf1d650e 100644 --- a/arch/x86/include/asm/stackprotector.h +++ b/arch/x86/include/asm/stackprotector.h @@ -74,6 +74,7 @@ static __always_inline void boot_init_stack_canary(void) get_random_bytes(&canary, sizeof(canary)); tsc = rdtsc(); canary += tsc + (tsc << 32UL); + canary &= CANARY_MASK; current->stack_canary = canary; #ifdef CONFIG_X86_64