162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * NetLabel System 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * The NetLabel system manages static and dynamic label mappings for network 662306a36Sopenharmony_ci * protocols such as CIPSO and RIPSO. 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * Author: Paul Moore <paul@paul-moore.com> 962306a36Sopenharmony_ci */ 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci/* 1262306a36Sopenharmony_ci * (c) Copyright Hewlett-Packard Development Company, L.P., 2006, 2008 1362306a36Sopenharmony_ci */ 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#ifndef _NETLABEL_H 1662306a36Sopenharmony_ci#define _NETLABEL_H 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci#include <linux/types.h> 1962306a36Sopenharmony_ci#include <linux/slab.h> 2062306a36Sopenharmony_ci#include <linux/net.h> 2162306a36Sopenharmony_ci#include <linux/skbuff.h> 2262306a36Sopenharmony_ci#include <linux/in.h> 2362306a36Sopenharmony_ci#include <linux/in6.h> 2462306a36Sopenharmony_ci#include <net/netlink.h> 2562306a36Sopenharmony_ci#include <net/request_sock.h> 2662306a36Sopenharmony_ci#include <linux/refcount.h> 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_cistruct cipso_v4_doi; 2962306a36Sopenharmony_cistruct calipso_doi; 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci/* 3262306a36Sopenharmony_ci * NetLabel - A management interface for maintaining network packet label 3362306a36Sopenharmony_ci * mapping tables for explicit packet labling protocols. 3462306a36Sopenharmony_ci * 3562306a36Sopenharmony_ci * Network protocols such as CIPSO and RIPSO require a label translation layer 3662306a36Sopenharmony_ci * to convert the label on the packet into something meaningful on the host 3762306a36Sopenharmony_ci * machine. In the current Linux implementation these mapping tables live 3862306a36Sopenharmony_ci * inside the kernel; NetLabel provides a mechanism for user space applications 3962306a36Sopenharmony_ci * to manage these mapping tables. 4062306a36Sopenharmony_ci * 4162306a36Sopenharmony_ci * NetLabel makes use of the Generic NETLINK mechanism as a transport layer to 4262306a36Sopenharmony_ci * send messages between kernel and user space. The general format of a 4362306a36Sopenharmony_ci * NetLabel message is shown below: 4462306a36Sopenharmony_ci * 4562306a36Sopenharmony_ci * +-----------------+-------------------+--------- --- -- - 4662306a36Sopenharmony_ci * | struct nlmsghdr | struct genlmsghdr | payload 4762306a36Sopenharmony_ci * +-----------------+-------------------+--------- --- -- - 4862306a36Sopenharmony_ci * 4962306a36Sopenharmony_ci * The 'nlmsghdr' and 'genlmsghdr' structs should be dealt with like normal. 5062306a36Sopenharmony_ci * The payload is dependent on the subsystem specified in the 5162306a36Sopenharmony_ci * 'nlmsghdr->nlmsg_type' and should be defined below, supporting functions 5262306a36Sopenharmony_ci * should be defined in the corresponding net/netlabel/netlabel_<subsys>.h|c 5362306a36Sopenharmony_ci * file. All of the fields in the NetLabel payload are NETLINK attributes, see 5462306a36Sopenharmony_ci * the include/net/netlink.h file for more information on NETLINK attributes. 5562306a36Sopenharmony_ci * 5662306a36Sopenharmony_ci */ 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci/* 5962306a36Sopenharmony_ci * NetLabel NETLINK protocol 6062306a36Sopenharmony_ci */ 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci/* NetLabel NETLINK protocol version 6362306a36Sopenharmony_ci * 1: initial version 6462306a36Sopenharmony_ci * 2: added static labels for unlabeled connections 6562306a36Sopenharmony_ci * 3: network selectors added to the NetLabel/LSM domain mapping and the 6662306a36Sopenharmony_ci * CIPSO_V4_MAP_LOCAL CIPSO mapping was added 6762306a36Sopenharmony_ci */ 6862306a36Sopenharmony_ci#define NETLBL_PROTO_VERSION 3 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci/* NetLabel NETLINK types/families */ 7162306a36Sopenharmony_ci#define NETLBL_NLTYPE_NONE 0 7262306a36Sopenharmony_ci#define NETLBL_NLTYPE_MGMT 1 7362306a36Sopenharmony_ci#define NETLBL_NLTYPE_MGMT_NAME "NLBL_MGMT" 7462306a36Sopenharmony_ci#define NETLBL_NLTYPE_RIPSO 2 7562306a36Sopenharmony_ci#define NETLBL_NLTYPE_RIPSO_NAME "NLBL_RIPSO" 7662306a36Sopenharmony_ci#define NETLBL_NLTYPE_CIPSOV4 3 7762306a36Sopenharmony_ci#define NETLBL_NLTYPE_CIPSOV4_NAME "NLBL_CIPSOv4" 7862306a36Sopenharmony_ci#define NETLBL_NLTYPE_CIPSOV6 4 7962306a36Sopenharmony_ci#define NETLBL_NLTYPE_CIPSOV6_NAME "NLBL_CIPSOv6" 8062306a36Sopenharmony_ci#define NETLBL_NLTYPE_UNLABELED 5 8162306a36Sopenharmony_ci#define NETLBL_NLTYPE_UNLABELED_NAME "NLBL_UNLBL" 8262306a36Sopenharmony_ci#define NETLBL_NLTYPE_ADDRSELECT 6 8362306a36Sopenharmony_ci#define NETLBL_NLTYPE_ADDRSELECT_NAME "NLBL_ADRSEL" 8462306a36Sopenharmony_ci#define NETLBL_NLTYPE_CALIPSO 7 8562306a36Sopenharmony_ci#define NETLBL_NLTYPE_CALIPSO_NAME "NLBL_CALIPSO" 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci/* 8862306a36Sopenharmony_ci * NetLabel - Kernel API for accessing the network packet label mappings. 8962306a36Sopenharmony_ci * 9062306a36Sopenharmony_ci * The following functions are provided for use by other kernel modules, 9162306a36Sopenharmony_ci * specifically kernel LSM modules, to provide a consistent, transparent API 9262306a36Sopenharmony_ci * for dealing with explicit packet labeling protocols such as CIPSO and 9362306a36Sopenharmony_ci * RIPSO. The functions defined here are implemented in the 9462306a36Sopenharmony_ci * net/netlabel/netlabel_kapi.c file. 9562306a36Sopenharmony_ci * 9662306a36Sopenharmony_ci */ 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci/* NetLabel audit information */ 9962306a36Sopenharmony_cistruct netlbl_audit { 10062306a36Sopenharmony_ci u32 secid; 10162306a36Sopenharmony_ci kuid_t loginuid; 10262306a36Sopenharmony_ci unsigned int sessionid; 10362306a36Sopenharmony_ci}; 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci/* 10662306a36Sopenharmony_ci * LSM security attributes 10762306a36Sopenharmony_ci */ 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ci/** 11062306a36Sopenharmony_ci * struct netlbl_lsm_cache - NetLabel LSM security attribute cache 11162306a36Sopenharmony_ci * @refcount: atomic reference counter 11262306a36Sopenharmony_ci * @free: LSM supplied function to free the cache data 11362306a36Sopenharmony_ci * @data: LSM supplied cache data 11462306a36Sopenharmony_ci * 11562306a36Sopenharmony_ci * Description: 11662306a36Sopenharmony_ci * This structure is provided for LSMs which wish to make use of the NetLabel 11762306a36Sopenharmony_ci * caching mechanism to store LSM specific data/attributes in the NetLabel 11862306a36Sopenharmony_ci * cache. If the LSM has to perform a lot of translation from the NetLabel 11962306a36Sopenharmony_ci * security attributes into it's own internal representation then the cache 12062306a36Sopenharmony_ci * mechanism can provide a way to eliminate some or all of that translation 12162306a36Sopenharmony_ci * overhead on a cache hit. 12262306a36Sopenharmony_ci * 12362306a36Sopenharmony_ci */ 12462306a36Sopenharmony_cistruct netlbl_lsm_cache { 12562306a36Sopenharmony_ci refcount_t refcount; 12662306a36Sopenharmony_ci void (*free) (const void *data); 12762306a36Sopenharmony_ci void *data; 12862306a36Sopenharmony_ci}; 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ci/** 13162306a36Sopenharmony_ci * struct netlbl_lsm_catmap - NetLabel LSM secattr category bitmap 13262306a36Sopenharmony_ci * @startbit: the value of the lowest order bit in the bitmap 13362306a36Sopenharmony_ci * @bitmap: the category bitmap 13462306a36Sopenharmony_ci * @next: pointer to the next bitmap "node" or NULL 13562306a36Sopenharmony_ci * 13662306a36Sopenharmony_ci * Description: 13762306a36Sopenharmony_ci * This structure is used to represent category bitmaps. Due to the large 13862306a36Sopenharmony_ci * number of categories supported by most labeling protocols it is not 13962306a36Sopenharmony_ci * practical to transfer a full bitmap internally so NetLabel adopts a sparse 14062306a36Sopenharmony_ci * bitmap structure modeled after SELinux's ebitmap structure. 14162306a36Sopenharmony_ci * The catmap bitmap field MUST be a power of two in length and large 14262306a36Sopenharmony_ci * enough to hold at least 240 bits. Special care (i.e. check the code!) 14362306a36Sopenharmony_ci * should be used when changing these values as the LSM implementation 14462306a36Sopenharmony_ci * probably has functions which rely on the sizes of these types to speed 14562306a36Sopenharmony_ci * processing. 14662306a36Sopenharmony_ci * 14762306a36Sopenharmony_ci */ 14862306a36Sopenharmony_ci#define NETLBL_CATMAP_MAPTYPE u64 14962306a36Sopenharmony_ci#define NETLBL_CATMAP_MAPCNT 4 15062306a36Sopenharmony_ci#define NETLBL_CATMAP_MAPSIZE (sizeof(NETLBL_CATMAP_MAPTYPE) * 8) 15162306a36Sopenharmony_ci#define NETLBL_CATMAP_SIZE (NETLBL_CATMAP_MAPSIZE * \ 15262306a36Sopenharmony_ci NETLBL_CATMAP_MAPCNT) 15362306a36Sopenharmony_ci#define NETLBL_CATMAP_BIT (NETLBL_CATMAP_MAPTYPE)0x01 15462306a36Sopenharmony_cistruct netlbl_lsm_catmap { 15562306a36Sopenharmony_ci u32 startbit; 15662306a36Sopenharmony_ci NETLBL_CATMAP_MAPTYPE bitmap[NETLBL_CATMAP_MAPCNT]; 15762306a36Sopenharmony_ci struct netlbl_lsm_catmap *next; 15862306a36Sopenharmony_ci}; 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_ci/** 16162306a36Sopenharmony_ci * struct netlbl_lsm_secattr - NetLabel LSM security attributes 16262306a36Sopenharmony_ci * @flags: indicate structure attributes, see NETLBL_SECATTR_* 16362306a36Sopenharmony_ci * @type: indicate the NLTYPE of the attributes 16462306a36Sopenharmony_ci * @domain: the NetLabel LSM domain 16562306a36Sopenharmony_ci * @cache: NetLabel LSM specific cache 16662306a36Sopenharmony_ci * @attr.mls: MLS sensitivity label 16762306a36Sopenharmony_ci * @attr.mls.cat: MLS category bitmap 16862306a36Sopenharmony_ci * @attr.mls.lvl: MLS sensitivity level 16962306a36Sopenharmony_ci * @attr.secid: LSM specific secid token 17062306a36Sopenharmony_ci * 17162306a36Sopenharmony_ci * Description: 17262306a36Sopenharmony_ci * This structure is used to pass security attributes between NetLabel and the 17362306a36Sopenharmony_ci * LSM modules. The flags field is used to specify which fields within the 17462306a36Sopenharmony_ci * struct are valid and valid values can be created by bitwise OR'ing the 17562306a36Sopenharmony_ci * NETLBL_SECATTR_* defines. The domain field is typically set by the LSM to 17662306a36Sopenharmony_ci * specify domain specific configuration settings and is not usually used by 17762306a36Sopenharmony_ci * NetLabel itself when returning security attributes to the LSM. 17862306a36Sopenharmony_ci * 17962306a36Sopenharmony_ci */ 18062306a36Sopenharmony_cistruct netlbl_lsm_secattr { 18162306a36Sopenharmony_ci u32 flags; 18262306a36Sopenharmony_ci /* bitmap values for 'flags' */ 18362306a36Sopenharmony_ci#define NETLBL_SECATTR_NONE 0x00000000 18462306a36Sopenharmony_ci#define NETLBL_SECATTR_DOMAIN 0x00000001 18562306a36Sopenharmony_ci#define NETLBL_SECATTR_DOMAIN_CPY (NETLBL_SECATTR_DOMAIN | \ 18662306a36Sopenharmony_ci NETLBL_SECATTR_FREE_DOMAIN) 18762306a36Sopenharmony_ci#define NETLBL_SECATTR_CACHE 0x00000002 18862306a36Sopenharmony_ci#define NETLBL_SECATTR_MLS_LVL 0x00000004 18962306a36Sopenharmony_ci#define NETLBL_SECATTR_MLS_CAT 0x00000008 19062306a36Sopenharmony_ci#define NETLBL_SECATTR_SECID 0x00000010 19162306a36Sopenharmony_ci /* bitmap meta-values for 'flags' */ 19262306a36Sopenharmony_ci#define NETLBL_SECATTR_FREE_DOMAIN 0x01000000 19362306a36Sopenharmony_ci#define NETLBL_SECATTR_CACHEABLE (NETLBL_SECATTR_MLS_LVL | \ 19462306a36Sopenharmony_ci NETLBL_SECATTR_MLS_CAT | \ 19562306a36Sopenharmony_ci NETLBL_SECATTR_SECID) 19662306a36Sopenharmony_ci u32 type; 19762306a36Sopenharmony_ci char *domain; 19862306a36Sopenharmony_ci struct netlbl_lsm_cache *cache; 19962306a36Sopenharmony_ci struct { 20062306a36Sopenharmony_ci struct { 20162306a36Sopenharmony_ci struct netlbl_lsm_catmap *cat; 20262306a36Sopenharmony_ci u32 lvl; 20362306a36Sopenharmony_ci } mls; 20462306a36Sopenharmony_ci u32 secid; 20562306a36Sopenharmony_ci } attr; 20662306a36Sopenharmony_ci}; 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_ci/** 20962306a36Sopenharmony_ci * struct netlbl_calipso_ops - NetLabel CALIPSO operations 21062306a36Sopenharmony_ci * @doi_add: add a CALIPSO DOI 21162306a36Sopenharmony_ci * @doi_free: free a CALIPSO DOI 21262306a36Sopenharmony_ci * @doi_getdef: returns a reference to a DOI 21362306a36Sopenharmony_ci * @doi_putdef: releases a reference of a DOI 21462306a36Sopenharmony_ci * @doi_walk: enumerate the DOI list 21562306a36Sopenharmony_ci * @sock_getattr: retrieve the socket's attr 21662306a36Sopenharmony_ci * @sock_setattr: set the socket's attr 21762306a36Sopenharmony_ci * @sock_delattr: remove the socket's attr 21862306a36Sopenharmony_ci * @req_setattr: set the req socket's attr 21962306a36Sopenharmony_ci * @req_delattr: remove the req socket's attr 22062306a36Sopenharmony_ci * @opt_getattr: retrieve attr from memory block 22162306a36Sopenharmony_ci * @skbuff_optptr: find option in packet 22262306a36Sopenharmony_ci * @skbuff_setattr: set the skbuff's attr 22362306a36Sopenharmony_ci * @skbuff_delattr: remove the skbuff's attr 22462306a36Sopenharmony_ci * @cache_invalidate: invalidate cache 22562306a36Sopenharmony_ci * @cache_add: add cache entry 22662306a36Sopenharmony_ci * 22762306a36Sopenharmony_ci * Description: 22862306a36Sopenharmony_ci * This structure is filled out by the CALIPSO engine and passed 22962306a36Sopenharmony_ci * to the NetLabel core via a call to netlbl_calipso_ops_register(). 23062306a36Sopenharmony_ci * It enables the CALIPSO engine (and hence IPv6) to be compiled 23162306a36Sopenharmony_ci * as a module. 23262306a36Sopenharmony_ci */ 23362306a36Sopenharmony_cistruct netlbl_calipso_ops { 23462306a36Sopenharmony_ci int (*doi_add)(struct calipso_doi *doi_def, 23562306a36Sopenharmony_ci struct netlbl_audit *audit_info); 23662306a36Sopenharmony_ci void (*doi_free)(struct calipso_doi *doi_def); 23762306a36Sopenharmony_ci int (*doi_remove)(u32 doi, struct netlbl_audit *audit_info); 23862306a36Sopenharmony_ci struct calipso_doi *(*doi_getdef)(u32 doi); 23962306a36Sopenharmony_ci void (*doi_putdef)(struct calipso_doi *doi_def); 24062306a36Sopenharmony_ci int (*doi_walk)(u32 *skip_cnt, 24162306a36Sopenharmony_ci int (*callback)(struct calipso_doi *doi_def, void *arg), 24262306a36Sopenharmony_ci void *cb_arg); 24362306a36Sopenharmony_ci int (*sock_getattr)(struct sock *sk, 24462306a36Sopenharmony_ci struct netlbl_lsm_secattr *secattr); 24562306a36Sopenharmony_ci int (*sock_setattr)(struct sock *sk, 24662306a36Sopenharmony_ci const struct calipso_doi *doi_def, 24762306a36Sopenharmony_ci const struct netlbl_lsm_secattr *secattr); 24862306a36Sopenharmony_ci void (*sock_delattr)(struct sock *sk); 24962306a36Sopenharmony_ci int (*req_setattr)(struct request_sock *req, 25062306a36Sopenharmony_ci const struct calipso_doi *doi_def, 25162306a36Sopenharmony_ci const struct netlbl_lsm_secattr *secattr); 25262306a36Sopenharmony_ci void (*req_delattr)(struct request_sock *req); 25362306a36Sopenharmony_ci int (*opt_getattr)(const unsigned char *calipso, 25462306a36Sopenharmony_ci struct netlbl_lsm_secattr *secattr); 25562306a36Sopenharmony_ci unsigned char *(*skbuff_optptr)(const struct sk_buff *skb); 25662306a36Sopenharmony_ci int (*skbuff_setattr)(struct sk_buff *skb, 25762306a36Sopenharmony_ci const struct calipso_doi *doi_def, 25862306a36Sopenharmony_ci const struct netlbl_lsm_secattr *secattr); 25962306a36Sopenharmony_ci int (*skbuff_delattr)(struct sk_buff *skb); 26062306a36Sopenharmony_ci void (*cache_invalidate)(void); 26162306a36Sopenharmony_ci int (*cache_add)(const unsigned char *calipso_ptr, 26262306a36Sopenharmony_ci const struct netlbl_lsm_secattr *secattr); 26362306a36Sopenharmony_ci}; 26462306a36Sopenharmony_ci 26562306a36Sopenharmony_ci/* 26662306a36Sopenharmony_ci * LSM security attribute operations (inline) 26762306a36Sopenharmony_ci */ 26862306a36Sopenharmony_ci 26962306a36Sopenharmony_ci/** 27062306a36Sopenharmony_ci * netlbl_secattr_cache_alloc - Allocate and initialize a secattr cache 27162306a36Sopenharmony_ci * @flags: the memory allocation flags 27262306a36Sopenharmony_ci * 27362306a36Sopenharmony_ci * Description: 27462306a36Sopenharmony_ci * Allocate and initialize a netlbl_lsm_cache structure. Returns a pointer 27562306a36Sopenharmony_ci * on success, NULL on failure. 27662306a36Sopenharmony_ci * 27762306a36Sopenharmony_ci */ 27862306a36Sopenharmony_cistatic inline struct netlbl_lsm_cache *netlbl_secattr_cache_alloc(gfp_t flags) 27962306a36Sopenharmony_ci{ 28062306a36Sopenharmony_ci struct netlbl_lsm_cache *cache; 28162306a36Sopenharmony_ci 28262306a36Sopenharmony_ci cache = kzalloc(sizeof(*cache), flags); 28362306a36Sopenharmony_ci if (cache) 28462306a36Sopenharmony_ci refcount_set(&cache->refcount, 1); 28562306a36Sopenharmony_ci return cache; 28662306a36Sopenharmony_ci} 28762306a36Sopenharmony_ci 28862306a36Sopenharmony_ci/** 28962306a36Sopenharmony_ci * netlbl_secattr_cache_free - Frees a netlbl_lsm_cache struct 29062306a36Sopenharmony_ci * @cache: the struct to free 29162306a36Sopenharmony_ci * 29262306a36Sopenharmony_ci * Description: 29362306a36Sopenharmony_ci * Frees @secattr including all of the internal buffers. 29462306a36Sopenharmony_ci * 29562306a36Sopenharmony_ci */ 29662306a36Sopenharmony_cistatic inline void netlbl_secattr_cache_free(struct netlbl_lsm_cache *cache) 29762306a36Sopenharmony_ci{ 29862306a36Sopenharmony_ci if (!refcount_dec_and_test(&cache->refcount)) 29962306a36Sopenharmony_ci return; 30062306a36Sopenharmony_ci 30162306a36Sopenharmony_ci if (cache->free) 30262306a36Sopenharmony_ci cache->free(cache->data); 30362306a36Sopenharmony_ci kfree(cache); 30462306a36Sopenharmony_ci} 30562306a36Sopenharmony_ci 30662306a36Sopenharmony_ci/** 30762306a36Sopenharmony_ci * netlbl_catmap_alloc - Allocate a LSM secattr catmap 30862306a36Sopenharmony_ci * @flags: memory allocation flags 30962306a36Sopenharmony_ci * 31062306a36Sopenharmony_ci * Description: 31162306a36Sopenharmony_ci * Allocate memory for a LSM secattr catmap, returns a pointer on success, NULL 31262306a36Sopenharmony_ci * on failure. 31362306a36Sopenharmony_ci * 31462306a36Sopenharmony_ci */ 31562306a36Sopenharmony_cistatic inline struct netlbl_lsm_catmap *netlbl_catmap_alloc(gfp_t flags) 31662306a36Sopenharmony_ci{ 31762306a36Sopenharmony_ci return kzalloc(sizeof(struct netlbl_lsm_catmap), flags); 31862306a36Sopenharmony_ci} 31962306a36Sopenharmony_ci 32062306a36Sopenharmony_ci/** 32162306a36Sopenharmony_ci * netlbl_catmap_free - Free a LSM secattr catmap 32262306a36Sopenharmony_ci * @catmap: the category bitmap 32362306a36Sopenharmony_ci * 32462306a36Sopenharmony_ci * Description: 32562306a36Sopenharmony_ci * Free a LSM secattr catmap. 32662306a36Sopenharmony_ci * 32762306a36Sopenharmony_ci */ 32862306a36Sopenharmony_cistatic inline void netlbl_catmap_free(struct netlbl_lsm_catmap *catmap) 32962306a36Sopenharmony_ci{ 33062306a36Sopenharmony_ci struct netlbl_lsm_catmap *iter; 33162306a36Sopenharmony_ci 33262306a36Sopenharmony_ci while (catmap) { 33362306a36Sopenharmony_ci iter = catmap; 33462306a36Sopenharmony_ci catmap = catmap->next; 33562306a36Sopenharmony_ci kfree(iter); 33662306a36Sopenharmony_ci } 33762306a36Sopenharmony_ci} 33862306a36Sopenharmony_ci 33962306a36Sopenharmony_ci/** 34062306a36Sopenharmony_ci * netlbl_secattr_init - Initialize a netlbl_lsm_secattr struct 34162306a36Sopenharmony_ci * @secattr: the struct to initialize 34262306a36Sopenharmony_ci * 34362306a36Sopenharmony_ci * Description: 34462306a36Sopenharmony_ci * Initialize an already allocated netlbl_lsm_secattr struct. 34562306a36Sopenharmony_ci * 34662306a36Sopenharmony_ci */ 34762306a36Sopenharmony_cistatic inline void netlbl_secattr_init(struct netlbl_lsm_secattr *secattr) 34862306a36Sopenharmony_ci{ 34962306a36Sopenharmony_ci memset(secattr, 0, sizeof(*secattr)); 35062306a36Sopenharmony_ci} 35162306a36Sopenharmony_ci 35262306a36Sopenharmony_ci/** 35362306a36Sopenharmony_ci * netlbl_secattr_destroy - Clears a netlbl_lsm_secattr struct 35462306a36Sopenharmony_ci * @secattr: the struct to clear 35562306a36Sopenharmony_ci * 35662306a36Sopenharmony_ci * Description: 35762306a36Sopenharmony_ci * Destroys the @secattr struct, including freeing all of the internal buffers. 35862306a36Sopenharmony_ci * The struct must be reset with a call to netlbl_secattr_init() before reuse. 35962306a36Sopenharmony_ci * 36062306a36Sopenharmony_ci */ 36162306a36Sopenharmony_cistatic inline void netlbl_secattr_destroy(struct netlbl_lsm_secattr *secattr) 36262306a36Sopenharmony_ci{ 36362306a36Sopenharmony_ci if (secattr->flags & NETLBL_SECATTR_FREE_DOMAIN) 36462306a36Sopenharmony_ci kfree(secattr->domain); 36562306a36Sopenharmony_ci if (secattr->flags & NETLBL_SECATTR_CACHE) 36662306a36Sopenharmony_ci netlbl_secattr_cache_free(secattr->cache); 36762306a36Sopenharmony_ci if (secattr->flags & NETLBL_SECATTR_MLS_CAT) 36862306a36Sopenharmony_ci netlbl_catmap_free(secattr->attr.mls.cat); 36962306a36Sopenharmony_ci} 37062306a36Sopenharmony_ci 37162306a36Sopenharmony_ci/** 37262306a36Sopenharmony_ci * netlbl_secattr_alloc - Allocate and initialize a netlbl_lsm_secattr struct 37362306a36Sopenharmony_ci * @flags: the memory allocation flags 37462306a36Sopenharmony_ci * 37562306a36Sopenharmony_ci * Description: 37662306a36Sopenharmony_ci * Allocate and initialize a netlbl_lsm_secattr struct. Returns a valid 37762306a36Sopenharmony_ci * pointer on success, or NULL on failure. 37862306a36Sopenharmony_ci * 37962306a36Sopenharmony_ci */ 38062306a36Sopenharmony_cistatic inline struct netlbl_lsm_secattr *netlbl_secattr_alloc(gfp_t flags) 38162306a36Sopenharmony_ci{ 38262306a36Sopenharmony_ci return kzalloc(sizeof(struct netlbl_lsm_secattr), flags); 38362306a36Sopenharmony_ci} 38462306a36Sopenharmony_ci 38562306a36Sopenharmony_ci/** 38662306a36Sopenharmony_ci * netlbl_secattr_free - Frees a netlbl_lsm_secattr struct 38762306a36Sopenharmony_ci * @secattr: the struct to free 38862306a36Sopenharmony_ci * 38962306a36Sopenharmony_ci * Description: 39062306a36Sopenharmony_ci * Frees @secattr including all of the internal buffers. 39162306a36Sopenharmony_ci * 39262306a36Sopenharmony_ci */ 39362306a36Sopenharmony_cistatic inline void netlbl_secattr_free(struct netlbl_lsm_secattr *secattr) 39462306a36Sopenharmony_ci{ 39562306a36Sopenharmony_ci netlbl_secattr_destroy(secattr); 39662306a36Sopenharmony_ci kfree(secattr); 39762306a36Sopenharmony_ci} 39862306a36Sopenharmony_ci 39962306a36Sopenharmony_ci#ifdef CONFIG_NETLABEL 40062306a36Sopenharmony_ci/* 40162306a36Sopenharmony_ci * LSM configuration operations 40262306a36Sopenharmony_ci */ 40362306a36Sopenharmony_ciint netlbl_cfg_map_del(const char *domain, 40462306a36Sopenharmony_ci u16 family, 40562306a36Sopenharmony_ci const void *addr, 40662306a36Sopenharmony_ci const void *mask, 40762306a36Sopenharmony_ci struct netlbl_audit *audit_info); 40862306a36Sopenharmony_ciint netlbl_cfg_unlbl_map_add(const char *domain, 40962306a36Sopenharmony_ci u16 family, 41062306a36Sopenharmony_ci const void *addr, 41162306a36Sopenharmony_ci const void *mask, 41262306a36Sopenharmony_ci struct netlbl_audit *audit_info); 41362306a36Sopenharmony_ciint netlbl_cfg_unlbl_static_add(struct net *net, 41462306a36Sopenharmony_ci const char *dev_name, 41562306a36Sopenharmony_ci const void *addr, 41662306a36Sopenharmony_ci const void *mask, 41762306a36Sopenharmony_ci u16 family, 41862306a36Sopenharmony_ci u32 secid, 41962306a36Sopenharmony_ci struct netlbl_audit *audit_info); 42062306a36Sopenharmony_ciint netlbl_cfg_unlbl_static_del(struct net *net, 42162306a36Sopenharmony_ci const char *dev_name, 42262306a36Sopenharmony_ci const void *addr, 42362306a36Sopenharmony_ci const void *mask, 42462306a36Sopenharmony_ci u16 family, 42562306a36Sopenharmony_ci struct netlbl_audit *audit_info); 42662306a36Sopenharmony_ciint netlbl_cfg_cipsov4_add(struct cipso_v4_doi *doi_def, 42762306a36Sopenharmony_ci struct netlbl_audit *audit_info); 42862306a36Sopenharmony_civoid netlbl_cfg_cipsov4_del(u32 doi, struct netlbl_audit *audit_info); 42962306a36Sopenharmony_ciint netlbl_cfg_cipsov4_map_add(u32 doi, 43062306a36Sopenharmony_ci const char *domain, 43162306a36Sopenharmony_ci const struct in_addr *addr, 43262306a36Sopenharmony_ci const struct in_addr *mask, 43362306a36Sopenharmony_ci struct netlbl_audit *audit_info); 43462306a36Sopenharmony_ciint netlbl_cfg_calipso_add(struct calipso_doi *doi_def, 43562306a36Sopenharmony_ci struct netlbl_audit *audit_info); 43662306a36Sopenharmony_civoid netlbl_cfg_calipso_del(u32 doi, struct netlbl_audit *audit_info); 43762306a36Sopenharmony_ciint netlbl_cfg_calipso_map_add(u32 doi, 43862306a36Sopenharmony_ci const char *domain, 43962306a36Sopenharmony_ci const struct in6_addr *addr, 44062306a36Sopenharmony_ci const struct in6_addr *mask, 44162306a36Sopenharmony_ci struct netlbl_audit *audit_info); 44262306a36Sopenharmony_ci/* 44362306a36Sopenharmony_ci * LSM security attribute operations 44462306a36Sopenharmony_ci */ 44562306a36Sopenharmony_ciint netlbl_catmap_walk(struct netlbl_lsm_catmap *catmap, u32 offset); 44662306a36Sopenharmony_ciint netlbl_catmap_walkrng(struct netlbl_lsm_catmap *catmap, u32 offset); 44762306a36Sopenharmony_ciint netlbl_catmap_getlong(struct netlbl_lsm_catmap *catmap, 44862306a36Sopenharmony_ci u32 *offset, 44962306a36Sopenharmony_ci unsigned long *bitmap); 45062306a36Sopenharmony_ciint netlbl_catmap_setbit(struct netlbl_lsm_catmap **catmap, 45162306a36Sopenharmony_ci u32 bit, 45262306a36Sopenharmony_ci gfp_t flags); 45362306a36Sopenharmony_ciint netlbl_catmap_setrng(struct netlbl_lsm_catmap **catmap, 45462306a36Sopenharmony_ci u32 start, 45562306a36Sopenharmony_ci u32 end, 45662306a36Sopenharmony_ci gfp_t flags); 45762306a36Sopenharmony_ciint netlbl_catmap_setlong(struct netlbl_lsm_catmap **catmap, 45862306a36Sopenharmony_ci u32 offset, 45962306a36Sopenharmony_ci unsigned long bitmap, 46062306a36Sopenharmony_ci gfp_t flags); 46162306a36Sopenharmony_ci 46262306a36Sopenharmony_ci/* Bitmap functions 46362306a36Sopenharmony_ci */ 46462306a36Sopenharmony_ciint netlbl_bitmap_walk(const unsigned char *bitmap, u32 bitmap_len, 46562306a36Sopenharmony_ci u32 offset, u8 state); 46662306a36Sopenharmony_civoid netlbl_bitmap_setbit(unsigned char *bitmap, u32 bit, u8 state); 46762306a36Sopenharmony_ci 46862306a36Sopenharmony_ci/* 46962306a36Sopenharmony_ci * LSM protocol operations (NetLabel LSM/kernel API) 47062306a36Sopenharmony_ci */ 47162306a36Sopenharmony_ciint netlbl_enabled(void); 47262306a36Sopenharmony_ciint netlbl_sock_setattr(struct sock *sk, 47362306a36Sopenharmony_ci u16 family, 47462306a36Sopenharmony_ci const struct netlbl_lsm_secattr *secattr); 47562306a36Sopenharmony_civoid netlbl_sock_delattr(struct sock *sk); 47662306a36Sopenharmony_ciint netlbl_sock_getattr(struct sock *sk, 47762306a36Sopenharmony_ci struct netlbl_lsm_secattr *secattr); 47862306a36Sopenharmony_ciint netlbl_conn_setattr(struct sock *sk, 47962306a36Sopenharmony_ci struct sockaddr *addr, 48062306a36Sopenharmony_ci const struct netlbl_lsm_secattr *secattr); 48162306a36Sopenharmony_ciint netlbl_req_setattr(struct request_sock *req, 48262306a36Sopenharmony_ci const struct netlbl_lsm_secattr *secattr); 48362306a36Sopenharmony_civoid netlbl_req_delattr(struct request_sock *req); 48462306a36Sopenharmony_ciint netlbl_skbuff_setattr(struct sk_buff *skb, 48562306a36Sopenharmony_ci u16 family, 48662306a36Sopenharmony_ci const struct netlbl_lsm_secattr *secattr); 48762306a36Sopenharmony_ciint netlbl_skbuff_getattr(const struct sk_buff *skb, 48862306a36Sopenharmony_ci u16 family, 48962306a36Sopenharmony_ci struct netlbl_lsm_secattr *secattr); 49062306a36Sopenharmony_civoid netlbl_skbuff_err(struct sk_buff *skb, u16 family, int error, int gateway); 49162306a36Sopenharmony_ci 49262306a36Sopenharmony_ci/* 49362306a36Sopenharmony_ci * LSM label mapping cache operations 49462306a36Sopenharmony_ci */ 49562306a36Sopenharmony_civoid netlbl_cache_invalidate(void); 49662306a36Sopenharmony_ciint netlbl_cache_add(const struct sk_buff *skb, u16 family, 49762306a36Sopenharmony_ci const struct netlbl_lsm_secattr *secattr); 49862306a36Sopenharmony_ci 49962306a36Sopenharmony_ci/* 50062306a36Sopenharmony_ci * Protocol engine operations 50162306a36Sopenharmony_ci */ 50262306a36Sopenharmony_cistruct audit_buffer *netlbl_audit_start(int type, 50362306a36Sopenharmony_ci struct netlbl_audit *audit_info); 50462306a36Sopenharmony_ci#else 50562306a36Sopenharmony_cistatic inline int netlbl_cfg_map_del(const char *domain, 50662306a36Sopenharmony_ci u16 family, 50762306a36Sopenharmony_ci const void *addr, 50862306a36Sopenharmony_ci const void *mask, 50962306a36Sopenharmony_ci struct netlbl_audit *audit_info) 51062306a36Sopenharmony_ci{ 51162306a36Sopenharmony_ci return -ENOSYS; 51262306a36Sopenharmony_ci} 51362306a36Sopenharmony_cistatic inline int netlbl_cfg_unlbl_map_add(const char *domain, 51462306a36Sopenharmony_ci u16 family, 51562306a36Sopenharmony_ci void *addr, 51662306a36Sopenharmony_ci void *mask, 51762306a36Sopenharmony_ci struct netlbl_audit *audit_info) 51862306a36Sopenharmony_ci{ 51962306a36Sopenharmony_ci return -ENOSYS; 52062306a36Sopenharmony_ci} 52162306a36Sopenharmony_cistatic inline int netlbl_cfg_unlbl_static_add(struct net *net, 52262306a36Sopenharmony_ci const char *dev_name, 52362306a36Sopenharmony_ci const void *addr, 52462306a36Sopenharmony_ci const void *mask, 52562306a36Sopenharmony_ci u16 family, 52662306a36Sopenharmony_ci u32 secid, 52762306a36Sopenharmony_ci struct netlbl_audit *audit_info) 52862306a36Sopenharmony_ci{ 52962306a36Sopenharmony_ci return -ENOSYS; 53062306a36Sopenharmony_ci} 53162306a36Sopenharmony_cistatic inline int netlbl_cfg_unlbl_static_del(struct net *net, 53262306a36Sopenharmony_ci const char *dev_name, 53362306a36Sopenharmony_ci const void *addr, 53462306a36Sopenharmony_ci const void *mask, 53562306a36Sopenharmony_ci u16 family, 53662306a36Sopenharmony_ci struct netlbl_audit *audit_info) 53762306a36Sopenharmony_ci{ 53862306a36Sopenharmony_ci return -ENOSYS; 53962306a36Sopenharmony_ci} 54062306a36Sopenharmony_cistatic inline int netlbl_cfg_cipsov4_add(struct cipso_v4_doi *doi_def, 54162306a36Sopenharmony_ci struct netlbl_audit *audit_info) 54262306a36Sopenharmony_ci{ 54362306a36Sopenharmony_ci return -ENOSYS; 54462306a36Sopenharmony_ci} 54562306a36Sopenharmony_cistatic inline void netlbl_cfg_cipsov4_del(u32 doi, 54662306a36Sopenharmony_ci struct netlbl_audit *audit_info) 54762306a36Sopenharmony_ci{ 54862306a36Sopenharmony_ci return; 54962306a36Sopenharmony_ci} 55062306a36Sopenharmony_cistatic inline int netlbl_cfg_cipsov4_map_add(u32 doi, 55162306a36Sopenharmony_ci const char *domain, 55262306a36Sopenharmony_ci const struct in_addr *addr, 55362306a36Sopenharmony_ci const struct in_addr *mask, 55462306a36Sopenharmony_ci struct netlbl_audit *audit_info) 55562306a36Sopenharmony_ci{ 55662306a36Sopenharmony_ci return -ENOSYS; 55762306a36Sopenharmony_ci} 55862306a36Sopenharmony_cistatic inline int netlbl_cfg_calipso_add(struct calipso_doi *doi_def, 55962306a36Sopenharmony_ci struct netlbl_audit *audit_info) 56062306a36Sopenharmony_ci{ 56162306a36Sopenharmony_ci return -ENOSYS; 56262306a36Sopenharmony_ci} 56362306a36Sopenharmony_cistatic inline void netlbl_cfg_calipso_del(u32 doi, 56462306a36Sopenharmony_ci struct netlbl_audit *audit_info) 56562306a36Sopenharmony_ci{ 56662306a36Sopenharmony_ci return; 56762306a36Sopenharmony_ci} 56862306a36Sopenharmony_cistatic inline int netlbl_cfg_calipso_map_add(u32 doi, 56962306a36Sopenharmony_ci const char *domain, 57062306a36Sopenharmony_ci const struct in6_addr *addr, 57162306a36Sopenharmony_ci const struct in6_addr *mask, 57262306a36Sopenharmony_ci struct netlbl_audit *audit_info) 57362306a36Sopenharmony_ci{ 57462306a36Sopenharmony_ci return -ENOSYS; 57562306a36Sopenharmony_ci} 57662306a36Sopenharmony_cistatic inline int netlbl_catmap_walk(struct netlbl_lsm_catmap *catmap, 57762306a36Sopenharmony_ci u32 offset) 57862306a36Sopenharmony_ci{ 57962306a36Sopenharmony_ci return -ENOENT; 58062306a36Sopenharmony_ci} 58162306a36Sopenharmony_cistatic inline int netlbl_catmap_walkrng(struct netlbl_lsm_catmap *catmap, 58262306a36Sopenharmony_ci u32 offset) 58362306a36Sopenharmony_ci{ 58462306a36Sopenharmony_ci return -ENOENT; 58562306a36Sopenharmony_ci} 58662306a36Sopenharmony_cistatic inline int netlbl_catmap_getlong(struct netlbl_lsm_catmap *catmap, 58762306a36Sopenharmony_ci u32 *offset, 58862306a36Sopenharmony_ci unsigned long *bitmap) 58962306a36Sopenharmony_ci{ 59062306a36Sopenharmony_ci return 0; 59162306a36Sopenharmony_ci} 59262306a36Sopenharmony_cistatic inline int netlbl_catmap_setbit(struct netlbl_lsm_catmap **catmap, 59362306a36Sopenharmony_ci u32 bit, 59462306a36Sopenharmony_ci gfp_t flags) 59562306a36Sopenharmony_ci{ 59662306a36Sopenharmony_ci return 0; 59762306a36Sopenharmony_ci} 59862306a36Sopenharmony_cistatic inline int netlbl_catmap_setrng(struct netlbl_lsm_catmap **catmap, 59962306a36Sopenharmony_ci u32 start, 60062306a36Sopenharmony_ci u32 end, 60162306a36Sopenharmony_ci gfp_t flags) 60262306a36Sopenharmony_ci{ 60362306a36Sopenharmony_ci return 0; 60462306a36Sopenharmony_ci} 60562306a36Sopenharmony_cistatic inline int netlbl_catmap_setlong(struct netlbl_lsm_catmap **catmap, 60662306a36Sopenharmony_ci u32 offset, 60762306a36Sopenharmony_ci unsigned long bitmap, 60862306a36Sopenharmony_ci gfp_t flags) 60962306a36Sopenharmony_ci{ 61062306a36Sopenharmony_ci return 0; 61162306a36Sopenharmony_ci} 61262306a36Sopenharmony_cistatic inline int netlbl_enabled(void) 61362306a36Sopenharmony_ci{ 61462306a36Sopenharmony_ci return 0; 61562306a36Sopenharmony_ci} 61662306a36Sopenharmony_cistatic inline int netlbl_sock_setattr(struct sock *sk, 61762306a36Sopenharmony_ci u16 family, 61862306a36Sopenharmony_ci const struct netlbl_lsm_secattr *secattr) 61962306a36Sopenharmony_ci{ 62062306a36Sopenharmony_ci return -ENOSYS; 62162306a36Sopenharmony_ci} 62262306a36Sopenharmony_cistatic inline void netlbl_sock_delattr(struct sock *sk) 62362306a36Sopenharmony_ci{ 62462306a36Sopenharmony_ci} 62562306a36Sopenharmony_cistatic inline int netlbl_sock_getattr(struct sock *sk, 62662306a36Sopenharmony_ci struct netlbl_lsm_secattr *secattr) 62762306a36Sopenharmony_ci{ 62862306a36Sopenharmony_ci return -ENOSYS; 62962306a36Sopenharmony_ci} 63062306a36Sopenharmony_cistatic inline int netlbl_conn_setattr(struct sock *sk, 63162306a36Sopenharmony_ci struct sockaddr *addr, 63262306a36Sopenharmony_ci const struct netlbl_lsm_secattr *secattr) 63362306a36Sopenharmony_ci{ 63462306a36Sopenharmony_ci return -ENOSYS; 63562306a36Sopenharmony_ci} 63662306a36Sopenharmony_cistatic inline int netlbl_req_setattr(struct request_sock *req, 63762306a36Sopenharmony_ci const struct netlbl_lsm_secattr *secattr) 63862306a36Sopenharmony_ci{ 63962306a36Sopenharmony_ci return -ENOSYS; 64062306a36Sopenharmony_ci} 64162306a36Sopenharmony_cistatic inline void netlbl_req_delattr(struct request_sock *req) 64262306a36Sopenharmony_ci{ 64362306a36Sopenharmony_ci return; 64462306a36Sopenharmony_ci} 64562306a36Sopenharmony_cistatic inline int netlbl_skbuff_setattr(struct sk_buff *skb, 64662306a36Sopenharmony_ci u16 family, 64762306a36Sopenharmony_ci const struct netlbl_lsm_secattr *secattr) 64862306a36Sopenharmony_ci{ 64962306a36Sopenharmony_ci return -ENOSYS; 65062306a36Sopenharmony_ci} 65162306a36Sopenharmony_cistatic inline int netlbl_skbuff_getattr(const struct sk_buff *skb, 65262306a36Sopenharmony_ci u16 family, 65362306a36Sopenharmony_ci struct netlbl_lsm_secattr *secattr) 65462306a36Sopenharmony_ci{ 65562306a36Sopenharmony_ci return -ENOSYS; 65662306a36Sopenharmony_ci} 65762306a36Sopenharmony_cistatic inline void netlbl_skbuff_err(struct sk_buff *skb, 65862306a36Sopenharmony_ci int error, 65962306a36Sopenharmony_ci int gateway) 66062306a36Sopenharmony_ci{ 66162306a36Sopenharmony_ci return; 66262306a36Sopenharmony_ci} 66362306a36Sopenharmony_cistatic inline void netlbl_cache_invalidate(void) 66462306a36Sopenharmony_ci{ 66562306a36Sopenharmony_ci return; 66662306a36Sopenharmony_ci} 66762306a36Sopenharmony_cistatic inline int netlbl_cache_add(const struct sk_buff *skb, u16 family, 66862306a36Sopenharmony_ci const struct netlbl_lsm_secattr *secattr) 66962306a36Sopenharmony_ci{ 67062306a36Sopenharmony_ci return 0; 67162306a36Sopenharmony_ci} 67262306a36Sopenharmony_cistatic inline struct audit_buffer *netlbl_audit_start(int type, 67362306a36Sopenharmony_ci struct netlbl_audit *audit_info) 67462306a36Sopenharmony_ci{ 67562306a36Sopenharmony_ci return NULL; 67662306a36Sopenharmony_ci} 67762306a36Sopenharmony_ci#endif /* CONFIG_NETLABEL */ 67862306a36Sopenharmony_ci 67962306a36Sopenharmony_ciconst struct netlbl_calipso_ops * 68062306a36Sopenharmony_cinetlbl_calipso_ops_register(const struct netlbl_calipso_ops *ops); 68162306a36Sopenharmony_ci 68262306a36Sopenharmony_ci#endif /* _NETLABEL_H */ 683