From patchwork Wed Feb 13 22:41:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Stoppa X-Patchwork-Id: 10811027 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AA47213A4 for ; Wed, 13 Feb 2019 22:42:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 989BC2E42F for ; Wed, 13 Feb 2019 22:42:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C7D92E5BF; Wed, 13 Feb 2019 22:42:48 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 10F822E42F for ; Wed, 13 Feb 2019 22:42:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2395256AbfBMWml (ORCPT ); Wed, 13 Feb 2019 17:42:41 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:52435 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2395246AbfBMWmk (ORCPT ); Wed, 13 Feb 2019 17:42:40 -0500 Received: by mail-wm1-f68.google.com with SMTP id m1so4334882wml.2; Wed, 13 Feb 2019 14:42:38 -0800 (PST) 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:reply-to :mime-version:content-transfer-encoding; bh=VlNzKepo585QEAzr1PoW4dWwLybStReaiWjN7bcxj8g=; b=JRNnYSF0B32te3X75TLvpnSw06mDUcTqBhWDZIT/xl3GaRwWSaGCTspIg/kzoSC5mm EIJLk/ST7d7VJB/A/IWScJOvMItHW/x4hC7d4xNYzOWLJuuLPOOwwg3cAigjgyRalxz0 o1FjUWhH36b3VnsTQ++e+vJ2oAPs+JVpSx4/39KXA29MMIZFPyRSW98b1oILTuP331/O 6JljWTMeGp9b2/dQxbgg2WwKybBQQakpaTC/1roZtKCBWoRs+heF3eDKU7dEpYaW/etM PiQoYjYnLQmSG1dj/GrKYTYg1WSRu4WfGeyapftL6GmbQnrsyURIUMqN/bQDDamRBWb5 WQ3g== 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:reply-to:mime-version:content-transfer-encoding; bh=VlNzKepo585QEAzr1PoW4dWwLybStReaiWjN7bcxj8g=; b=bLmLZDTS7LwIbw5g5hqQUyR+6td8dQkqOnka+eOUdDy3MWlzvV3uk2BaTBmZryhlNl CD7uIyFhUqPkoHkIEA1O6I3tuBt7k43m4bB0N1dWPM5wxzf+pxEr/mQOFFxj5q1KrYnc CdAqwH+T361fhBJOv5EJ6MAv5Ojggka9BTmouPFYxWoaVFVb+UbM61nYZ8l9WW1lo7NE Bm/ngidlSNvhLbFwC02Inpo2e+3areovc4Q08tbISy9AAuFhtWIcDFk2p3RYrr0c7/lR HY5N+i5ZKANNaqSla5VY/G22JzqoTd6fCUwmC5bWpk6WIb3RFBCnnP4sIYH0WDUN4RzD OrQg== X-Gm-Message-State: AHQUAubeUg3p4dTz6yvoLv/LeZ63fK2qtRyQs8F9X60PXnLr2G2R+vhc /TmIQ+gVU5HB+dV7kfkeRo8= X-Google-Smtp-Source: AHgI3IYWBD6OYKGNIHnWvKT1+X5xZVNe8vjVhHJodT1atGydjrsUyW8KD1kHYHBWgBaVu1rmWrjCdw== X-Received: by 2002:a7b:cb82:: with SMTP id m2mr289249wmi.135.1550097757879; Wed, 13 Feb 2019 14:42:37 -0800 (PST) Received: from localhost.localdomain ([91.75.74.250]) by smtp.gmail.com with ESMTPSA id f196sm780810wme.36.2019.02.13.14.42.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Feb 2019 14:42:37 -0800 (PST) From: Igor Stoppa X-Google-Original-From: Igor Stoppa Cc: Igor Stoppa , Andy Lutomirski , Nadav Amit , Matthew Wilcox , Peter Zijlstra , Kees Cook , Dave Hansen , Mimi Zohar , Thiago Jung Bauermann , Ahmed Soliman , linux-integrity@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v5 12/12] IMA: turn ima_policy_flags into __wr_after_init Date: Thu, 14 Feb 2019 00:41:41 +0200 Message-Id: X-Mailer: git-send-email 2.19.1 In-Reply-To: References: Reply-To: Igor Stoppa MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The policy flags could be targeted by an attacker aiming at disabling IMA, so that there would be no trace of a file system modification in the measurement list. Since the flags can be altered at runtime, it is not possible to make them become fully read-only, for example with __ro_after_init. __wr_after_init can still provide some protection, at least against simple memory overwrite attacks Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: Thiago Jung Bauermann CC: Ahmed Soliman CC: linux-integrity@vger.kernel.org CC: kernel-hardening@lists.openwall.com CC: linux-mm@kvack.org CC: linux-kernel@vger.kernel.org --- security/integrity/ima/ima.h | 3 ++- security/integrity/ima/ima_policy.c | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index cc12f3449a72..297c25f5122e 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "../integrity.h" @@ -50,7 +51,7 @@ enum tpm_pcrs { TPM_PCR0 = 0, TPM_PCR8 = 8 }; #define IMA_TEMPLATE_IMA_FMT "d|n" /* current content of the policy */ -extern int ima_policy_flag; +extern int ima_policy_flag __wr_after_init; /* set during initialization */ extern int ima_hash_algo; diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index 8bc8a1c8cb3f..d49c545b9cfb 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -48,7 +48,7 @@ #define INVALID_PCR(a) (((a) < 0) || \ (a) >= (FIELD_SIZEOF(struct integrity_iint_cache, measured_pcrs) * 8)) -int ima_policy_flag; +int ima_policy_flag __wr_after_init; static int temp_ima_appraise; static int build_ima_appraise __ro_after_init; @@ -460,12 +460,13 @@ void ima_update_policy_flag(void) list_for_each_entry(entry, ima_rules, list) { if (entry->action & IMA_DO_MASK) - ima_policy_flag |= entry->action; + wr_assign(ima_policy_flag, + ima_policy_flag | entry->action); } ima_appraise |= (build_ima_appraise | temp_ima_appraise); if (!ima_appraise) - ima_policy_flag &= ~IMA_APPRAISE; + wr_assign(ima_policy_flag, ima_policy_flag & ~IMA_APPRAISE); } static int ima_appraise_flag(enum ima_hooks func) @@ -651,7 +652,7 @@ void ima_update_policy(void) list_splice_tail_init_rcu(&ima_temp_rules, policy, synchronize_rcu); if (ima_rules != policy) { - ima_policy_flag = 0; + wr_assign(ima_policy_flag, 0); ima_rules = policy; /*