Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2216250imu; Sat, 22 Dec 2018 15:38:28 -0800 (PST) X-Google-Smtp-Source: ALg8bN7z+JArZjNhSJro9tQY6fVHNIHwPozSMrVaI6d/2VGGXteFjAKSk/VGU8Yx2DduVQ3JaK6m X-Received: by 2002:a17:902:765:: with SMTP id 92mr7999477pli.242.1545521908740; Sat, 22 Dec 2018 15:38:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545521908; cv=none; d=google.com; s=arc-20160816; b=w2K0STdDGNA1wYYwlvwNdEd09ot38M/mLqhWqpVLwWWPDlDs6qwVHoj8ydzO7ueT8p iIDNi7loxdGldRGYZrrqc+tUWzOMNRsoudQ1femFo6qrURoScXy1fZxuLhrD0MjUhchR YtqX9/3YAs1gSTUPxADBnEXNv3eH6LMIh51r4w54DcTAP2fSWoGmErf0thJsbL8Q9uSh IuXSisFEEBfUWEy6crDksag66FcPH7GiJXwz3TV71Fa5lllXYcOfaiqPkzMykzUCfxqW K7cWsc/lC+Nx7KfqC9g+Lmv0oZed2NbQR7YwFBYrIaTKA2BLNX6POuGHMb8PyOmT7pgk 5tpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :reply-to:references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9kpmCY6dszhDuHojBIZmAzgP6TFY8woIDvUXpPQug1w=; b=efUjrAZULXePkFVKsRLjTiXGeMXocmH3Abv078BfnnI1EvrlIq9R/Ykf0binTtRLuV 6gP/jEJtkhE+wfydNhLsKMYlb0EtyW4Qrt2wWVIg7Qx/vE1UNgYhcVktkgEMF+FU81zN a58MPmxkEJz9wbbjS/o9iOfA8TY7FcEbLkrHxnVngtiujBjeQBUAFo/WPhe05XW2E5fN tLTpmnKxei4t1lyXDSsp4Bcc/TNWehER7OqB7I/HYQv9vGL30iV08cKIaSbYwFNlEt8t aMN015NqNnLXHUudoIGVIfuvX+1rYO9aG7nMXQwAvY5K0YBmfeBbkbCkLQf7gLPvmo+Z haYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=i1aWqsy0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 44si7563215plb.57.2018.12.22.15.38.13; Sat, 22 Dec 2018 15:38:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=i1aWqsy0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404427AbeLUSPN (ORCPT + 99 others); Fri, 21 Dec 2018 13:15:13 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:34100 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404397AbeLUSPK (ORCPT ); Fri, 21 Dec 2018 13:15:10 -0500 Received: by mail-lf1-f65.google.com with SMTP id p6so4554200lfc.1; Fri, 21 Dec 2018 10:15:08 -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=9kpmCY6dszhDuHojBIZmAzgP6TFY8woIDvUXpPQug1w=; b=i1aWqsy0VvtYOOA+H+FaFy454gTvRTd9toczqI+B2j3w8dJaT6MdrohN2Nucdkx2uT O7heRehVrBUK1v8nRNP7Qq9H8Hm1aZI05b3pvICKey+/lupkRDm0HDM02tGB+gdbYQ2H QkchLfTMTMrz8CoF5dWFSFNhGcidh1S2e9bKy8KBN+sBGQrfCN/Culgu41PU1KSjx4pC 1PwMUt1P5owoEyJQGQUJa2a1XdLa6n6vqGFNYWOMHkP/0R6R7QYRclERrymq615h3mVP zzjrHTxZh+NZNwUtU17p0X0jbZ0nxaYv7NnWwdHIx+LRUPOg8BzvteriVLu/n62OLVpl xZPw== 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=9kpmCY6dszhDuHojBIZmAzgP6TFY8woIDvUXpPQug1w=; b=am/NtbB1oxRQvJnRXWqyu5h7FQ1jOOm2LKBcFX1E6a8+cfgv3aPYA3GzxP1AKhDqVP ptCcdgtv1lmVLME2BGIC3G7OmJWhvkHNHHwhJtVPL1g502ZUEjddzQuxBfzuL3Xy+2Nr y+z7xdK/XKo2TaUM9+Kag3IFNTNQBE33Zff7cRbw1WemZ2tzoIHg+doce9zru9F8rxrv uXTl0wpgYYqAv0gSXTP8iIFihSwL0Nu1IplyV8rydIo47JXPZO7r9G/5tHmO2IaMw5Dp yE9od81dv+UTSR07ord06h73vShLpyM4ZKIa+z03jt/EJTfcA5CvT0TMgNVXDHtZXu7P 6ybQ== X-Gm-Message-State: AA+aEWZwjQFXcgRRzHBRxVK7BEWzA8LWu2PsU31nGemPuYwPmWGWLdP3 wUgB9kbRrVBNV55J3KeQN0E= X-Received: by 2002:a19:3b9c:: with SMTP id d28mr2119418lfl.30.1545416107450; Fri, 21 Dec 2018 10:15:07 -0800 (PST) Received: from localhost.localdomain (dmhwpt3bffxn8z3-j6k-4.rev.dnainternet.fi. [2001:14bb:51:a4c8:5c24:24d7:ca5f:e7d2]) by smtp.gmail.com with ESMTPSA id m63-v6sm5444564lje.81.2018.12.21.10.15.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Dec 2018 10:15:06 -0800 (PST) From: Igor Stoppa X-Google-Original-From: Igor Stoppa To: Andy Lutomirski , Matthew Wilcox , Peter Zijlstra , Dave Hansen , Mimi Zohar , Thiago Jung Bauermann Cc: igor.stoppa@huawei.com, Nadav Amit , Kees Cook , Ahmed Soliman , linux-integrity@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 11/12] IMA: turn ima_policy_flags into __wr_after_init Date: Fri, 21 Dec 2018 20:14:22 +0200 Message-Id: <20181221181423.20455-12-igor.stoppa@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181221181423.20455-1-igor.stoppa@huawei.com> References: <20181221181423.20455-1-igor.stoppa@huawei.com> Reply-To: Igor Stoppa MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 7489cb7de6dc..2004de818d92 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -47,7 +47,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; @@ -452,12 +452,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) @@ -574,7 +575,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; } ima_update_policy_flag(); -- 2.19.1