From patchwork Thu Apr 6 21:18:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9668443 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 161D9602B3 for ; Thu, 6 Apr 2017 21:19:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4797F285E8 for ; Thu, 6 Apr 2017 21:19:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 372D4285E4; Thu, 6 Apr 2017 21:19:29 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id AE007285E4 for ; Thu, 6 Apr 2017 21:19:27 +0000 (UTC) Received: (qmail 28669 invoked by uid 550); 6 Apr 2017 21:19:18 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 28577 invoked from network); 6 Apr 2017 21:19:15 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5ylx+0iByR+j+ijVHMsGe5z5a7mf62tsEoObK0ZuGb0=; b=m/5WfYKaFBv8HyDyO6GenlPzt6qa7GkJEurTqr+mNpdupNKwcSKk+l9sQiHLTH9lG3 rWf0xA+IWxB+QXwb502eFfNhczRqh179/YwzdT9pGd56Arr8RPpgNoqITq7w7MlT5zzP EMqxUHCXmOnH3GPdV7icqWy7lksyOtOp7RYCM= 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:in-reply-to :references; bh=5ylx+0iByR+j+ijVHMsGe5z5a7mf62tsEoObK0ZuGb0=; b=e8hy73Np+gnub84IRk9g9Cz46i0yf0kIKDFsN44ulHO8Xztc4OMOJfbq/jQOPy8hGx weER+qytWsaC7IqahwYFEQqLsn9vY4PDxFYYpQEPgxj+1CI8Tv5oCoakw4p29gEiFPeT nKg/UiU13scHkGhJvjNVP5YVNnyPZsXAg4QVXEC+MooN5yNVowlifsI8iERhFtmW28/M vZK8nFh8lLri2SGNPYFPmtSlJZh0uTnrh/IHcvUbR8rHV6/EEeZ3+zRvrGE9tXufoI9i /DHM7xcnsphDqhJH2g3FxwbCn2ARMxkCqbabjjyq1LD740KQsnKa7/AaiqGQSso1JhRv y3lQ== X-Gm-Message-State: AFeK/H259/xuK9b8AFpHhYTqHFB20zcHVAbYrkfvEALbZsjIXLHX5H50pwvltsDs4VWemwTB X-Received: by 10.99.103.193 with SMTP id b184mr17567395pgc.35.1491513543632; Thu, 06 Apr 2017 14:19:03 -0700 (PDT) From: Kees Cook To: kernel-hardening@lists.openwall.com Cc: Kees Cook , Michael Leibowitz Date: Thu, 6 Apr 2017 14:18:18 -0700 Message-Id: <1491513513-84351-4-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491513513-84351-1-git-send-email-keescook@chromium.org> References: <1491513513-84351-1-git-send-email-keescook@chromium.org> Subject: [kernel-hardening] [PATCH 03/18] randstruct: Set designated_init attribute X-Virus-Scanned: ClamAV using ClamSMTP Since randomized structures need designated initializers, make sure the designated_init attribute is set for GCC 5.1 and later's -Werror=designated-init. Since this marking is needed for both manually and automatically identified structures, have the plugin perform the marking when active, otherwise fall back to just the manually marked structures. Signed-off-by: Kees Cook --- include/linux/compiler.h | 2 +- scripts/gcc-plugins/randomize_layout_plugin.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 40e584448605..105410d776a6 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -449,7 +449,7 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s #endif #ifndef __randomize_layout -# define __randomize_layout +# define __randomize_layout __designated_init #endif #ifndef __no_randomize_layout diff --git a/scripts/gcc-plugins/randomize_layout_plugin.c b/scripts/gcc-plugins/randomize_layout_plugin.c index eb8ac6cc315e..6e5dccc4f221 100644 --- a/scripts/gcc-plugins/randomize_layout_plugin.c +++ b/scripts/gcc-plugins/randomize_layout_plugin.c @@ -377,6 +377,7 @@ static int relayout_struct(tree type) TYPE_FIELDS(variant) = list; TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant)); TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant)); + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("designated_init"), NULL_TREE, TYPE_ATTRIBUTES(variant)); if (has_flexarray) TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("has_flexarray"), NULL_TREE, TYPE_ATTRIBUTES(type)); }