Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp45314pxh; Thu, 7 Apr 2022 13:30:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCulG7naUVEbK3/MLIEgkYOk/A5MnhMIQ0/FDeZQ6il4YZLYp79ud190RK1cTaYQmtOgyr X-Received: by 2002:a17:902:c948:b0:156:c07d:8222 with SMTP id i8-20020a170902c94800b00156c07d8222mr15870625pla.30.1649363435538; Thu, 07 Apr 2022 13:30:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649363435; cv=none; d=google.com; s=arc-20160816; b=elgh9ktvRW5OZBWC+5s4SqcYXQr/03QBmptTN96ZecKgzAR/+YJKKXJMg8GEDk5RyQ uox+oNo7YZAaLRBh1huzN5JiFaGKXiIXU6ONxhsDlFiYExcrco0It2BiFm9/OTdka95b oa30Ak2vEd2hSkABkJtns8mKOSh8HtCJwzT70nT2Dxypi7OHIC8ffb2J1srVTx01fMiZ bpYvksqK/1Nywha9YZlTdqeXOxlPj6fy+AgWhzaR2ekVjugbKDJkBLMRDOwsbct0xuks cFBCm2lByUUlrv6s6FnNsQOz/fF5CgiveOQPEWpaatIatRFH4FgASO8MM085qK4+iVQx Ew1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=qW2G6QJQPB0zAi9jxpZzn0oRvztQZG9cLDkwD68iVl0=; b=IzBSPIZ4z6eaqrNPN7KaATycN0gv+txEJi5ET0BXTCLuMZ2Wr7hvoo82Rpv7Iw0mWA Iz8F6hnV9VOWp+PrzvqI7agycJjw0cl3WtF8uXJhD4JP9pn7sG8MhvuzwjIgrqNQzBJh MBN+Cq9gJJ6Gf4zucOtQD+mMOnnOofQsX9K7vFuTB0JKckwXPygt2W+58z2zlT5POCjG cMXFX8cxTv05AcMqj2VTThXi9NTekEmHJH4PGIjl1C0xD4KAL8iJhyAP4hU2Q8ZJjV3r PFWJTdECfWHaISWTfVpGvJ/wlagXGt/qEt9hd8YuPcwRshmCszIdC72dxdBbfXfVTD9/ V0Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=oR4xdvGw; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id s203-20020a632cd4000000b003816043ee33si19511271pgs.40.2022.04.07.13.30.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 13:30:35 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=oR4xdvGw; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2FBE437EA8A; Thu, 7 Apr 2022 12:44:35 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346700AbiDGSBq (ORCPT + 99 others); Thu, 7 Apr 2022 14:01:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346690AbiDGSBo (ORCPT ); Thu, 7 Apr 2022 14:01:44 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FC7D45ADB for ; Thu, 7 Apr 2022 10:59:44 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-2d2d45c0df7so55210767b3.1 for ; Thu, 07 Apr 2022 10:59:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=qW2G6QJQPB0zAi9jxpZzn0oRvztQZG9cLDkwD68iVl0=; b=oR4xdvGw3j0+k09kg7TSurTUKAgegEO6DhqberYZFqr9S5IhaQ8lB8xT7Vpmk2EZZ9 2IizFWMW4QaQnv7jzov4pCAZVMwzutdJ0MeACwMajyrRJeevFyNqtLMMMix8Q8v/F+g+ ax33VxknIU6WrU6+nSGQiv+1kiQNEPuOaT6S/R0xJEnzUmbbPHYRi4oZb3dPdQa51Yfw gMx04W5CPC1X2VzSFImUkLF3oyLpMyl5vy84AuTS4fBXefv1yRKnfFVFvyyqnjj5UMUp xuskqUkbHGFX+BCwYqNzRzQo5i96nXcT/C7eeDymFEgX14GsqxmLsYvWFtNUedTiDTGH 16VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=qW2G6QJQPB0zAi9jxpZzn0oRvztQZG9cLDkwD68iVl0=; b=sl+bnNnT/EcngUTBVu1Y+QXdvJMxstyc+BGnlyUSW1jK0IvFasgo4DLsZ1323fZ+j0 YlnCi8QJYSRdBM0JE44Y9KRQ2w1obQ7kWpRjI0q0EYYvrGzov2mqQ4nq6zaBwUspqxnq GIlHPkH1u0JxZmURx2hNvLQL3a/8uZJ+qPGHzDeZwmWLIq21kEbkuIFcSDKde/hVqlJ3 1bhrJ1EhmSpwZ1mbo/v8AOxu30Tx+FNCeTshy2rkt8khI+5rR6fBrrVUx8c0LAkDylbE PufMi3FmBclq2t4nVPHDOE1CbsTKQOMgCZyaPr62++Xys9dehjO7cKHXKICSplunepl1 yWzQ== X-Gm-Message-State: AOAM5316B6JIhvRItsZEV4lJTQqr563F2NBXcqLPzYO1Al+K4IBDMJXq a3veiQijuJhIpN9LU4vrpTHQ2Xwe X-Received: from fawn.svl.corp.google.com ([2620:15c:2cd:202:9502:92c1:77f9:4633]) (user=morbo job=sendgmr) by 2002:a81:52c4:0:b0:2eb:8d52:60d6 with SMTP id g187-20020a8152c4000000b002eb8d5260d6mr13102169ywb.394.1649354383373; Thu, 07 Apr 2022 10:59:43 -0700 (PDT) Date: Thu, 7 Apr 2022 10:59:30 -0700 Message-Id: <20220407175930.471870-1-morbo@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.1.1178.g4f1659d476-goog Subject: [PATCH] security: don't treat structure as an array of struct hlist_head From: Bill Wendling To: Kees Cook , James Morris , "Serge E. Hallyn" , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Cc: Bill Wendling Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The initialization of "security_hook_heads" is done by casting it to another structure pointer type, and treating it as an array of "struct hlist_head" objects. This requires an exception be made in "randstruct", because otherwise it will emit an error, reducing the effectiveness of the hardening technique. Instead of using a cast, initialize the individual struct hlist_head elements in security_hook_heads explicitly. This removes the need for the cast and randstruct exception. Signed-off-by: Bill Wendling Cc: Kees Cook --- scripts/gcc-plugins/randomize_layout_plugin.c | 2 -- security/security.c | 9 ++++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/scripts/gcc-plugins/randomize_layout_plugin.c b/scripts/gcc-plugins/randomize_layout_plugin.c index 334741a31d0a..c2ec81b68505 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 b7cf5cbfdc67..37a9eeb901e0 100644 --- a/security/security.c +++ b/security/security.c @@ -365,13 +365,12 @@ static void __init ordered_lsm_init(void) int __init early_security_init(void) { - int i; - struct hlist_head *list = (struct hlist_head *) &security_hook_heads; struct lsm_info *lsm; - for (i = 0; i < sizeof(security_hook_heads) / sizeof(struct hlist_head); - i++) - INIT_HLIST_HEAD(&list[i]); +#define LSM_HOOK(RET, DEFAULT, NAME, ...) \ + INIT_HLIST_HEAD(&security_hook_heads.NAME); +#include "linux/lsm_hook_defs.h" +#undef LSM_HOOK for (lsm = __start_early_lsm_info; lsm < __end_early_lsm_info; lsm++) { if (!lsm->enabled) -- 2.35.1.1178.g4f1659d476-goog