Received: by 10.192.165.148 with SMTP id m20csp2541697imm; Sun, 22 Apr 2018 09:11:13 -0700 (PDT) X-Google-Smtp-Source: AIpwx48jGro2+iTFjjNd9bs4IR34hChU7Nf1CdpZr9MwAMcJoGfVNekmnqJIrC0GJ2rzS6DBON8v X-Received: by 2002:a17:902:9303:: with SMTP id bc3-v6mr17766989plb.18.1524413473261; Sun, 22 Apr 2018 09:11:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524413473; cv=none; d=google.com; s=arc-20160816; b=p0Bt2cYGaHOEHFFSpioxzj9h7vAyXXhMRAFYlQAzSAOobQH3sTf5caIHVuGBKc9hy0 W35x+v2C21zqHnH50qpbpsEzpdnzP1IdSZh6RQ+lm2HUo2R2zqqeLMFvE4cloYaSJGgg ZUI+zv+Ja8dd44L1xE+Yg6XFVhvY4/6vF1TgG3eKqZJIfVXYDuhIAOkLOayoUMnY0Dot ef4JoZuNUUgxyCBqrwyLFTcwIxdUPaTJNmvYAcJI4oqdLy7VAkbOXbmwo09sgtSoelxe qDtzY7AO1bc7BvpV0QaRkDpxWKz+QfhLHPpAmLWnRob3cSa9I6ONL0Xibe8Wle1xxDpG ySMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=yEX5yzA9soLTMCC+HbBFgiejyWWr8J1IAg68Uz8sw6k=; b=aws+mtMU8Lq+4V162IaNqMsfByNIzJesSGWtHQ5dSw3ePhd/FwXbd3kjIGnS0pZkH+ e5Cjm+166gRsP/0cqxH7xxnb9Jg/+ZgRgRfaEyvEAu8rrcun0V5+Qi3EkVSEAMoM907g xSLqDcYRZOP6ex19WdTvLreIs1iSwjb2PM0QE8BE95Szz+C87F8qftgpMFQnrg/1ZL93 QoOKQhDLuGq3s33aAWyehrZc8Sj4vZMlgnJakZuCGWz5h5PngJrH3cKK7kxSGM17k8i4 vY++soP+hL1zBtdDIcPfYRQDDi7WjbRvBci0j9hSP3eTHxt4OI6SpRZ1EE9otQknIE2y 1WGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a64si8140870pgc.265.2018.04.22.09.10.58; Sun, 22 Apr 2018 09:11:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753765AbeDVN42 (ORCPT + 99 others); Sun, 22 Apr 2018 09:56:28 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45132 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753722AbeDVN4Y (ORCPT ); Sun, 22 Apr 2018 09:56:24 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 4DFCEBF8; Sun, 22 Apr 2018 13:56:23 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kees Cook , Peter Zijlstra , Ingo Molnar , Andrew Morton , Linus Torvalds Subject: [PATCH 4.16 012/196] task_struct: only use anon struct under randstruct plugin Date: Sun, 22 Apr 2018 15:50:32 +0200 Message-Id: <20180422135104.805503660@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135104.278511750@linuxfoundation.org> References: <20180422135104.278511750@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kees Cook commit 2cfe0d3009418a132b93d78642a8059a38fe5944 upstream. The original intent for always adding the anonymous struct in task_struct was to make sure we had compiler coverage. However, this caused pathological padding of 40 bytes at the start of task_struct. Instead, move the anonymous struct to being only used when struct layout randomization is enabled. Link: http://lkml.kernel.org/r/20180327213609.GA2964@beast Fixes: 29e48ce87f1e ("task_struct: Allow randomized") Signed-off-by: Kees Cook Reported-by: Peter Zijlstra Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- include/linux/compiler-clang.h | 3 --- include/linux/compiler-gcc.h | 12 +++--------- 2 files changed, 3 insertions(+), 12 deletions(-) --- a/include/linux/compiler-clang.h +++ b/include/linux/compiler-clang.h @@ -17,9 +17,6 @@ */ #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__) -#define randomized_struct_fields_start struct { -#define randomized_struct_fields_end }; - /* all clang versions usable with the kernel support KASAN ABI version 5 */ #define KASAN_ABI_VERSION 5 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h @@ -242,6 +242,9 @@ #if defined(RANDSTRUCT_PLUGIN) && !defined(__CHECKER__) #define __randomize_layout __attribute__((randomize_layout)) #define __no_randomize_layout __attribute__((no_randomize_layout)) +/* This anon struct can add padding, so only enable it under randstruct. */ +#define randomized_struct_fields_start struct { +#define randomized_struct_fields_end } __randomize_layout; #endif #endif /* GCC_VERSION >= 40500 */ @@ -256,15 +259,6 @@ */ #define __visible __attribute__((externally_visible)) -/* - * RANDSTRUCT_PLUGIN wants to use an anonymous struct, but it is only - * possible since GCC 4.6. To provide as much build testing coverage - * as possible, this is used for all GCC 4.6+ builds, and not just on - * RANDSTRUCT_PLUGIN builds. - */ -#define randomized_struct_fields_start struct { -#define randomized_struct_fields_end } __randomize_layout; - #endif /* GCC_VERSION >= 40600 */