Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp867039pxa; Thu, 27 Aug 2020 18:58:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2WePSQ9jQULCJNi3mjbVMxTDDHZw6pEJXbhM+RhZ95fKLUOAWzIHzgOxyzc9Qo9wjrZl9 X-Received: by 2002:a17:906:a206:: with SMTP id r6mr23349952ejy.70.1598579921437; Thu, 27 Aug 2020 18:58:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598579921; cv=none; d=google.com; s=arc-20160816; b=dvcdH8HUX+8SBY8RIK4NT/aHeQXWkpCrIhfKoVdHsgR6lVZGsPdou6xlRMCvCuJYKQ EEyaU554o+sfkQ2cXpClwFDbJLkl9kqgBybpDP2c6q0kk75ry8OWwRhpL+FKL4SjKBBL d6lL9Pi18O07pGDGekrBRGbNmFUm+zpGIktDZHVRRBr5/3PSfN1J7ipxVv+obCQY5MHY nv82+q8frvh5zx0DurGWKHw90S0c/6UVBPf87XWMxE/IQQSA4VVNUeDK4qpiz2L3Z3KM lcg0dquFfpCW3VNzY4ZcGHghGQvqyWYLqJeidP+T+3j2zioUQ1/Z1mQf1JaLWfdSZsXa rFeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=/oNkgUW9zSIuVV9hzhJDu+lqIFChEKC0BuHbXmW5m3Y=; b=Tkg5IsxOmM3mppwtC5+tNSfihO+Rru8eVflpmMxpj166VGoAelNKRp2S7JcRDfQr0r FDcFpceQcjeS75YXiW6UZJpgLEshkkBuT7wuv/JjNbxGL8JlrDQw/UCQ0rtIn9seHNE2 RxE9l/IBGCaAkFLFKAqgDeX6yXCd1Lap9iMEbBxalf0TJ+Imv3uIckhCLkgPf6j5JnMY BDvkbcklWFSx1iM8qwv4BTYgZfnMXHuVC084itsoLqWZu3joyRyDVMwbm8HLM2wGAPzX tGmL4pzrJXwpU9AJNitUHL5rpBTNi/DCd07CA7KUQL0IhcpPxLi5q4su5R4FT5m/Xz7Z l99g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="Cyz/YHC3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f4si2520979ejr.532.2020.08.27.18.58.18; Thu, 27 Aug 2020 18:58:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="Cyz/YHC3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728401AbgH1B53 (ORCPT + 99 others); Thu, 27 Aug 2020 21:57:29 -0400 Received: from linux.microsoft.com ([13.77.154.182]:38500 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728353AbgH1B5V (ORCPT ); Thu, 27 Aug 2020 21:57:21 -0400 Received: from tusharsu-Ubuntu.lan (c-71-197-163-6.hsd1.wa.comcast.net [71.197.163.6]) by linux.microsoft.com (Postfix) with ESMTPSA id 5BEF120C27C5; Thu, 27 Aug 2020 18:57:20 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 5BEF120C27C5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1598579840; bh=/oNkgUW9zSIuVV9hzhJDu+lqIFChEKC0BuHbXmW5m3Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cyz/YHC3WltXaOC2W1Hu7dvdzMKlVlrik0OyrAKvc3bYjiBOWarXk/sMLKG5Rg302 fbDJaPYrLp1qHtc2FhixkEyPt5aRcJ9BDsKfLQZuW7svV2PjA1czuY27qzJ0eRdFwn TEcJ+5giT+ILXTcXHTRG3KaEqEnPdHzOp8Y6cqDM= From: Tushar Sugandhi To: zohar@linux.ibm.com, stephen.smalley.work@gmail.com, casey@schaufler-ca.com, agk@redhat.com, snitzer@redhat.com, gmazyland@gmail.com Cc: tyhicks@linux.microsoft.com, sashal@kernel.org, jmorris@namei.org, nramas@linux.microsoft.com, linux-integrity@vger.kernel.org, selinux@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, dm-devel@redhat.com Subject: [PATCH v3 6/6] IMA: validate supported kernel data sources before measurement Date: Thu, 27 Aug 2020 18:57:04 -0700 Message-Id: <20200828015704.6629-7-tusharsu@linux.microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200828015704.6629-1-tusharsu@linux.microsoft.com> References: <20200828015704.6629-1-tusharsu@linux.microsoft.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, IMA does not restrict random data sources from measuring their data using ima_measure_critical_data(). Any kernel data source can call the function, and it's data will get measured as long as the input event_data_source is part of the IMA policy - CRITICAL_DATA+critical_kernel_data_sources. This may result in IMA log getting bloated by random data sources. Supporting random data sources at run-time may also impact the reliability of the system. To ensure that only data from supported sources are measured, the kernel component needs to be added to a compile-time list of supported sources (an "allowed list of components") in ima.h. IMA then validates the input parameter - event_data_source passed to ima_measure_critical_data() against this allowed list at run-time. Provide an infrastructure for kernel data sources to be added to the supported data sources list at compile-time. Update ima_measure_critical_data() to validate, at run-time, that the data source is supported before measuring the data. Signed-off-by: Tushar Sugandhi --- security/integrity/ima/ima.h | 29 +++++++++++++++++++++++++++++ security/integrity/ima/ima_main.c | 3 +++ 2 files changed, 32 insertions(+) diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index 00b84052c8f1..ecb0a1e7378f 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -228,6 +228,35 @@ extern const char *const func_tokens[]; struct modsig; +#define __ima_supported_kernel_data_sources(source) \ + source(MIN_SOURCE, min_source) \ + source(MAX_SOURCE, max_source) + +#define __ima_enum_stringify(ENUM, str) (#str), + +enum ima_supported_kernel_data_sources { + __ima_supported_kernel_data_sources(__ima_hook_enumify) +}; + +static const char * const ima_supported_kernel_data_sources_str[] = { + __ima_supported_kernel_data_sources(__ima_enum_stringify) +}; + +static inline bool ima_kernel_data_source_is_supported(const char *source) +{ + int i; + + if (!source) + return false; + + for (i = MIN_SOURCE + 1; i < MAX_SOURCE; i++) { + if (!strcmp(ima_supported_kernel_data_sources_str[i], source)) + return true; + } + + return false; +} + #ifdef CONFIG_IMA_QUEUE_EARLY_BOOT_KEYS /* * To track keys that need to be measured. diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c index a889bf40cb7e..41be4d1d839e 100644 --- a/security/integrity/ima/ima_main.c +++ b/security/integrity/ima/ima_main.c @@ -888,6 +888,9 @@ int ima_measure_critical_data(const char *event_name, if (!event_name || !event_data_source || !buf || !buf_len) return -EINVAL; + if (!ima_kernel_data_source_is_supported(event_data_source)) + return -EPERM; + return process_buffer_measurement(NULL, buf, buf_len, event_name, CRITICAL_DATA, 0, event_data_source, measure_buf_hash); -- 2.17.1