From patchwork Sun Feb 19 10:04:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hoeun Ryu X-Patchwork-Id: 9581525 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 9113C604A0 for ; Sun, 19 Feb 2017 10:05:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 83CCB2872C for ; Sun, 19 Feb 2017 10:05:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7895228734; Sun, 19 Feb 2017 10:05:39 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 A4BA72872C for ; Sun, 19 Feb 2017 10:05:38 +0000 (UTC) Received: (qmail 21633 invoked by uid 550); 19 Feb 2017 10:05:37 -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 21599 invoked from network); 19 Feb 2017 10:05:34 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=H9/a2Dxboo1pmq1t7beM7CglOYUnaeSHY+RlOxVB8vw=; b=mfxbtS8CUCSYA2pyYmMpnJH7LB6qxZMU2qApH8yECCQDOx6KM0glYBrAabhWZWshRN Q3HoRCHBZWzty1vRuJFfZtlLYhan8s0E0lH1aL2lItG7taQl5mb4qWCMmXCTSpUGstZq cat287WdQGIQYaaVzHh556XS/KeIkzeCaho1uQ8uiIuadoP+O/VVOSr4hwju739N4AiI 2LBGhf6dIvL10PNKkSrCLwBJoyvFrm0CNGNzNxQEus02t12VpzwwNbgLCaNFurtrkF5A dB1YKPNXW/poAwKhr+TyPHv5sbuMT6fbzLh6CmC/y/zHZLAAHK79PpPbBbu84Mo1+Wfz UPiA== 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=H9/a2Dxboo1pmq1t7beM7CglOYUnaeSHY+RlOxVB8vw=; b=FPEJpiD0Sc4IwZZSm+ekv4W/Nl0j2uTgdffhVsLGdQ8VfpkZpZDPxu+Lyqz5iLoIi6 lEi3RhEW2w/7xs/Dk5/Kzx9J7YVP3546422mzdr8MUA/COkx5DPrJpN9vaD1wjfV/CF6 SbCZRP1btVkn5Z623H7X7DOB2NsgFyqsDnOAcHh4ZKM5XjL3UfDDxlSDiyqBRCe5RGB4 dv76BBgij53TCL785C/nWXQ1llnr8c8ubAyoE5V1DrXf+Vp1yl0CUE2LlwoLbNn0KoGg 98uy0IXE5Okg3x0HQEI69s2FzgKmwLIktxNpxqhnLWvDUloGMtEpsRf1u0SPJh7TRFoW 9LPQ== X-Gm-Message-State: AMke39l9YR+YsifXHFfpofySGROTXJszKbcvZRLXrgyXHhO8pmVnvYpYBcr+hO22oXV4pA== X-Received: by 10.99.199.69 with SMTP id v5mr20781794pgg.90.1487498723035; Sun, 19 Feb 2017 02:05:23 -0800 (PST) From: Hoeun Ryu To: kernel-hardening@lists.openwall.com, linux-kernel@vger.kernel.org Cc: Hoeun Ryu , Paul Moore , Stephen Smalley , Eric Paris , James Morris , "Serge E. Hallyn" , selinux@tycho.nsa.gov, linux-security-module@vger.kernel.org Date: Sun, 19 Feb 2017 19:04:07 +0900 Message-Id: <1487498660-16600-4-git-send-email-hoeun.ryu@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487498660-16600-1-git-send-email-hoeun.ryu@gmail.com> References: <1487498660-16600-1-git-send-email-hoeun.ryu@gmail.com> Subject: [kernel-hardening] [RFC 4/7] selinux: mark __ro_mostly_after_init for selinux_hooks/selinux_nf_ops X-Virus-Scanned: ClamAV using ClamSMTP It would be good that selinux hooks objects are marked as `__ro_mostly_after_init`. They can not be simply marked as `__ro_after_init' because they should be writable during selinux_disable procedure. `__ro_mostly_after_init` section is temporarily read-write during selinux_disable procedure via set_ro_mostly_after_init_rw/ro pair. Now that they can be read-only except during the procedure. Signed-off-by: Hoeun Ryu --- security/selinux/hooks.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 9a8f12f..64fd799 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6106,7 +6106,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer) #endif -static struct security_hook_list selinux_hooks[] = { +static struct security_hook_list selinux_hooks[] __ro_mostly_after_init = { LSM_HOOK_INIT(binder_set_context_mgr, selinux_binder_set_context_mgr), LSM_HOOK_INIT(binder_transaction, selinux_binder_transaction), LSM_HOOK_INIT(binder_transfer_binder, selinux_binder_transfer_binder), @@ -6381,7 +6381,7 @@ security_initcall(selinux_init); #if defined(CONFIG_NETFILTER) -static struct nf_hook_ops selinux_nf_ops[] = { +static struct nf_hook_ops selinux_nf_ops[] __ro_mostly_after_init = { { .hook = selinux_ipv4_postroute, .pf = NFPROTO_IPV4, @@ -6477,13 +6477,17 @@ int selinux_disable(void) selinux_disabled = 1; selinux_enabled = 0; + set_ro_mostly_after_init_rw(); security_delete_hooks(selinux_hooks, ARRAY_SIZE(selinux_hooks)); + set_ro_mostly_after_init_ro(); /* Try to destroy the avc node cache */ avc_disable(); /* Unregister netfilter hooks. */ + set_ro_mostly_after_init_ro(); selinux_nf_ip_exit(); + set_ro_mostly_after_init_rw(); /* Unregister selinuxfs. */ exit_sel_fs();