From patchwork Wed Feb 1 20:23:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9550637 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 CFB7A60236 for ; Wed, 1 Feb 2017 20:24:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C01082847C for ; Wed, 1 Feb 2017 20:24:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B4CB128480; Wed, 1 Feb 2017 20:24:11 +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 8F9842847C for ; Wed, 1 Feb 2017 20:24:10 +0000 (UTC) Received: (qmail 8171 invoked by uid 550); 1 Feb 2017 20:24:08 -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 8023 invoked from network); 1 Feb 2017 20:24:00 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=PYdta5l35hWZ6be2TYQmKT3+t3VGx6al1uVK+3dkG4w=; b=jmohHprzJE06xEXIxeKtTiylGpgR1zYU3+7GUXSiHTvE73xJYk5V6SRJySNCcmL1GM 1G5Hpv1Kd2EjQBVLbO98UQTf/tv5Svl4LEnS5y7oVh6rdSpyyi91yhVYnAqJBCSdCm1Q BH1MSaxVUCTFWHOvJB97AijrzsG0uONwEKJeU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=PYdta5l35hWZ6be2TYQmKT3+t3VGx6al1uVK+3dkG4w=; b=FjZuEz/RcI2UTiedz4NsVCZbwWROj+w3+c/SmStrfj4S7CtbKtE+XThCRLmOXQldbg Uq6cagrPSahWmqbuBYoL0b8zAubPBqoFD8FXEpOtjtMK6KwXR8Vs50NfvhuniniJGp+K umH4FrX79i/2xpI0pQXAqUZ9Hc1K+1fjj8o+cmyuogaj8sWsbSq0WQ09lLaWI/RERsfW eY2bP+IzULD4CCyWAf2mgJdsTChXtDekoVsxGAR93y754UbYs+PlTDYg2sVtEMoR91kc 2uRhnVM7FvXSveYDBOkCRiUKgpAhdRSXgR6mWZxf7iuqfu/Vm6HNHFHNYoqoaBIg1xZJ uSfw== X-Gm-Message-State: AIkVDXKk/8l0WWaTiY6KsJa37Gvmjl73/ECu4WnkFj0AevlltGswHRDX61395GWqJns8SZ3I X-Received: by 10.99.243.21 with SMTP id l21mr5988792pgh.37.1485980629213; Wed, 01 Feb 2017 12:23:49 -0800 (PST) Date: Wed, 1 Feb 2017 12:23:47 -0800 From: Kees Cook To: Brad Spengler Cc: Josh Triplett , PaX Team , Emese Revfy , kernel-hardening@lists.openwall.com Message-ID: <20170201202347.GA75273@beast> MIME-Version: 1.0 Content-Disposition: inline Subject: [kernel-hardening] [PATCH] randstruct: Use -Werror=designated-init X-Virus-Scanned: ClamAV using ClamSMTP GCC 5.1 and later supports -Werror=designated-init, which can be used with randstruct to locate places where designated initializers are missing. Suggested-by: Josh Triplett Signed-off-by: Kees Cook --- Makefile | 3 +++ include/linux/compiler-gcc.h | 2 ++ scripts/gcc-plugins/randomize_layout_plugin.c | 1 + 3 files changed, 6 insertions(+) diff --git a/Makefile b/Makefile index f21d750fa022..1f94aba409b5 100644 --- a/Makefile +++ b/Makefile @@ -781,6 +781,9 @@ KBUILD_CFLAGS += $(call cc-option,-Werror=date-time) # enforce correct pointer usage KBUILD_CFLAGS += $(call cc-option,-Werror=incompatible-pointer-types) +# Require designated initializers for all marked structures +KBUILD_CFLAGS += $(call cc-option,-Werror=designated-init) + # use the deterministic mode of AR if available KBUILD_ARFLAGS := $(call ar-option,D) diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index 3ae2773b0498..fc411495e534 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h @@ -197,6 +197,8 @@ #ifdef RANDSTRUCT_PLUGIN #define __randomize_layout __attribute__((randomize_layout)) #define __no_randomize_layout __attribute__((no_randomize_layout)) +#else +#define __randomize_layout __attribute__((designated_init)) #endif #ifdef CONSTIFY_PLUGIN diff --git a/scripts/gcc-plugins/randomize_layout_plugin.c b/scripts/gcc-plugins/randomize_layout_plugin.c index 1f62fabc1141..9e314e4d9162 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)); }