Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 32f50cde authored by Paul Moore's avatar Paul Moore Committed by David S. Miller
Browse files

[NetLabel]: add audit support for configuration changes



This patch adds audit support to NetLabel, including six new audit message
types shown below.

 #define AUDIT_MAC_UNLBL_ACCEPT 1406
 #define AUDIT_MAC_UNLBL_DENY   1407
 #define AUDIT_MAC_CIPSOV4_ADD  1408
 #define AUDIT_MAC_CIPSOV4_DEL  1409
 #define AUDIT_MAC_MAP_ADD      1410
 #define AUDIT_MAC_MAP_DEL      1411

Signed-off-by: default avatarPaul Moore <paul.moore@hp.com>
Acked-by: default avatarJames Morris <jmorris@namei.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 8ea333eb
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -95,6 +95,12 @@
#define AUDIT_MAC_POLICY_LOAD	1403	/* Policy file load */
#define AUDIT_MAC_STATUS	1404	/* Changed enforcing,permissive,off */
#define AUDIT_MAC_CONFIG_CHANGE	1405	/* Changes to booleans */
#define AUDIT_MAC_UNLBL_ACCEPT	1406	/* NetLabel: allow unlabeled traffic */
#define AUDIT_MAC_UNLBL_DENY	1407	/* NetLabel: deny unlabeled traffic */
#define AUDIT_MAC_CIPSOV4_ADD	1408	/* NetLabel: add CIPSOv4 DOI entry */
#define AUDIT_MAC_CIPSOV4_DEL	1409	/* NetLabel: del CIPSOv4 DOI entry */
#define AUDIT_MAC_MAP_ADD	1410	/* NetLabel: add LSM domain mapping */
#define AUDIT_MAC_MAP_DEL	1411	/* NetLabel: del LSM domain mapping */

#define AUDIT_FIRST_KERN_ANOM_MSG   1700
#define AUDIT_LAST_KERN_ANOM_MSG    1799
+4 −1
Original line number Diff line number Diff line
@@ -128,7 +128,9 @@ extern int cipso_v4_rbm_strictvalid;

#ifdef CONFIG_NETLABEL
int cipso_v4_doi_add(struct cipso_v4_doi *doi_def);
int cipso_v4_doi_remove(u32 doi, void (*callback) (struct rcu_head * head));
int cipso_v4_doi_remove(u32 doi,
			u32 audit_secid,
			void (*callback) (struct rcu_head * head));
struct cipso_v4_doi *cipso_v4_doi_getdef(u32 doi);
int cipso_v4_doi_walk(u32 *skip_cnt,
		     int (*callback) (struct cipso_v4_doi *doi_def, void *arg),
@@ -143,6 +145,7 @@ static inline int cipso_v4_doi_add(struct cipso_v4_doi *doi_def)
}

