Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3661740imm; Tue, 29 May 2018 11:05:56 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpSVV24Gx1gHNhsSX/C6C0TwxBABldxqYj02l0Jm9vaorbdxGyKA4IAweY3JqmedGYt5krK X-Received: by 2002:a65:5386:: with SMTP id x6-v6mr14538516pgq.188.1527617156353; Tue, 29 May 2018 11:05:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527617156; cv=none; d=google.com; s=arc-20160816; b=RDBbBOMUdYwJoiGBOzxhC+VYyQIbfv9encyZCYU2XDTii4y8S5XBzDRrYH1fxb14sM TxzLDTfaWGL6INbHgbZ2WLSa8IqTrk4ADLKN0SvdZtQfGujc0h4ZIcQJ370YkCGtB/r9 hckxWnVC2XNAeO5EMmRO8bYuELmBVA9avNceI5bzcH0h0G5LW4X/At0hi4Ev8TXcuj+I htygcfuo4ufw1LtOj/Aqv12+Mjm/YNEUSDJTh5KLxY5D5JfFvqNGX+xq5HF8KxD7oZaK vUjZrWKD0oWp30zKZJah6tuLemn9zxWQEJKDrPVijP8w22sADR5iTzSfTK+8ipHNpWCq rJhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=vsG0b6Fc7Hv3L/x1YVhN9jGdCKzR6IzNSoEUhpqHfWM=; b=MUfU6Au+BRaMQ/TN3N6YyEjDZRRhMiFU7dh8VP+37PzJwztMoOPYEVqtceWOsD/fxx Z/EoQUiIvG31h9zAB9N6e+Bh6rW+zr/cqvJTJJoIOrtA9fwqRMWEnkHIKhBLJ2cZpz4Y h54nRjVp9dSFgd+gHEmD5FIKs2j3hOsQaQZAyYXYD0EAjprAHLqAcrV35fO9IPoKsvVy i4U/suDO9OelZYRwNi/3MeP7yhEAMaDJJzBL/yBJZPuFU75ISNgsZYOUd31XI68nBCv8 /hvSLVDvJsWY6NX85E0gr9WvoADl222FFh3FlPSSXadocWuLCqIshFf4OhwZSRIgRQoL MFOQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 64-v6si32378293plk.137.2018.05.29.11.05.42; Tue, 29 May 2018 11:05:56 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965753AbeE2SCV (ORCPT + 99 others); Tue, 29 May 2018 14:02:21 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:48504 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965622AbeE2SCS (ORCPT ); Tue, 29 May 2018 14:02:18 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4THsbu7144039 for ; Tue, 29 May 2018 14:02:18 -0400 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 2j9ajgu956-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 May 2018 14:02:17 -0400 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 29 May 2018 19:02:14 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 29 May 2018 19:02:11 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4TI2AMG20774950 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 29 May 2018 18:02:10 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 45F02AE058; Tue, 29 May 2018 18:51:17 +0100 (BST) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 091B4AE059; Tue, 29 May 2018 18:51:16 +0100 (BST) Received: from dhcp-9-2-54-219.watson.ibm.com (unknown [9.2.54.219]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 29 May 2018 18:51:15 +0100 (BST) From: Mimi Zohar To: linux-integrity@vger.kernel.org Cc: Mimi Zohar , linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, David Howells , "Luis R . Rodriguez" , Eric Biederman , kexec@lists.infradead.org, Andres Rodriguez , Greg Kroah-Hartman , Ard Biesheuvel , Kees Cook , Casey Schaufler Subject: [PATCH v4 1/8] security: define new LSM hook named security_kernel_load_data Date: Tue, 29 May 2018 14:01:53 -0400 X-Mailer: git-send-email 2.7.5 In-Reply-To: <1527616920-5415-1-git-send-email-zohar@linux.vnet.ibm.com> References: <1527616920-5415-1-git-send-email-zohar@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18052918-0040-0000-0000-0000045EA138 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18052918-0041-0000-0000-0000210313AA Message-Id: <1527616920-5415-2-git-send-email-zohar@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-05-29_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=5 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1805290195 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Differentiate between the kernel reading a file from the kernel loading data provided by userspace. This patch defines a new LSM hook named security_kernel_load_data. Signed-off-by: Mimi Zohar Cc: Eric Biederman Cc: Luis R. Rodriguez Cc: Kees Cook Cc: David Howells Cc: Casey Schaufler Changelog v4: - Define new LSM hook named security_kernel_load_data. Changelog v3: - Rename security_kernel_read_file to security_kernel_read_data(). Changelog v2: - Define a generic wrapper named security_kernel_read_blob() for security_kernel_read_file(). Changelog v1: - Define and call security_kexec_load(), a wrapper for security_kernel_read_file(). --- include/linux/lsm_hooks.h | 6 ++++++ include/linux/security.h | 33 +++++++++++++++++++++++++++++++++ security/security.c | 5 +++++ 3 files changed, 44 insertions(+) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 8f1131c8dd54..a08bc2587b96 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -576,6 +576,10 @@ * userspace to load a kernel module with the given name. * @kmod_name name of the module requested by the kernel * Return 0 if successful. + * @kernel_load_data: + * Load data provided by userspace. + * @id kernel load data identifier + * Return 0 if permission is granted. * @kernel_read_file: * Read a file specified by userspace. * @file contains the file structure pointing to the file being read @@ -1582,6 +1586,7 @@ union security_list_options { int (*kernel_act_as)(struct cred *new, u32 secid); int (*kernel_create_files_as)(struct cred *new, struct inode *inode); int (*kernel_module_request)(char *kmod_name); + int (*kernel_load_data)(enum kernel_load_data_id id); int (*kernel_read_file)(struct file *file, enum kernel_read_file_id id); int (*kernel_post_read_file)(struct file *file, char *buf, loff_t size, enum kernel_read_file_id id); @@ -1872,6 +1877,7 @@ struct security_hook_heads { struct hlist_head cred_getsecid; struct hlist_head kernel_act_as; struct hlist_head kernel_create_files_as; + struct hlist_head kernel_load_data; struct hlist_head kernel_read_file; struct hlist_head kernel_post_read_file; struct hlist_head kernel_module_request; diff --git a/include/linux/security.h b/include/linux/security.h index 63030c85ee19..3d54d5945755 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -159,6 +159,33 @@ extern int mmap_min_addr_handler(struct ctl_table *table, int write, typedef int (*initxattrs) (struct inode *inode, const struct xattr *xattr_array, void *fs_data); + +#define __kernel_load_data_id(id) \ + id(UNKNOWN, unknown) \ + id(FIRMWARE, firmware) \ + id(MODULE, kernel-module) \ + id(KEXEC_IMAGE, kexec-image) \ + id(MAX_ID, ) + +#define __data_id_enumify(ENUM, dummy) LOADING_ ## ENUM, +#define __data_id_stringify(dummy, str) #str, + +enum kernel_load_data_id { + __kernel_load_data_id(__data_id_enumify) +}; + +static const char * const kernel_load_data_str[] = { + __kernel_load_data_id(__data_id_stringify) +}; + +static inline const char *kernel_load_data_id_str(enum kernel_load_data_id id) +{ + if ((unsigned)id >= LOADING_MAX_ID) + return kernel_load_data_str[LOADING_UNKNOWN]; + + return kernel_load_data_str[id]; +} + #ifdef CONFIG_SECURITY struct security_mnt_opts { @@ -320,6 +347,7 @@ void security_cred_getsecid(const struct cred *c, u32 *secid); int security_kernel_act_as(struct cred *new, u32 secid); int security_kernel_create_files_as(struct cred *new, struct inode *inode); int security_kernel_module_request(char *kmod_name); +int security_kernel_load_data(enum kernel_load_data_id id); int security_kernel_read_file(struct file *file, enum kernel_read_file_id id); int security_kernel_post_read_file(struct file *file, char *buf, loff_t size, enum kernel_read_file_id id); @@ -909,6 +937,11 @@ static inline int security_kernel_module_request(char *kmod_name) return 0; } +static inline int security_kernel_load_data(enum kernel_load_data_id id) +{ + return 0; +} + static inline int security_kernel_read_file(struct file *file, enum kernel_read_file_id id) { diff --git a/security/security.c b/security/security.c index 68f46d849abe..c2de2f134854 100644 --- a/security/security.c +++ b/security/security.c @@ -1056,6 +1056,11 @@ int security_kernel_post_read_file(struct file *file, char *buf, loff_t size, } EXPORT_SYMBOL_GPL(security_kernel_post_read_file); +int security_kernel_load_data(enum kernel_load_data_id id) +{ + return call_int_hook(kernel_load_data, 0, id); +} + int security_task_fix_setuid(struct cred *new, const struct cred *old, int flags) { -- 2.7.5