From patchwork Mon Jun 20 13:36:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huw Davies X-Patchwork-Id: 9187665 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 60C3E607D1 for ; Mon, 20 Jun 2016 14:46:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4ADEB2787C for ; Mon, 20 Jun 2016 14:46:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3CF552793A; Mon, 20 Jun 2016 14:46:06 +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=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from emsm-gh1-uea10.nsa.gov (emsm-gh1-uea10.nsa.gov [8.44.101.8]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E360F2787C for ; Mon, 20 Jun 2016 14:46:04 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.26,499,1459814400"; d="scan'208";a="14814366" IronPort-PHdr: =?us-ascii?q?9a23=3AQSs2ARK2WmwahJUprdmcpTZWNBhigK39O0sv0rFi?= =?us-ascii?q?tYgVK/nxwZ3uMQTl6Ol3ixeRBMOAu6MC2red7P6ocFdDyKjCmUhKSIZLWR4BhJ?= =?us-ascii?q?detC0bK+nBN3fGKuX3ZTcxBsVIWQwt1Xi6NU9IBJS2PAWK8TWM5DIfUi/yKRBy?= =?us-ascii?q?brysXNWC3oLmiqvtpdX6WEZhunmUWftKNhK4rAHc5IE9oLBJDeIP8CbPuWZCYO?= =?us-ascii?q?9MxGlldhq5lhf44dqsrtY4q3wD888784Z8dYmyP+FhFf0LRAghZmY4+MHmqzHd?= =?us-ascii?q?QgaVoHgRSGMbllxPGQeBpBX7WIrh9zD3vfdn2TWLeMjxQa0wVBy84KpxDhzlki?= =?us-ascii?q?EKM3g+6m6Twtd9iKNdvQKJuw10w4mSZpqccvV5YPDzZ9QfEEpcQY59XjJAD5j0?= =?us-ascii?q?O4sSEMIKOupVsIT0uVYUtl21Agz6V7Cn8SNBmnKjhf5y6O8mCwyTmVV4Eg=3D?= =?us-ascii?q?=3D?= X-IPAS-Result: =?us-ascii?q?A2F0BQCyAGhX/wHyM5BdHQGDIIFTvFgfhgCBNEwBAQEBAQE?= =?us-ascii?q?CAmIngjEPOTwBAQEBAQEjAg1mAiQTBgEBDCAMAgMJAhcpCAgDAS0LChgHCwUYB?= =?us-ascii?q?IgPr1CFKQEBBYwACI8GEQE1hUKYe44siVqFRo93VIF7DRyBTW2JE4E1AQEB?= Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea10.nsa.gov with ESMTP; 20 Jun 2016 14:45:03 +0000 Received: from prometheus.infosec.tycho.ncsc.mil (prometheus [192.168.25.40]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u5KEhDwr024180; Mon, 20 Jun 2016 10:44:40 -0400 Received: from tarius.tycho.ncsc.mil (tarius.infosec.tycho.ncsc.mil [144.51.242.1]) by prometheus.infosec.tycho.ncsc.mil (8.15.2/8.15.2) with ESMTP id u5KDbqqv090440 for ; Mon, 20 Jun 2016 09:37:52 -0400 Received: from goalie.tycho.ncsc.mil (goalie [144.51.242.250]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u5KDblbf013792 for ; Mon, 20 Jun 2016 09:37:52 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1DJAgDV8GdXfYO9+9heHAEBhHO4VoQBCBeGAIEzTAEBAQEBARMBARYzhH4qGQEBNwGBHCISiDCvToUpAQEFi1IpCJF9C0CCR5h7jiyPII93gk8NHIFNOzKKSAEBAQ X-IPAS-Result: A1DJAgDV8GdXfYO9+9heHAEBhHO4VoQBCBeGAIEzTAEBAQEBARMBARYzhH4qGQEBNwGBHCISiDCvToUpAQEFi1IpCJF9C0CCR5h7jiyPII93gk8NHIFNOzKKSAEBAQ X-IronPort-AV: E=Sophos;i="5.26,498,1459828800"; d="scan'208";a="5526700" Received: from emsm-gh1-uea10.corp.nsa.gov (HELO emsm-gh1-uea10.nsa.gov) ([10.208.41.36]) by goalie.tycho.ncsc.mil with ESMTP; 20 Jun 2016 09:37:52 -0400 IronPort-PHdr: =?us-ascii?q?9a23=3AQcWHbRdU7CBpBxwc46VO1hBelGMj4u6mDksu8pMi?= =?us-ascii?q?zoh2WeGdxc+4Zh7h7PlgxGXEQZ/co6odzbGG4uaxBCdevd6oizMrTt9lb1c9k8?= =?us-ascii?q?IYnggtUoauKHbQC7rUVRE8B9lIT1R//nu2YgB/Ecf6YEDO8DXptWZBUiv2OQc9?= =?us-ascii?q?HOnpAIma153xjLDjvcyOKFsUzBOGIppMbzyO5T3LsccXhYYwYo0Q8TDu5kVyRu?= =?us-ascii?q?JN2GlzLkiSlRuvru25/Zpk7jgC86l5r50IeezAcq85Vb1VCig9eyBwvZWz9EqL?= =?us-ascii?q?cQza4HYAXmgIugRHDhKD7xzgWJr19Czgua413CicIN2zVr0/RC6j87YuTRjklS?= =?us-ascii?q?MKHyA2/XuRicFqiq9f5hW7qFg32IPQYYeIJNJib6jdepUcXmMHUcFPBAJbBYbp?= =?us-ascii?q?T5YQR8YII+dVtMGpp0YRhRC5CQSzCerxxyVTwHTx2PtpgKwaDQja0Vl4TJo1u3?= =?us-ascii?q?POoYCwbf9KXA=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0EiAwBu8WdXfYO9+9heHAEBhHO4VoQBC?= =?us-ascii?q?BeGAIEzTAEBAQEBAQICDwEBFjMvgjEPOTwBAQEBAQEjAg1iKhkBATcBgRwiEog?= =?us-ascii?q?wr06FKQEBBYtTKQiRfQtAgkeYe44sjyCPd4JPDRyBTTsyikgBAQE?= X-IPAS-Result: =?us-ascii?q?A0EiAwBu8WdXfYO9+9heHAEBhHO4VoQBCBeGAIEzTAEBAQE?= =?us-ascii?q?BAQICDwEBFjMvgjEPOTwBAQEBAQEjAg1iKhkBATcBgRwiEogwr06FKQEBBYtTK?= =?us-ascii?q?QiRfQtAgkeYe44sjyCPd4JPDRyBTTsyikgBAQE?= X-IronPort-AV: E=Sophos;i="5.26,498,1459814400"; d="scan'208";a="14809869" Received: from mail.codeweavers.com ([216.251.189.131]) by emsm-gh1-uea10.nsa.gov with ESMTP/TLS/DHE-RSA-AES128-SHA; 20 Jun 2016 13:37:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=6377696661; h=Message-Id:Date:Subject:Cc:To:From; bh=pQRIjC1BIww0S/fMam0zPuI85eCzelpnBQSRCVOapq4=; b=RtX+PNCwFZ9m0m99U/6sTylSZPnocS72SCTkOEnSmsSkV2cpOPPePCxdRekQ65FUUhsdUBJTtu1v85ag/84xDMrt3UjnxmK2VinxhD++l2TEdNhPUSDrgd2NZEKsZX9Bi302hu3BnD0QQIV2Sy1IU0VOrJ/f8kyudEXz1Y4ycfo=; Received: from vpn38.vpn.mn.codeweavers.com ([10.69.139.38] helo=merlot.physics.ox.ac.uk) by mail.codeweavers.com with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1bEzOG-00028t-EY; Mon, 20 Jun 2016 08:37:30 -0500 Received: from daviesh by merlot.physics.ox.ac.uk with local (Exim 4.86_2) (envelope-from ) id 1bEzNs-0003LC-L9; Mon, 20 Jun 2016 14:37:00 +0100 From: Huw Davies To: netdev@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov Subject: [PATCH v4 07/19] netlabel: Add support for removing a CALIPSO DOI. Date: Mon, 20 Jun 2016 14:36:47 +0100 Message-Id: <1466429819-12707-8-git-send-email-huw@codeweavers.com> X-Mailer: git-send-email 2.7.4 X-BeenThere: selinux@tycho.nsa.gov X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Security-Enhanced Linux \(SELinux\) mailing list" List-Post: List-Help: MIME-Version: 1.0 Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" X-Virus-Scanned: ClamAV using ClamSMTP Remove a specified DOI through the NLBL_CALIPSO_C_REMOVE command. It requires the attribute: NLBL_CALIPSO_A_DOI. Signed-off-by: Huw Davies --- include/net/netlabel.h | 1 + net/ipv6/calipso.c | 48 +++++++++++++++++++++ net/netlabel/netlabel_calipso.c | 92 +++++++++++++++++++++++++++++++++++++++++ net/netlabel/netlabel_calipso.h | 9 ++++ 4 files changed, 150 insertions(+) diff --git a/include/net/netlabel.h b/include/net/netlabel.h index 2653d3a..2c0513b 100644 --- a/include/net/netlabel.h +++ b/include/net/netlabel.h @@ -237,6 +237,7 @@ struct netlbl_calipso_ops { int (*doi_add)(struct calipso_doi *doi_def, struct netlbl_audit *audit_info); void (*doi_free)(struct calipso_doi *doi_def); + int (*doi_remove)(u32 doi, struct netlbl_audit *audit_info); struct calipso_doi *(*doi_getdef)(u32 doi); void (*doi_putdef)(struct calipso_doi *doi_def); int (*doi_walk)(u32 *skip_cnt, diff --git a/net/ipv6/calipso.c b/net/ipv6/calipso.c index fa17c7a..d7df7a4 100644 --- a/net/ipv6/calipso.c +++ b/net/ipv6/calipso.c @@ -163,6 +163,53 @@ static void calipso_doi_free_rcu(struct rcu_head *entry) } /** + * calipso_doi_remove - Remove an existing DOI from the CALIPSO protocol engine + * @doi: the DOI value + * @audit_secid: the LSM secid to use in the audit message + * + * Description: + * Removes a DOI definition from the CALIPSO engine. The NetLabel routines will + * be called to release their own LSM domain mappings as well as our own + * domain list. Returns zero on success and negative values on failure. + * + */ +static int calipso_doi_remove(u32 doi, struct netlbl_audit *audit_info) +{ + int ret_val; + struct calipso_doi *doi_def; + struct audit_buffer *audit_buf; + + spin_lock(&calipso_doi_list_lock); + doi_def = calipso_doi_search(doi); + if (!doi_def) { + spin_unlock(&calipso_doi_list_lock); + ret_val = -ENOENT; + goto doi_remove_return; + } + if (!atomic_dec_and_test(&doi_def->refcount)) { + spin_unlock(&calipso_doi_list_lock); + ret_val = -EBUSY; + goto doi_remove_return; + } + list_del_rcu(&doi_def->list); + spin_unlock(&calipso_doi_list_lock); + + call_rcu(&doi_def->rcu, calipso_doi_free_rcu); + ret_val = 0; + +doi_remove_return: + audit_buf = netlbl_audit_start(AUDIT_MAC_CALIPSO_DEL, audit_info); + if (audit_buf) { + audit_log_format(audit_buf, + " calipso_doi=%u res=%u", + doi, ret_val == 0 ? 1 : 0); + audit_log_end(audit_buf); + } + + return ret_val; +} + +/** * calipso_doi_getdef - Returns a reference to a valid DOI definition * @doi: the DOI value * @@ -253,6 +300,7 @@ doi_walk_return: static const struct netlbl_calipso_ops ops = { .doi_add = calipso_doi_add, .doi_free = calipso_doi_free, + .doi_remove = calipso_doi_remove, .doi_getdef = calipso_doi_getdef, .doi_putdef = calipso_doi_putdef, .doi_walk = calipso_doi_walk, diff --git a/net/netlabel/netlabel_calipso.c b/net/netlabel/netlabel_calipso.c index 2141145..2857673 100644 --- a/net/netlabel/netlabel_calipso.c +++ b/net/netlabel/netlabel_calipso.c @@ -53,6 +53,12 @@ struct netlbl_calipso_doiwalk_arg { u32 seq; }; +/* Argument struct for netlbl_domhsh_walk() */ +struct netlbl_domhsh_walk_arg { + struct netlbl_audit *audit_info; + u32 doi; +}; + /* NetLabel Generic NETLINK CALIPSO family */ static struct genl_family netlbl_calipso_gnl_family = { .id = GENL_ID_GENERATE, @@ -257,6 +263,64 @@ static int netlbl_calipso_listall(struct sk_buff *skb, return skb->len; } +/** + * netlbl_calipso_remove_cb - netlbl_calipso_remove() callback for REMOVE + * @entry: LSM domain mapping entry + * @arg: the netlbl_domhsh_walk_arg structure + * + * Description: + * This function is intended for use by netlbl_calipso_remove() as the callback + * for the netlbl_domhsh_walk() function; it removes LSM domain map entries + * which are associated with the CALIPSO DOI specified in @arg. Returns zero on + * success, negative values on failure. + * + */ +static int netlbl_calipso_remove_cb(struct netlbl_dom_map *entry, void *arg) +{ + struct netlbl_domhsh_walk_arg *cb_arg = arg; + + if (entry->def.type == NETLBL_NLTYPE_CALIPSO && + entry->def.calipso->doi == cb_arg->doi) + return netlbl_domhsh_remove_entry(entry, cb_arg->audit_info); + + return 0; +} + +/** + * netlbl_calipso_remove - Handle a REMOVE message + * @skb: the NETLINK buffer + * @info: the Generic NETLINK info block + * + * Description: + * Process a user generated REMOVE message and respond accordingly. Returns + * zero on success, negative values on failure. + * + */ +static int netlbl_calipso_remove(struct sk_buff *skb, struct genl_info *info) +{ + int ret_val = -EINVAL; + struct netlbl_domhsh_walk_arg cb_arg; + struct netlbl_audit audit_info; + u32 skip_bkt = 0; + u32 skip_chain = 0; + + if (!info->attrs[NLBL_CALIPSO_A_DOI]) + return -EINVAL; + + netlbl_netlink_auditinfo(skb, &audit_info); + cb_arg.doi = nla_get_u32(info->attrs[NLBL_CALIPSO_A_DOI]); + cb_arg.audit_info = &audit_info; + ret_val = netlbl_domhsh_walk(&skip_bkt, &skip_chain, + netlbl_calipso_remove_cb, &cb_arg); + if (ret_val == 0 || ret_val == -ENOENT) { + ret_val = calipso_doi_remove(cb_arg.doi, &audit_info); + if (ret_val == 0) + atomic_dec(&netlabel_mgmt_protocount); + } + + return ret_val; +} + /* NetLabel Generic NETLINK Command Definitions */ @@ -269,6 +333,13 @@ static const struct genl_ops netlbl_calipso_ops[] = { .dumpit = NULL, }, { + .cmd = NLBL_CALIPSO_C_REMOVE, + .flags = GENL_ADMIN_PERM, + .policy = calipso_genl_policy, + .doit = netlbl_calipso_remove, + .dumpit = NULL, + }, + { .cmd = NLBL_CALIPSO_C_LIST, .flags = 0, .policy = calipso_genl_policy, @@ -363,6 +434,27 @@ void calipso_doi_free(struct calipso_doi *doi_def) } /** + * calipso_doi_remove - Remove an existing DOI from the CALIPSO protocol engine + * @doi: the DOI value + * @audit_secid: the LSM secid to use in the audit message + * + * Description: + * Removes a DOI definition from the CALIPSO engine. The NetLabel routines will + * be called to release their own LSM domain mappings as well as our own + * domain list. Returns zero on success and negative values on failure. + * + */ +int calipso_doi_remove(u32 doi, struct netlbl_audit *audit_info) +{ + int ret_val = -ENOMSG; + const struct netlbl_calipso_ops *ops = netlbl_calipso_ops_get(); + + if (ops) + ret_val = ops->doi_remove(doi, audit_info); + return ret_val; +} + +/** * calipso_doi_getdef - Returns a reference to a valid DOI definition * @doi: the DOI value * diff --git a/net/netlabel/netlabel_calipso.h b/net/netlabel/netlabel_calipso.h index 1f24174..ed78554 100644 --- a/net/netlabel/netlabel_calipso.h +++ b/net/netlabel/netlabel_calipso.h @@ -46,6 +46,14 @@ * * If using CALIPSO_MAP_PASS no additional attributes are required. * + * o REMOVE: + * Sent by an application to remove a specific DOI mapping table from the + * CALIPSO system. + * + * Required attributes: + * + * NLBL_CALIPSO_A_DOI + * * o LIST: * Sent by an application to list the details of a DOI definition. On * success the kernel should send a response using the following format. @@ -114,6 +122,7 @@ static inline int netlbl_calipso_genl_init(void) int calipso_doi_add(struct calipso_doi *doi_def, struct netlbl_audit *audit_info); void calipso_doi_free(struct calipso_doi *doi_def); +int calipso_doi_remove(u32 doi, struct netlbl_audit *audit_info); struct calipso_doi *calipso_doi_getdef(u32 doi); void calipso_doi_putdef(struct calipso_doi *doi_def); int calipso_doi_walk(u32 *skip_cnt,