static inline int cipso_v4_doi_remove(u32 doi,
				    u32 audit_secid,
				    void (*callback) (struct rcu_head * head))
{
	return 0;
+1 −1
Original line number Diff line number Diff line
@@ -96,7 +96,7 @@
struct netlbl_dom_map;

/* Domain mapping operations */
int netlbl_domhsh_remove(const char *domain);
int netlbl_domhsh_remove(const char *domain, u32 audit_secid);

/* LSM security attributes */
struct netlbl_lsm_cache {
+6 −2
Original line number Diff line number Diff line
@@ -474,6 +474,7 @@ int cipso_v4_doi_add(struct cipso_v4_doi *doi_def)
/**
 * cipso_v4_doi_remove - Remove an existing DOI from the CIPSO protocol engine
 * @doi: the DOI value
 * @audit_secid: the LSM secid to use in the audit message
 * @callback: the DOI cleanup/free callback
 *
 * Description:
@@ -483,7 +484,9 @@ int cipso_v4_doi_add(struct cipso_v4_doi *doi_def)
 * success and negative values on failure.
 *
 */
int cipso_v4_doi_remove(u32 doi, void (*callback) (struct rcu_head * head))
int cipso_v4_doi_remove(u32 doi,
			u32 audit_secid,
			void (*callback) (struct rcu_head * head))
{
	struct cipso_v4_doi *doi_def;
	struct cipso_v4_domhsh_entry *dom_iter;
@@ -502,7 +505,8 @@ int cipso_v4_doi_remove(u32 doi, void (*callback) (struct rcu_head * head))
		spin_unlock(&cipso_v4_doi_list_lock);
		list_for_each_entry_rcu(dom_iter, &doi_def->dom_list, list)
			if (dom_iter->valid)
				netlbl_domhsh_remove(dom_iter->domain);
				netlbl_domhsh_remove(dom_iter->domain,
						     audit_secid);
		cipso_v4_cache_invalidate();
		rcu_read_unlock();

+33 −10
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
#include <linux/socket.h>
#include <linux/string.h>
#include <linux/skbuff.h>
#include <linux/audit.h>
#include <net/sock.h>
#include <net/netlink.h>
#include <net/genetlink.h>
@@ -162,8 +163,7 @@ static int netlbl_cipsov4_add_std(struct genl_info *info)
	int nla_a_rem;
	int nla_b_rem;

	if (!info->attrs[NLBL_CIPSOV4_A_DOI] ||
	    !info->attrs[NLBL_CIPSOV4_A_TAGLST] ||
	if (!info->attrs[NLBL_CIPSOV4_A_TAGLST] ||
	    !info->attrs[NLBL_CIPSOV4_A_MLSLVLLST])
		return -EINVAL;

@@ -344,8 +344,7 @@ static int netlbl_cipsov4_add_pass(struct genl_info *info)
	int ret_val;
	struct cipso_v4_doi *doi_def = NULL;

	if (!info->attrs[NLBL_CIPSOV4_A_DOI] ||
	    !info->attrs[NLBL_CIPSOV4_A_TAGLST])
	if (!info->attrs[NLBL_CIPSOV4_A_TAGLST])
		return -EINVAL;

	doi_def = kmalloc(sizeof(*doi_def), GFP_KERNEL);
@@ -381,21 +380,35 @@ static int netlbl_cipsov4_add(struct sk_buff *skb, struct genl_info *info)

{
	int ret_val = -EINVAL;
	u32 map_type;
	u32 type;
	u32 doi;
	const char *type_str = "(unknown)";
	struct audit_buffer *audit_buf;

	if (!info->attrs[NLBL_CIPSOV4_A_MTYPE])
	if (!info->attrs[NLBL_CIPSOV4_A_DOI] ||
	    !info->attrs[NLBL_CIPSOV4_A_MTYPE])
		return -EINVAL;

	map_type = nla_get_u32(info->attrs[NLBL_CIPSOV4_A_MTYPE]);
	switch (map_type) {
	type = nla_get_u32(info->attrs[NLBL_CIPSOV4_A_MTYPE]);
	switch (type) {
	case CIPSO_V4_MAP_STD:
		type_str = "std";
		ret_val = netlbl_cipsov4_add_std(info);
		break;
	case CIPSO_V4_MAP_PASS:
		type_str = "pass";
		ret_val = netlbl_cipsov4_add_pass(info);
		break;
	}

	if (ret_val == 0) {
		doi = nla_get_u32(info->attrs[NLBL_CIPSOV4_A_DOI]);
		audit_buf = netlbl_audit_start_common(AUDIT_MAC_CIPSOV4_ADD,
						      NETLINK_CB(skb).sid);
		audit_log_format(audit_buf, " doi=%u type=%s", doi, type_str);
		audit_log_end(audit_buf);
	}

	return ret_val;
}

@@ -653,11 +666,21 @@ static int netlbl_cipsov4_listall(struct sk_buff *skb,
static int netlbl_cipsov4_remove(struct sk_buff *skb, struct genl_info *info)
{
	int ret_val = -EINVAL;
	u32 doi;
	u32 doi = 0;
	struct audit_buffer *audit_buf;

	if (info->attrs[NLBL_CIPSOV4_A_DOI]) {
		doi = nla_get_u32(info->attrs[NLBL_CIPSOV4_A_DOI]);
		ret_val = cipso_v4_doi_remove(doi, netlbl_cipsov4_doi_free);
		ret_val = cipso_v4_doi_remove(doi,
					      NETLINK_CB(skb).sid,
					      netlbl_cipsov4_doi_free);
	}

	if (ret_val == 0) {
		audit_buf = netlbl_audit_start_common(AUDIT_MAC_CIPSOV4_DEL,
						      NETLINK_CB(skb).sid);
		audit_log_format(audit_buf, " doi=%u", doi);
		audit_log_end(audit_buf);
	}

	return ret_val;
Loading