From patchwork Fri May 3 22:25:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prakhar Srivastava X-Patchwork-Id: 10929387 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 30F76912 for ; Fri, 3 May 2019 22:25:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E772287DB for ; Fri, 3 May 2019 22:25:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F3D2287E5; Fri, 3 May 2019 22:25:57 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 6BCAC287DB for ; Fri, 3 May 2019 22:25:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726646AbfECWZb (ORCPT ); Fri, 3 May 2019 18:25:31 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:34731 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726042AbfECWZb (ORCPT ); Fri, 3 May 2019 18:25:31 -0400 Received: by mail-pf1-f194.google.com with SMTP id b3so3571440pfd.1; Fri, 03 May 2019 15:25:30 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=BaAl3T5YxfM/1JfpIAfuXV3CrS6GA7YYTHBIDImU8Hc=; b=knPPgJFejR41jK8dhVk9qE/92sGnk8eZjxSD9NN5rgRiP+FJi4piT4/0cLw/YAebF2 m2XYeD7n3E0+TXUH3WfT5DKvx19Zt6fe5nHpV6gSFTEuh7l+pb78CqlTFNxN8jbzTJO9 jiO+A0R5GqLF5mGkW66Yvb9Tj7JwytQI9IxJTA4pu/0uAxWDOcAMbQZcdKmOJiHW4LJW q1Fw+Pw7WpCunouucgT9aZ5bntBotUe1fwBKr55jCrOxcMnEv+C/v5X3V+0K26yD/YSl 7z0oEwD42xB2B24zoQewy7hZr+a39jz+lV2NxehPEZhdtZIQea76UH8dLb0dkkZQgSDj LOWw== 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:mime-version:content-transfer-encoding; bh=BaAl3T5YxfM/1JfpIAfuXV3CrS6GA7YYTHBIDImU8Hc=; b=KRbIEFIaiVjLajIDcFO7s/5QG+sf7teaadt2ak1QfBUO55KsxJSnQ/cnroGJVved9O bVux4ey0g6kMfHI8BOcOh+gQmMRSh91hfw43PbBGitA0F55SnjWvjOy1UDVf+0d2XinJ C2i/9inGwnF/g7dbAj7x5eZghgMz8sKVoqUNYbe/dssUe9wefN9T9hb8tCrhjMIA3jfG tSIFENk/UL2AyIs6W1UtcFtDo3c9EoULNRxDXsDB9Z9MVWrZn1vvKoPJKIriNnHYzafo GAmC7B8X+UXf/AthkUpkamqZJzvvshlDjkAcHwyruqYLb48DONekzl34dP/tLLIlFzjC LiEw== X-Gm-Message-State: APjAAAU8muaOCtDbyfxsrpTf6dErXD51oq2Io1oAnot06G7a5fZKbWET J7Sdp9U6FoyJlrzRF+NfanHSbarkjzI= X-Google-Smtp-Source: APXvYqwUTrc4HbPUugEtms1cvz9SLMSlkIWqH4NUyCDeW6d8TPNwjR3Y1kBce6jiyflIkAC2HInpzw== X-Received: by 2002:a65:654c:: with SMTP id a12mr13974588pgw.101.1556922329882; Fri, 03 May 2019 15:25:29 -0700 (PDT) Received: from prsriva-linux.corp.microsoft.com ([2001:4898:80e8:b:3170:1a6b:a13a:7ff]) by smtp.gmail.com with ESMTPSA id j22sm4314337pfi.139.2019.05.03.15.25.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 May 2019 15:25:28 -0700 (PDT) From: Prakhar Srivastava X-Google-Original-From: Prakhar Srivastava To: linux-integrity@vger.kernel.org, linux-secuirty-module@vger.kernel.org, linux-kernel@vger.kernel.org Cc: zohar@linux.ibm.com, ebiederm@xmission.com, vgoyal@redhat.com, nayna@linux.ibm.com, nramas@microsoft.com, prsriva@microsoft.com, Prakhar Srivastava Subject: [PATCH 1/5 v4] added a new ima policy func buffer_check, and ima hook to measure the buffer hash into ima Date: Fri, 3 May 2019 15:25:19 -0700 Message-Id: <20190503222523.6294-2-prsriva02@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190503222523.6294-1-prsriva02@gmail.com> References: <20190503222523.6294-1-prsriva02@gmail.com> MIME-Version: 1.0 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 From: Prakhar Srivastava This change adds a new ima policy func buffer_check, and ima hook to measure the buffer hash into ima log. Signed-off-by: Prakhar Srivastava --- Documentation/ABI/testing/ima_policy | 1 + include/linux/ima.h | 5 ++ security/integrity/ima/ima.h | 1 + security/integrity/ima/ima_api.c | 1 + security/integrity/ima/ima_main.c | 89 ++++++++++++++++++++++++++++ security/integrity/ima/ima_policy.c | 8 +++ 6 files changed, 105 insertions(+) diff --git a/Documentation/ABI/testing/ima_policy b/Documentation/ABI/testing/ima_policy index 74c6702de74e..12cfe3ff2dea 100644 --- a/Documentation/ABI/testing/ima_policy +++ b/Documentation/ABI/testing/ima_policy @@ -29,6 +29,7 @@ Description: base: func:= [BPRM_CHECK][MMAP_CHECK][CREDS_CHECK][FILE_CHECK][MODULE_CHECK] [FIRMWARE_CHECK] [KEXEC_KERNEL_CHECK] [KEXEC_INITRAMFS_CHECK] + [BUFFER_CHECK] mask:= [[^]MAY_READ] [[^]MAY_WRITE] [[^]MAY_APPEND] [[^]MAY_EXEC] fsmagic:= hex value diff --git a/include/linux/ima.h b/include/linux/ima.h index dc12fbcf484c..f0abade74707 100644 --- a/include/linux/ima.h +++ b/include/linux/ima.h @@ -26,6 +26,8 @@ extern int ima_read_file(struct file *file, enum kernel_read_file_id id); extern int ima_post_read_file(struct file *file, void *buf, loff_t size, enum kernel_read_file_id id); extern void ima_post_path_mknod(struct dentry *dentry); +extern void ima_buffer_check(const void *buff, int size, + const char *eventname); #ifdef CONFIG_IMA_KEXEC extern void ima_add_kexec_buffer(struct kimage *image); @@ -92,6 +94,9 @@ static inline void ima_post_path_mknod(struct dentry *dentry) return; } +static inline void ima_buffer_check(const void *buff, int size, + const char *eventname) +{} #endif /* CONFIG_IMA */ #ifndef CONFIG_IMA_KEXEC diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index d213e835c498..de70df132575 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -184,6 +184,7 @@ static inline unsigned long ima_hash_key(u8 *digest) hook(KEXEC_KERNEL_CHECK) \ hook(KEXEC_INITRAMFS_CHECK) \ hook(POLICY_CHECK) \ + hook(BUFFER_CHECK) \ hook(MAX_CHECK) #define __ima_hook_enumify(ENUM) ENUM, diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c index c7505fb122d4..cb3f67b366f1 100644 --- a/security/integrity/ima/ima_api.c +++ b/security/integrity/ima/ima_api.c @@ -169,6 +169,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename, * subj=, obj=, type=, func=, mask=, fsmagic= * subj,obj, and type: are LSM specific. * func: FILE_CHECK | BPRM_CHECK | CREDS_CHECK | MMAP_CHECK | MODULE_CHECK + * | BUFFER_CHECK * mask: contains the permission mask * fsmagic: hex value * diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c index 357edd140c09..3db3f3966ac7 100644 --- a/security/integrity/ima/ima_main.c +++ b/security/integrity/ima/ima_main.c @@ -576,6 +576,95 @@ int ima_load_data(enum kernel_load_data_id id) return 0; } +/* + * process_buffer_measurement - Measure the buffer passed to ima log. + * (Instead of using the file hash the buffer hash is used). + * @buff - The buffer that needs to be added to the log + * @size - size of buffer(in bytes) + * @eventname - this is eventname used for the various buffers + * that can be measured. + * + * The buffer passed is added to the ima logs. + * If the sig template is used, then the sig field contains the buffer. + * + * On success return 0. + * On error cases surface errors from ima calls. + */ +static int process_buffer_measurement(const void *buff, int size, + const char *eventname, const struct cred *cred, + u32 secid) +{ + int ret = -EINVAL; + struct ima_template_entry *entry = NULL; + struct integrity_iint_cache tmp_iint, *iint = &tmp_iint; + struct ima_event_data event_data = {iint, NULL, NULL, + NULL, 0, NULL}; + struct { + struct ima_digest_data hdr; + char digest[IMA_MAX_DIGEST_SIZE]; + } hash; + int violation = 0; + int pcr = CONFIG_IMA_MEASURE_PCR_IDX; + + if (!buff || size == 0 || !eventname) + goto err_out; + + if (ima_get_action(NULL, cred, secid, 0, BUFFER_CHECK, &pcr) + != IMA_MEASURE) + goto err_out; + + memset(iint, 0, sizeof(*iint)); + memset(&hash, 0, sizeof(hash)); + + event_data.filename = eventname; + + iint->ima_hash = &hash.hdr; + iint->ima_hash->algo = ima_hash_algo; + iint->ima_hash->length = hash_digest_size[ima_hash_algo]; + + ret = ima_calc_buffer_hash(buff, size, iint->ima_hash); + if (ret < 0) + goto err_out; + + ret = ima_alloc_init_template(&event_data, &entry); + if (ret < 0) + goto err_out; + + ret = ima_store_template(entry, violation, NULL, + buff, pcr); + if (ret < 0) { + ima_free_template_entry(entry); + goto err_out; + } + + return 0; + +err_out: + pr_err("Error in adding buffer measure: %d\n", ret); + return ret; +} + +/** + * ima_buffer_check - based on policy, collect & store buffer measurement + * @buf: pointer to buffer + * @size: size of buffer + * @eventname: event name identifier + * + * Buffers can only be measured, not appraised. The buffer identifier + * is used as the measurement list entry name (eg. boot_cmdline). + */ +void ima_buffer_check(const void *buf, int size, const char *eventname) +{ + u32 secid; + + if (buf && size != 0 && eventname) { + security_task_getsecid(current, &secid); + process_buffer_measurement(buf, size, eventname, + current_cred(), secid); + } +} + + static int __init init_ima(void) { int error; diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index e0cc323f948f..b12551ed191c 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -291,6 +291,12 @@ static bool ima_match_rules(struct ima_rule_entry *rule, struct inode *inode, { int i; + // Incase of BUFFER_CHECK, Inode is NULL + if (!inode) { + if ((rule->flags & IMA_FUNC) && (rule->func == func)) + return true; + return false; + } if ((rule->flags & IMA_FUNC) && (rule->func != func && func != POST_SETATTR)) return false; @@ -869,6 +875,8 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry) entry->func = KEXEC_INITRAMFS_CHECK; else if (strcmp(args[0].from, "POLICY_CHECK") == 0) entry->func = POLICY_CHECK; + else if (strcmp(args[0].from, "BUFFER_CHECK") == 0) + entry->func = BUFFER_CHECK; else result = -EINVAL; if (!result) From patchwork Fri May 3 22:25:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prakhar Srivastava X-Patchwork-Id: 10929385 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 A888614DB for ; Fri, 3 May 2019 22:25:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9995C287DB for ; Fri, 3 May 2019 22:25:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8DA02287E5; Fri, 3 May 2019 22:25:54 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 2A450287DB for ; Fri, 3 May 2019 22:25:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726042AbfECWZc (ORCPT ); Fri, 3 May 2019 18:25:32 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:34733 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726584AbfECWZc (ORCPT ); Fri, 3 May 2019 18:25:32 -0400 Received: by mail-pf1-f195.google.com with SMTP id b3so3571458pfd.1; Fri, 03 May 2019 15:25:31 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=FCYiRNnltpkvoj8ToixhqlqBTpeJ7lAyOQFKreaMHto=; b=j+uD5XuhlO/E0xasB/FTkqDwc1JF2EE3loRoxhhozBo09wg7SZIvnT/8snOPpjob8/ JfQ1C1cssLbQIDhBxJmWkKOcM0YgWPtTCzt54AFwhuyx9uu3H1EANjXNLK2qyveBoHDr s0MKrF3HufoI6tJmyvNgxBVyh2CFklyq04n5ued5mvebpSIhomA6slfU9mhlkBatC7U7 A09j+rMYm+i34Sb7tnrwAHZZUKO6ugT+gyp45KHoByp3jej/JbhtuUZ8wlYeaLF7G1gm 2Tko4UrMBLY/B9GQsBNQ3QP8TRk6U7N7YExYDr8GV8b6870LaboHezK/KM+STqAdtNux beVg== 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:mime-version:content-transfer-encoding; bh=FCYiRNnltpkvoj8ToixhqlqBTpeJ7lAyOQFKreaMHto=; b=SUV9U9oGBk122icGiqERl1Pj+ShA2UdqYUB7kI8ZqC3qH6u+KC6GLZLIzKwHK7WrwW LfgHxsW66i9L1sbn+JG8znAq4obElsHPLuvFn1J/twzxn/Y3ZqexB0R7oH9P3Ng9zRCd xn0fVBwiaaS42fAgpMNRFLH15vrbU8wTnWttRk4F3IFGOoAd0ImSkmmmRqQX/DaPO7cU R+Ho2xqghPCMl6zm/47Hl7AnUCfD7s3Pkz4LIw+fGpdvbAA6LGvIn0PwwwNPxyXI0/NZ 1ZZic8I6cpEg+GGhWJoaTblIEUOttnf2BoFTwSBER76d1q2HPL9gnNm6LYaFlinxn5Jd 24HQ== X-Gm-Message-State: APjAAAVOOIOi9K/ksbtv3O7Y4XNy9oB5zr9SK1vx/lQRqKn5GddKbO/w NUWV+g63wtTBqK/VZ2jj91MSTyAMDM0= X-Google-Smtp-Source: APXvYqzXmnh92kzvMCsoi/9maVTJasAr1J7QkHZ9L8sl3nrOen9tUfqBCvRr2TpBp3UNrQn75bnJ7A== X-Received: by 2002:a62:ed10:: with SMTP id u16mr14442618pfh.187.1556922331013; Fri, 03 May 2019 15:25:31 -0700 (PDT) Received: from prsriva-linux.corp.microsoft.com ([2001:4898:80e8:b:3170:1a6b:a13a:7ff]) by smtp.gmail.com with ESMTPSA id j22sm4314337pfi.139.2019.05.03.15.25.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 May 2019 15:25:30 -0700 (PDT) From: Prakhar Srivastava X-Google-Original-From: Prakhar Srivastava To: linux-integrity@vger.kernel.org, linux-secuirty-module@vger.kernel.org, linux-kernel@vger.kernel.org Cc: zohar@linux.ibm.com, ebiederm@xmission.com, vgoyal@redhat.com, nayna@linux.ibm.com, nramas@microsoft.com, prsriva@microsoft.com, Prakhar Srivastava Subject: [PATCH 2/5 v4] add the buffer to the xattr Date: Fri, 3 May 2019 15:25:20 -0700 Message-Id: <20190503222523.6294-3-prsriva02@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190503222523.6294-1-prsriva02@gmail.com> References: <20190503222523.6294-1-prsriva02@gmail.com> MIME-Version: 1.0 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 From: Prakhar Srivastava This change adds the buffer passed in to the xattr used for template entries. Signed-off-by: Prakhar Srivastava --- security/integrity/ima/ima_main.c | 37 ++++++++++++++++++++--- security/integrity/ima/ima_template_lib.c | 3 +- security/integrity/integrity.h | 1 + 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c index 3db3f3966ac7..7362952ab273 100644 --- a/security/integrity/ima/ima_main.c +++ b/security/integrity/ima/ima_main.c @@ -603,16 +603,37 @@ static int process_buffer_measurement(const void *buff, int size, struct ima_digest_data hdr; char digest[IMA_MAX_DIGEST_SIZE]; } hash; + struct buffer_xattr { + enum evm_ima_xattr_type type; + u16 buff_length; + unsigned char buff[0]; + }; + int violation = 0; int pcr = CONFIG_IMA_MEASURE_PCR_IDX; + struct buffer_xattr *buffer_event_data = NULL; + int alloc_length = 0; + int action = 0; if (!buff || size == 0 || !eventname) goto err_out; - if (ima_get_action(NULL, cred, secid, 0, BUFFER_CHECK, &pcr) - != IMA_MEASURE) + action = ima_get_action(NULL, cred, secid, 0, BUFFER_CHECK, &pcr); + if (!(action & IMA_AUDIT) && !(action & IMA_MEASURE)) + goto err_out; + + alloc_length = sizeof(struct buffer_xattr) + size; + buffer_event_data = kzalloc(alloc_length, GFP_KERNEL); + if (!buffer_event_data) goto err_out; + buffer_event_data->type = IMA_XATTR_BUFFER; + buffer_event_data->buff_length = size; + memcpy(buffer_event_data->buff, buff, size); + + event_data.xattr_value = (struct evm_ima_xattr_data *)buffer_event_data; + event_data.xattr_len = alloc_length; + memset(iint, 0, sizeof(*iint)); memset(&hash, 0, sizeof(hash)); @@ -630,17 +651,23 @@ static int process_buffer_measurement(const void *buff, int size, if (ret < 0) goto err_out; - ret = ima_store_template(entry, violation, NULL, + if (action & IMA_MEASURE) + ret = ima_store_template(entry, violation, NULL, buff, pcr); + if (ret < 0) { ima_free_template_entry(entry); goto err_out; } - return 0; + if (action & IMA_AUDIT) + ima_audit_measurement(iint, event_data.filename); + + ret = 0; err_out: - pr_err("Error in adding buffer measure: %d\n", ret); + kfree(buffer_event_data); + pr_debug("%s return: %d\n", __func__, ret); return ret; } diff --git a/security/integrity/ima/ima_template_lib.c b/security/integrity/ima/ima_template_lib.c index 513b457ae900..d22de3d8fcd9 100644 --- a/security/integrity/ima/ima_template_lib.c +++ b/security/integrity/ima/ima_template_lib.c @@ -383,7 +383,8 @@ int ima_eventsig_init(struct ima_event_data *event_data, { struct evm_ima_xattr_data *xattr_value = event_data->xattr_value; - if ((!xattr_value) || (xattr_value->type != EVM_IMA_XATTR_DIGSIG)) + if ((!xattr_value) || !((xattr_value->type == EVM_IMA_XATTR_DIGSIG) || + (xattr_value->type == IMA_XATTR_BUFFER))) return 0; return ima_write_template_field_data(xattr_value, event_data->xattr_len, diff --git a/security/integrity/integrity.h b/security/integrity/integrity.h index 7de59f44cba3..14ef904f091d 100644 --- a/security/integrity/integrity.h +++ b/security/integrity/integrity.h @@ -74,6 +74,7 @@ enum evm_ima_xattr_type { EVM_IMA_XATTR_DIGSIG, IMA_XATTR_DIGEST_NG, EVM_XATTR_PORTABLE_DIGSIG, + IMA_XATTR_BUFFER, IMA_XATTR_LAST }; From patchwork Fri May 3 22:25:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prakhar Srivastava X-Patchwork-Id: 10929383 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 4360314DB for ; Fri, 3 May 2019 22:25:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 33FD4287DB for ; Fri, 3 May 2019 22:25:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 27EFF287E5; Fri, 3 May 2019 22:25:52 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 AA11B287DB for ; Fri, 3 May 2019 22:25:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726862AbfECWZd (ORCPT ); Fri, 3 May 2019 18:25:33 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:45803 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726584AbfECWZd (ORCPT ); Fri, 3 May 2019 18:25:33 -0400 Received: by mail-pg1-f194.google.com with SMTP id i21so3350081pgi.12; Fri, 03 May 2019 15:25:32 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=6gv710NSkDAzQhiL4/sod+kpIyd9jem9gPAv5bYZQfg=; b=YVTbcFJorVl79ZUDMSEDOvyuPc0skNIYQiZkpjwwnLkumtyPTWj3IjndIofVX+eKUY MZB8ieAbzcuM+hWQgSPj4wlCWHS8mS2Eb26reNYIqQFlZkM6e/Wmpl+VsbSqOJ5d4YmC ofsc3DNbAmlY02M4bDlut3tHuvK6371mc2A6y81g45mrx+ZY0mKjsG5hXutokmkTeMg6 Odxn8bSpEgQIBgRtj9r272PmcZDfZJFD+Ak43ceNLItpWG8cGeYbwDSSqadGdUVvWj+E EFhRKl034OOaIRj7o9VnNrRZtG2ySFTZoUZsIRLjsaCM5yHVJvbi16DWBEo0OVLTQwsu 8oHg== 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:mime-version:content-transfer-encoding; bh=6gv710NSkDAzQhiL4/sod+kpIyd9jem9gPAv5bYZQfg=; b=QSxhDBTJDmFouB8RKHMRhKzwBiT5qIWJa5btzn0ABKG3ClFy7MKJHBR+RR/x6eOCEz N9OSpcxgGQ6YShgzmer9Et+VGpMiV62ZoNvPwsSOv+8z3DuHPebEIIJz0KIVNLywJCvZ xQ/6eTXRSzgKP9fQSqV74l7pO2k8JeFB4gWPd7Qa7KYQXXZ7wfJtcRFD1GwTMC2WamvY +LmeJreiI/9HbM5CGmtpi8q0ng4nHzvGAJlltk19oNNZN6zlBQnuV3bOg9xTC272j6tP PqAVUXOoHqRTx9wHx0a5Dm5jic6jXE+qB91kiVkyc6beLXC+8770fne4Z6oZ4SwiqT9w bwPA== X-Gm-Message-State: APjAAAVQscKLCNMQZ/0czbB7pF4BSWoTlTSgGJ5Lx2nE8Ouy8gG6y1/q QD3MNrn3XCPrV3XYWobocPAh3oAccKs= X-Google-Smtp-Source: APXvYqxDkZh+slC+4Z+87hPeHKLlOYmeOQyy5/4NoOJTg9Uxezh8X+J2vT6ijOrAEHRHYj7g5rXtkA== X-Received: by 2002:a62:a503:: with SMTP id v3mr14698626pfm.32.1556922332291; Fri, 03 May 2019 15:25:32 -0700 (PDT) Received: from prsriva-linux.corp.microsoft.com ([2001:4898:80e8:b:3170:1a6b:a13a:7ff]) by smtp.gmail.com with ESMTPSA id j22sm4314337pfi.139.2019.05.03.15.25.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 May 2019 15:25:31 -0700 (PDT) From: Prakhar Srivastava X-Google-Original-From: Prakhar Srivastava To: linux-integrity@vger.kernel.org, linux-secuirty-module@vger.kernel.org, linux-kernel@vger.kernel.org Cc: zohar@linux.ibm.com, ebiederm@xmission.com, vgoyal@redhat.com, nayna@linux.ibm.com, nramas@microsoft.com, prsriva@microsoft.com, Prakhar Srivastava Subject: [PATCH 3/5 v4] add kexec_cmdline used to ima Date: Fri, 3 May 2019 15:25:21 -0700 Message-Id: <20190503222523.6294-4-prsriva02@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190503222523.6294-1-prsriva02@gmail.com> References: <20190503222523.6294-1-prsriva02@gmail.com> MIME-Version: 1.0 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 From: Prakhar Srivastava prepend the kernel file name to the cmdline args to avoid conflicrts in case of multiple kexec. Pass the new generated buffer to ima for measurmenet. Signed-off-by: Prakhar Srivastava --- kernel/kexec_core.c | 57 +++++++++++++++++++++++++++++++++++++++++++++ kernel/kexec_file.c | 14 +++++++++++ 2 files changed, 71 insertions(+) diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index d7140447be75..4667f03d406e 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -1213,3 +1213,60 @@ void __weak arch_kexec_protect_crashkres(void) void __weak arch_kexec_unprotect_crashkres(void) {} + +/** + * kexec_cmdline_prepend_img_name - prepare the buffer with cmdline + * that needs to be measured + * @outbuf - out buffer that contains the formated string + * @kernel_fd - the file identifier for the kerenel image + * @cmdline_ptr - ptr to the cmdline buffer + * @cmdline_len - len of the buffer. + * + * This generates a buffer in the format Kerenelfilename::cmdline + * + * On success return 0. + * On failure return -EINVAL. + */ +int kexec_cmdline_prepend_img_name(char **outbuf, int kernel_fd, + const char *cmdline_ptr, + unsigned long cmdline_len) +{ + int ret = -EINVAL; + struct fd f = {}; + int size = 0; + char *buf = NULL; + char delimiter[] = "::"; + + if (!outbuf || !cmdline_ptr) + goto out; + + f = fdget(kernel_fd); + if (!f.file) + goto out; + + size = (f.file->f_path.dentry->d_name.len + cmdline_len - 1+ + ARRAY_SIZE(delimiter)) - 1; + + buf = kzalloc(size, GFP_KERNEL); + if (!buf) + goto out; + + memcpy(buf, f.file->f_path.dentry->d_name.name, + f.file->f_path.dentry->d_name.len); + memcpy(buf + f.file->f_path.dentry->d_name.len, + delimiter, ARRAY_SIZE(delimiter) - 1); + memcpy(buf + f.file->f_path.dentry->d_name.len + + ARRAY_SIZE(delimiter) - 1, + cmdline_ptr, cmdline_len - 1); + + *outbuf = buf; + ret = size; + + pr_debug("kexec cmdline buff: %s\n", buf); + +out: + if (f.file) + fdput(f); + + return ret; +} diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index f1d0e00a3971..d287e139085c 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -191,6 +191,8 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd, int ret = 0; void *ldata; loff_t size; + char *buff_to_measure = NULL; + int buff_to_measure_size = 0; ret = kernel_read_file_from_fd(kernel_fd, &image->kernel_buf, &size, INT_MAX, READING_KEXEC_IMAGE); @@ -241,6 +243,16 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd, ret = -EINVAL; goto out; } + + /* IMA measures the cmdline args passed to the next kernel*/ + buff_to_measure_size = + kexec_cmdline_prepend_img_name(&buff_to_measure, + kernel_fd, image->cmdline_buf, image->cmdline_buf_len); + + ima_buffer_check(buff_to_measure, buff_to_measure_size, + "kexec_cmdline"); + + } /* Call arch image load handlers */ @@ -253,7 +265,9 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd, image->image_loader_data = ldata; out: + /* In case of error, free up all allocated memory in this function */ + kfree(buff_to_measure); if (ret) kimage_file_post_load_cleanup(image); return ret; From patchwork Fri May 3 22:25:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prakhar Srivastava X-Patchwork-Id: 10929379 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 94BDF912 for ; Fri, 3 May 2019 22:25:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 845DA287E5 for ; Fri, 3 May 2019 22:25:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 78084287E6; Fri, 3 May 2019 22:25:44 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 EFDF4287E3 for ; Fri, 3 May 2019 22:25:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726939AbfECWZg (ORCPT ); Fri, 3 May 2019 18:25:36 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:38152 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726883AbfECWZe (ORCPT ); Fri, 3 May 2019 18:25:34 -0400 Received: by mail-pf1-f193.google.com with SMTP id 10so3563136pfo.5; Fri, 03 May 2019 15:25:33 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=Vw/WCoWJC8LG27VjrkL+CC1VMWeROo418tAMf4jQKGQ=; b=mdGH1SaHShD+kgLt/Fx6BWhW6AJ0v4kausIuhDquzZhHChDRtQZM/OK/MHkvW4xUQl WCusueh03W4KqzU2NPxy/5BZ1p1pR6tOamo1uDRB+7/z4vXp6lMkNIuAMBmJnnFsAkFn 5XJ6Tmexbpzdv6RHSqiW8HjXN3PgtrZHoaCprVtCtYraLjgNZQ5xYxShCIAohXx3j44y LxPaIx2eMTv/5BY1O/mHjfPFoGSnGxAc8TrPWBlgspy7I/TGxEsszBrpcvku8euWSo2m o8fVgp5Uor0whNnbajXLVzVIR6VbGuze5KOX/L5k8eUiT8lwz+/nJLmxrshnhgti9jAI QRPg== 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:mime-version:content-transfer-encoding; bh=Vw/WCoWJC8LG27VjrkL+CC1VMWeROo418tAMf4jQKGQ=; b=nGp+dMHsrN93DsWxXY9qKayGNQx7Lc+5aghXnhOOKqCT4enu6zK/RV11B3oFKC0rJi O5S/QGWQ1VnjxR5twYvdCBYTeWY2v8/W0JXL3ybLRGmQASAxx3CrtKCTzyyXYrvJXFPQ y4kCueLjUr8EAGgSRPgRFnwFvX0x0o8I2APIVycgtmc1IhCiDwQIBASZz2SlcgmHY5ZZ 0mAAb3KlF9siqVcKWs2QDqT00qNFoRPmBesDdHFKawiS0BSa90YltzB6UN7JStrFwCRE Y2b3wC+Pg1dzVY54+IazZjAwaALoZ2WVQrvhIt2fOEEJF96aEVTYdJA0BJ8leWi2jq99 WD0A== X-Gm-Message-State: APjAAAVmE9NeROVQC/uP2Beb7JRNLmhE4Qa1dWZ6YYoJx/6+AKRnJsAl B2Y6sOwkPpRcApMxJqjJ7U0el+GIqQg= X-Google-Smtp-Source: APXvYqzwVBUrpU+9GszPOlMwB4DPuKWzEhuImiw055hwutotb6LgPxCQ/3G9Jj33vn4zAtmHrGCH7A== X-Received: by 2002:a62:5915:: with SMTP id n21mr14163364pfb.180.1556922333427; Fri, 03 May 2019 15:25:33 -0700 (PDT) Received: from prsriva-linux.corp.microsoft.com ([2001:4898:80e8:b:3170:1a6b:a13a:7ff]) by smtp.gmail.com with ESMTPSA id j22sm4314337pfi.139.2019.05.03.15.25.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 May 2019 15:25:32 -0700 (PDT) From: Prakhar Srivastava X-Google-Original-From: Prakhar Srivastava To: linux-integrity@vger.kernel.org, linux-secuirty-module@vger.kernel.org, linux-kernel@vger.kernel.org Cc: zohar@linux.ibm.com, ebiederm@xmission.com, vgoyal@redhat.com, nayna@linux.ibm.com, nramas@microsoft.com, prsriva@microsoft.com, Prakhar Srivastava Subject: [PATCH 4/5 v4] added LSM hook to call ima_buffer_check Date: Fri, 3 May 2019 15:25:22 -0700 Message-Id: <20190503222523.6294-5-prsriva02@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190503222523.6294-1-prsriva02@gmail.com> References: <20190503222523.6294-1-prsriva02@gmail.com> MIME-Version: 1.0 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 From: Prakhar Srivastava add a LAM hook for kexec_cmldine args to be made available to other LSMs. Signed-off-by: Prakhar Srivastava --- include/linux/lsm_hooks.h | 3 +++ include/linux/security.h | 3 +++ kernel/kexec_internal.h | 4 +++- security/security.c | 6 ++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index a240a3fc5fc4..f18562c1eb24 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1672,6 +1672,8 @@ union security_list_options { int (*inode_setsecctx)(struct dentry *dentry, void *ctx, u32 ctxlen); int (*inode_getsecctx)(struct inode *inode, void **ctx, u32 *ctxlen); + int (*buffer_check)(const void *buff, int size, const char *eventname); + #ifdef CONFIG_SECURITY_NETWORK int (*unix_stream_connect)(struct sock *sock, struct sock *other, struct sock *newsk); @@ -1945,6 +1947,7 @@ struct security_hook_heads { struct hlist_head inode_notifysecctx; struct hlist_head inode_setsecctx; struct hlist_head inode_getsecctx; + struct hlist_head buffer_check; #ifdef CONFIG_SECURITY_NETWORK struct hlist_head unix_stream_connect; struct hlist_head unix_may_send; diff --git a/include/linux/security.h b/include/linux/security.h index 49f2685324b0..8dece6da0dda 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -388,6 +388,7 @@ void security_inode_invalidate_secctx(struct inode *inode); int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen); int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen); int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen); +void security_buffer_measure(const void *buff, int size, char *eventname); #else /* CONFIG_SECURITY */ static inline int call_lsm_notifier(enum lsm_event event, void *data) @@ -1188,6 +1189,8 @@ static inline int security_inode_getsecctx(struct inode *inode, void **ctx, u32 { return -EOPNOTSUPP; } +static inline void security_buffer_measure(const void *buff, int size, char *eventname) +{ } #endif /* CONFIG_SECURITY */ #ifdef CONFIG_SECURITY_NETWORK diff --git a/kernel/kexec_internal.h b/kernel/kexec_internal.h index 48aaf2ac0d0d..9f967fbb5aa0 100644 --- a/kernel/kexec_internal.h +++ b/kernel/kexec_internal.h @@ -12,7 +12,9 @@ int kimage_load_segment(struct kimage *image, struct kexec_segment *segment); void kimage_terminate(struct kimage *image); int kimage_is_destination_range(struct kimage *image, unsigned long start, unsigned long end); - +int kexec_cmdline_prepend_img_name(char **outbuf, int kernel_fd, + const char *cmdline_ptr, + unsigned long cmdline_len); extern struct mutex kexec_mutex; #ifdef CONFIG_KEXEC_FILE diff --git a/security/security.c b/security/security.c index 23cbb1a295a3..2b575a40470e 100644 --- a/security/security.c +++ b/security/security.c @@ -754,6 +754,12 @@ int security_bprm_check(struct linux_binprm *bprm) return ima_bprm_check(bprm); } +void security_buffer_measure(const void *buff, int size, char *eventname) +{ + call_void_hook(buffer_check, buff, size, eventname); + return ima_buffer_check(buff, size, eventname); +} + void security_bprm_committing_creds(struct linux_binprm *bprm) { call_void_hook(bprm_committing_creds, bprm); From patchwork Fri May 3 22:25:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prakhar Srivastava X-Patchwork-Id: 10929381 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 B582414DB for ; Fri, 3 May 2019 22:25:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A54CB287DB for ; Fri, 3 May 2019 22:25:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 999C4287E5; Fri, 3 May 2019 22:25:44 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 BB1FD287DB for ; Fri, 3 May 2019 22:25:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726925AbfECWZg (ORCPT ); Fri, 3 May 2019 18:25:36 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:44226 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726584AbfECWZf (ORCPT ); Fri, 3 May 2019 18:25:35 -0400 Received: by mail-pf1-f193.google.com with SMTP id y13so3549099pfm.11; Fri, 03 May 2019 15:25:34 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=IDxzpd/1S+G1CGbrrMAZE/cFBJgmFdFrBdHZz/vYhQI=; b=sdjrYTm+dgmdjujB/5PqC8aF79vzR66pBSOWV+lk7u61d0b10MxHuUNJ9Z5wnfGPyz 67TI4jUNaFD2YWjHR+9/GGGocbDrEiQJbLFJOeEXb4ldkL3c2ybKxVREe9DKO+9883Ya 9Pfh7cs8ZnReGu2dmoP9P2KLc8yA5tSylhi0/mYulKwP/BrcrnKGKL5Y1vzZ6wzJdedB QGNya0X9xxr3nrE5ZxI0mnLPfdmwsDtyssXG6HmcwMUpEh2OLnZ+9xhoLSNQdei05pkU BPQ9gDcfm8lUsxkicP2+z94mmzVRpwKpBKFPe3otKKBzz6BKK1fOrKISMZb5lw2EmUab 2rJA== 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:mime-version:content-transfer-encoding; bh=IDxzpd/1S+G1CGbrrMAZE/cFBJgmFdFrBdHZz/vYhQI=; b=Iw0zkYqS+NFL3jUO878yEJlBTv5fbWgVmy0VQASnLaUHtCBPcn1AaEDAZfGJ1uWe5v kOhfT9SFoM8WDJXYdOblBW/Pl/5FSiEZmLWWLh2S7f4CHQQ/cTNVuomCzapiSak3q/nN E18gz3NBH+46L2NNiESWprRL2emgjGUofnvq5h+3OCYN6YX3tZxgZwbvlX9RRoyOcVSF PDnk6sQkQFF3o5+LtTP7g+q02ieWyxh0wC9g6f57x7dFhSKbXUcc6YFoTgoO+RSMdyqd fP6p3tDB+U9MDTXivJA5YZY2D4jSenn5eSvK9AmUgfxANB9H2G1m5TC0GLLL/+cNghS0 X2Wg== X-Gm-Message-State: APjAAAWpIlCZ2zVAiXpFCYLyRdgF2C0I+y6+hLUtugklZWc1kLO9MS28 Xbh9QuLsFptLPdlsSF2y4q4OyjW66Dw= X-Google-Smtp-Source: APXvYqyySb3xbHGJMlPDR5N45Ya9GmccZkU6b7QdNuu7IgnkgB/voTWfDTA0r+u/k5lXPHaFH+GAQQ== X-Received: by 2002:a63:6fc1:: with SMTP id k184mr13969477pgc.239.1556922334434; Fri, 03 May 2019 15:25:34 -0700 (PDT) Received: from prsriva-linux.corp.microsoft.com ([2001:4898:80e8:b:3170:1a6b:a13a:7ff]) by smtp.gmail.com with ESMTPSA id j22sm4314337pfi.139.2019.05.03.15.25.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 May 2019 15:25:33 -0700 (PDT) From: Prakhar Srivastava X-Google-Original-From: Prakhar Srivastava To: linux-integrity@vger.kernel.org, linux-secuirty-module@vger.kernel.org, linux-kernel@vger.kernel.org Cc: zohar@linux.ibm.com, ebiederm@xmission.com, vgoyal@redhat.com, nayna@linux.ibm.com, nramas@microsoft.com, prsriva@microsoft.com, Prakhar Srivastava Subject: [PATCH 5/5 v4] removed the LSM hook made available, and renamed the ima_policy to be KEXEC_CMDLINE Date: Fri, 3 May 2019 15:25:23 -0700 Message-Id: <20190503222523.6294-6-prsriva02@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190503222523.6294-1-prsriva02@gmail.com> References: <20190503222523.6294-1-prsriva02@gmail.com> MIME-Version: 1.0 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 From: Prakhar Srivastava Per suggestions from the community, removed the LSM hook. and renamed the buffer_check func and policy to kexec_cmdline [suggested by: Mimi Zohar] Signed-off-by: Prakhar Srivastava --- Documentation/ABI/testing/ima_policy | 2 +- include/linux/ima.h | 6 +-- include/linux/lsm_hooks.h | 3 -- include/linux/security.h | 1 - kernel/kexec_core.c | 59 +--------------------------- kernel/kexec_file.c | 14 +------ security/integrity/ima/ima.h | 2 +- security/integrity/ima/ima_api.c | 2 +- security/integrity/ima/ima_main.c | 11 +++--- security/integrity/ima/ima_policy.c | 4 +- security/security.c | 6 --- 11 files changed, 15 insertions(+), 95 deletions(-) diff --git a/Documentation/ABI/testing/ima_policy b/Documentation/ABI/testing/ima_policy index 12cfe3ff2dea..62e7cd687e9c 100644 --- a/Documentation/ABI/testing/ima_policy +++ b/Documentation/ABI/testing/ima_policy @@ -29,7 +29,7 @@ Description: base: func:= [BPRM_CHECK][MMAP_CHECK][CREDS_CHECK][FILE_CHECK][MODULE_CHECK] [FIRMWARE_CHECK] [KEXEC_KERNEL_CHECK] [KEXEC_INITRAMFS_CHECK] - [BUFFER_CHECK] + [KEXEC_CMDLINE] mask:= [[^]MAY_READ] [[^]MAY_WRITE] [[^]MAY_APPEND] [[^]MAY_EXEC] fsmagic:= hex value diff --git a/include/linux/ima.h b/include/linux/ima.h index f0abade74707..2c7a22231008 100644 --- a/include/linux/ima.h +++ b/include/linux/ima.h @@ -26,8 +26,7 @@ extern int ima_read_file(struct file *file, enum kernel_read_file_id id); extern int ima_post_read_file(struct file *file, void *buf, loff_t size, enum kernel_read_file_id id); extern void ima_post_path_mknod(struct dentry *dentry); -extern void ima_buffer_check(const void *buff, int size, - const char *eventname); +extern void ima_kexec_cmdline(const void *buff, int size); #ifdef CONFIG_IMA_KEXEC extern void ima_add_kexec_buffer(struct kimage *image); @@ -94,8 +93,7 @@ static inline void ima_post_path_mknod(struct dentry *dentry) return; } -static inline void ima_buffer_check(const void *buff, int size, - const char *eventname) +static inline void ima_kexec_cmdline(const void *buff, int size) {} #endif /* CONFIG_IMA */ diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index f18562c1eb24..a240a3fc5fc4 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1672,8 +1672,6 @@ union security_list_options { int (*inode_setsecctx)(struct dentry *dentry, void *ctx, u32 ctxlen); int (*inode_getsecctx)(struct inode *inode, void **ctx, u32 *ctxlen); - int (*buffer_check)(const void *buff, int size, const char *eventname); - #ifdef CONFIG_SECURITY_NETWORK int (*unix_stream_connect)(struct sock *sock, struct sock *other, struct sock *newsk); @@ -1947,7 +1945,6 @@ struct security_hook_heads { struct hlist_head inode_notifysecctx; struct hlist_head inode_setsecctx; struct hlist_head inode_getsecctx; - struct hlist_head buffer_check; #ifdef CONFIG_SECURITY_NETWORK struct hlist_head unix_stream_connect; struct hlist_head unix_may_send; diff --git a/include/linux/security.h b/include/linux/security.h index 8dece6da0dda..8a129664ba4e 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -388,7 +388,6 @@ void security_inode_invalidate_secctx(struct inode *inode); int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen); int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen); int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen); -void security_buffer_measure(const void *buff, int size, char *eventname); #else /* CONFIG_SECURITY */ static inline int call_lsm_notifier(enum lsm_event event, void *data) diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index 4667f03d406e..8c0a83980d72 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -1212,61 +1212,4 @@ void __weak arch_kexec_protect_crashkres(void) {} void __weak arch_kexec_unprotect_crashkres(void) -{} - -/** - * kexec_cmdline_prepend_img_name - prepare the buffer with cmdline - * that needs to be measured - * @outbuf - out buffer that contains the formated string - * @kernel_fd - the file identifier for the kerenel image - * @cmdline_ptr - ptr to the cmdline buffer - * @cmdline_len - len of the buffer. - * - * This generates a buffer in the format Kerenelfilename::cmdline - * - * On success return 0. - * On failure return -EINVAL. - */ -int kexec_cmdline_prepend_img_name(char **outbuf, int kernel_fd, - const char *cmdline_ptr, - unsigned long cmdline_len) -{ - int ret = -EINVAL; - struct fd f = {}; - int size = 0; - char *buf = NULL; - char delimiter[] = "::"; - - if (!outbuf || !cmdline_ptr) - goto out; - - f = fdget(kernel_fd); - if (!f.file) - goto out; - - size = (f.file->f_path.dentry->d_name.len + cmdline_len - 1+ - ARRAY_SIZE(delimiter)) - 1; - - buf = kzalloc(size, GFP_KERNEL); - if (!buf) - goto out; - - memcpy(buf, f.file->f_path.dentry->d_name.name, - f.file->f_path.dentry->d_name.len); - memcpy(buf + f.file->f_path.dentry->d_name.len, - delimiter, ARRAY_SIZE(delimiter) - 1); - memcpy(buf + f.file->f_path.dentry->d_name.len + - ARRAY_SIZE(delimiter) - 1, - cmdline_ptr, cmdline_len - 1); - - *outbuf = buf; - ret = size; - - pr_debug("kexec cmdline buff: %s\n", buf); - -out: - if (f.file) - fdput(f); - - return ret; -} +{} \ No newline at end of file diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index d287e139085c..2eb977984537 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -191,8 +191,6 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd, int ret = 0; void *ldata; loff_t size; - char *buff_to_measure = NULL; - int buff_to_measure_size = 0; ret = kernel_read_file_from_fd(kernel_fd, &image->kernel_buf, &size, INT_MAX, READING_KEXEC_IMAGE); @@ -244,15 +242,8 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd, goto out; } - /* IMA measures the cmdline args passed to the next kernel*/ - buff_to_measure_size = - kexec_cmdline_prepend_img_name(&buff_to_measure, - kernel_fd, image->cmdline_buf, image->cmdline_buf_len); - - ima_buffer_check(buff_to_measure, buff_to_measure_size, - "kexec_cmdline"); - - + /* IMA measures the cmdline args passed to the next kernel */ + ima_kexec_cmdline(image->cmdline_buf, image->cmdline_buf_len - 1); } /* Call arch image load handlers */ @@ -267,7 +258,6 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd, out: /* In case of error, free up all allocated memory in this function */ - kfree(buff_to_measure); if (ret) kimage_file_post_load_cleanup(image); return ret; diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index de70df132575..226a26d8de09 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -184,7 +184,7 @@ static inline unsigned long ima_hash_key(u8 *digest) hook(KEXEC_KERNEL_CHECK) \ hook(KEXEC_INITRAMFS_CHECK) \ hook(POLICY_CHECK) \ - hook(BUFFER_CHECK) \ + hook(KEXEC_CMDLINE) \ hook(MAX_CHECK) #define __ima_hook_enumify(ENUM) ENUM, diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c index cb3f67b366f1..800d965232e5 100644 --- a/security/integrity/ima/ima_api.c +++ b/security/integrity/ima/ima_api.c @@ -169,7 +169,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename, * subj=, obj=, type=, func=, mask=, fsmagic= * subj,obj, and type: are LSM specific. * func: FILE_CHECK | BPRM_CHECK | CREDS_CHECK | MMAP_CHECK | MODULE_CHECK - * | BUFFER_CHECK + * | KEXEC_CMDLINE * mask: contains the permission mask * fsmagic: hex value * diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c index 7362952ab273..fc9cef54e37c 100644 --- a/security/integrity/ima/ima_main.c +++ b/security/integrity/ima/ima_main.c @@ -618,7 +618,7 @@ static int process_buffer_measurement(const void *buff, int size, if (!buff || size == 0 || !eventname) goto err_out; - action = ima_get_action(NULL, cred, secid, 0, BUFFER_CHECK, &pcr); + action = ima_get_action(NULL, cred, secid, 0, KEXEC_CMDLINE, &pcr); if (!(action & IMA_AUDIT) && !(action & IMA_MEASURE)) goto err_out; @@ -672,21 +672,20 @@ static int process_buffer_measurement(const void *buff, int size, } /** - * ima_buffer_check - based on policy, collect & store buffer measurement + * ima_kexec_cmdline - based on policy, collect & store buffer measurement * @buf: pointer to buffer * @size: size of buffer - * @eventname: event name identifier * * Buffers can only be measured, not appraised. The buffer identifier * is used as the measurement list entry name (eg. boot_cmdline). */ -void ima_buffer_check(const void *buf, int size, const char *eventname) +void ima_kexec_cmdline(const void *buf, int size) { u32 secid; - if (buf && size != 0 && eventname) { + if (buf && size != 0) { security_task_getsecid(current, &secid); - process_buffer_measurement(buf, size, eventname, + process_buffer_measurement(buf, size, "Kexec-cmdline", current_cred(), secid); } } diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index b12551ed191c..7ae59afbf28f 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -875,8 +875,8 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry) entry->func = KEXEC_INITRAMFS_CHECK; else if (strcmp(args[0].from, "POLICY_CHECK") == 0) entry->func = POLICY_CHECK; - else if (strcmp(args[0].from, "BUFFER_CHECK") == 0) - entry->func = BUFFER_CHECK; + else if (strcmp(args[0].from, "KEXEC_CMDLINE") == 0) + entry->func = KEXEC_CMDLINE; else result = -EINVAL; if (!result) diff --git a/security/security.c b/security/security.c index 2b575a40470e..23cbb1a295a3 100644 --- a/security/security.c +++ b/security/security.c @@ -754,12 +754,6 @@ int security_bprm_check(struct linux_binprm *bprm) return ima_bprm_check(bprm); } -void security_buffer_measure(const void *buff, int size, char *eventname) -{ - call_void_hook(buffer_check, buff, size, eventname); - return ima_buffer_check(buff, size, eventname); -} - void security_bprm_committing_creds(struct linux_binprm *bprm) { call_void_hook(bprm_committing_creds, bprm);