From patchwork Sun Apr 1 10:18:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sargun Dhillon X-Patchwork-Id: 10319109 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 107F160375 for ; Sun, 1 Apr 2018 10:18:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F3A04205F7 for ; Sun, 1 Apr 2018 10:18:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E844A29175; Sun, 1 Apr 2018 10:18:30 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 78F89205F7 for ; Sun, 1 Apr 2018 10:18:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753458AbeDAKST (ORCPT ); Sun, 1 Apr 2018 06:18:19 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:39312 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753455AbeDAKSR (ORCPT ); Sun, 1 Apr 2018 06:18:17 -0400 Received: by mail-it0-f68.google.com with SMTP id e98-v6so15553830itd.4 for ; Sun, 01 Apr 2018 03:18:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sargun.me; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=k5wcYZQAvwGk3LQHDOV9cHaw1xSEjspIjHwoW4YNr5s=; b=FokBRIS2b1enrAVU7yuNy9eH9bccyDgGai4SHGCaGy834bHwDkoeqIYYstfhl+NbDl P5OGcAxl9pOErI49FyoqXa65EsOoOfb/6RU+Dean3gli//QaS56TpjWR98w32a6QTh42 ZgiRz/6S9JaYjVR6D3w7IgN/yL06+GpkHjLHc= 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=k5wcYZQAvwGk3LQHDOV9cHaw1xSEjspIjHwoW4YNr5s=; b=D7Q+n+f70FkxAfx1NWP5JUxj5HzjfJUoT6VnKRGiWuNVOaOD2hczccH4/QbVi/8loS BuuiSY59MCxpIhhlqXOJrZvqRQ28FVgKSBL/9q1svNKg5bU420n3OzThRNw+ADPeRpfK bgQ8cnMvAKP2ig6b5mQ+kzSYtKuRHcq409x8xHkICrzM5HehQmFgvzzpy6GQxmTBzjuQ wyoUKdOoTOt/wPwWZw9FEO2Op78vmoUo2/2I5++1DQtJHZqO3Un27k3N/I3fMung6ewv w+R0hanCDJ7I2Aiyga0uZRzMe48bPJuNZSOQiooUd34R0OXkfZG+0uStKdZDpecenLGw Z+dA== X-Gm-Message-State: ALQs6tDljv6LhkvoxYgF33F2kLz8M0tXwabd5DLnLRBSwOcKkne8i/Ax oCh/OgP2xqYB1RwaBGS9nqDX6J44gABWww== X-Google-Smtp-Source: AIpwx49yrU0RJBpyzrk0dbRCxTuX9gJXPs44yvUQPuXPAZkCoshfUAFieY/qVFQCzzUsBFO+/F30zQ== X-Received: by 2002:a24:5f10:: with SMTP id r16-v6mr9263315itb.93.1522577896472; Sun, 01 Apr 2018 03:18:16 -0700 (PDT) Received: from ircssh-2.c.rugged-nimbus-611.internal (80.60.198.104.bc.googleusercontent.com. [104.198.60.80]) by smtp.gmail.com with ESMTPSA id h63sm6615517ioa.81.2018.04.01.03.18.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Apr 2018 03:18:16 -0700 (PDT) Date: Sun, 1 Apr 2018 10:18:14 +0000 From: Sargun Dhillon To: linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Cc: penguin-kernel@i-love.sakura.ne.jp, keescook@chromium.org, igor.stoppa@huawei.com, casey@schaufler-ca.com, jmorris@namei.org Subject: [PATCH 4/4] security: generated security hook initialization based on lsm_hook_types.h Message-ID: <113007a6b9333ec02a08301405db6a59b294f1d6.1522577650.git.sargun@sargun.me> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This replaces the old logic of casting the security hook heads struct to an array, and then traversing it in order to initialize it. Instead, it generates the code to set the security hook heads to null at start time. Signed-off-by: Sargun Dhillon --- scripts/gcc-plugins/randomize_layout_plugin.c | 2 -- security/security.c | 17 ++++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/scripts/gcc-plugins/randomize_layout_plugin.c b/scripts/gcc-plugins/randomize_layout_plugin.c index 6d5bbd31db7f..d94138999427 100644 --- a/scripts/gcc-plugins/randomize_layout_plugin.c +++ b/scripts/gcc-plugins/randomize_layout_plugin.c @@ -52,8 +52,6 @@ static const struct whitelist_entry whitelist[] = { { "net/unix/af_unix.c", "unix_skb_parms", "char" }, /* big_key payload.data struct splashing */ { "security/keys/big_key.c", "path", "void *" }, - /* walk struct security_hook_heads as an array of struct hlist_head */ - { "security/security.c", "hlist_head", "security_hook_heads" }, { } }; diff --git a/security/security.c b/security/security.c index dd246a38b3f0..c849cfa03b92 100644 --- a/security/security.c +++ b/security/security.c @@ -32,6 +32,9 @@ #define MAX_LSM_EVM_XATTR 2 +#define INIT_SEC_HEAD(_hook_name) \ + INIT_HLIST_HEAD(&security_hook_heads._hook_name) + /* Maximum number of letters for an LSM name string */ #define SECURITY_NAME_MAX 10 @@ -60,12 +63,16 @@ static void __init do_security_initcalls(void) */ int __init security_init(void) { - int i; - struct hlist_head *list = (struct hlist_head *) &security_hook_heads; + /* + * This generates an unrolled version of the security head + * initialization. + */ +#define INT_HOOK(_hook_name, ...) INIT_SEC_HEAD(_hook_name) +#define VOID_HOOK(_hook_name, ...) INIT_SEC_HEAD(_hook_name) +#include +#undef INT_HOOK +#undef VOID_HOOK - for (i = 0; i < sizeof(security_hook_heads) / sizeof(struct hlist_head); - i++) - INIT_HLIST_HEAD(&list[i]); pr_info("Security Framework initialized\n"); /*