111a03f78SPaul Moore /* 211a03f78SPaul Moore * NetLabel System 311a03f78SPaul Moore * 411a03f78SPaul Moore * The NetLabel system manages static and dynamic label mappings for network 511a03f78SPaul Moore * protocols such as CIPSO and RIPSO. 611a03f78SPaul Moore * 782c21bfaSPaul Moore * Author: Paul Moore <paul@paul-moore.com> 811a03f78SPaul Moore * 911a03f78SPaul Moore */ 1011a03f78SPaul Moore 1111a03f78SPaul Moore /* 1263c41688SPaul Moore * (c) Copyright Hewlett-Packard Development Company, L.P., 2006, 2008 1311a03f78SPaul Moore * 1411a03f78SPaul Moore * This program is free software; you can redistribute it and/or modify 1511a03f78SPaul Moore * it under the terms of the GNU General Public License as published by 1611a03f78SPaul Moore * the Free Software Foundation; either version 2 of the License, or 1711a03f78SPaul Moore * (at your option) any later version. 1811a03f78SPaul Moore * 1911a03f78SPaul Moore * This program is distributed in the hope that it will be useful, 2011a03f78SPaul Moore * but WITHOUT ANY WARRANTY; without even the implied warranty of 2111a03f78SPaul Moore * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 2211a03f78SPaul Moore * the GNU General Public License for more details. 2311a03f78SPaul Moore * 2411a03f78SPaul Moore * You should have received a copy of the GNU General Public License 25a6227e26SJeff Kirsher * along with this program; if not, see <http://www.gnu.org/licenses/>. 2611a03f78SPaul Moore * 2711a03f78SPaul Moore */ 2811a03f78SPaul Moore 2911a03f78SPaul Moore #ifndef _NETLABEL_H 3011a03f78SPaul Moore #define _NETLABEL_H 3111a03f78SPaul Moore 3211a03f78SPaul Moore #include <linux/types.h> 335a0e3ad6STejun Heo #include <linux/slab.h> 347a0e1d60SPaul Moore #include <linux/net.h> 3511a03f78SPaul Moore #include <linux/skbuff.h> 366c2e8ac0SPaul Moore #include <linux/in.h> 376c2e8ac0SPaul Moore #include <linux/in6.h> 3811a03f78SPaul Moore #include <net/netlink.h> 39389fb800SPaul Moore #include <net/request_sock.h> 4060063497SArun Sharma #include <linux/atomic.h> 4111a03f78SPaul Moore 42eda61d32SPaul Moore struct cipso_v4_doi; 43cb72d382SHuw Davies struct calipso_doi; 44eda61d32SPaul Moore 4511a03f78SPaul Moore /* 4611a03f78SPaul Moore * NetLabel - A management interface for maintaining network packet label 4711a03f78SPaul Moore * mapping tables for explicit packet labling protocols. 4811a03f78SPaul Moore * 4911a03f78SPaul Moore * Network protocols such as CIPSO and RIPSO require a label translation layer 5011a03f78SPaul Moore * to convert the label on the packet into something meaningful on the host 5111a03f78SPaul Moore * machine. In the current Linux implementation these mapping tables live 5211a03f78SPaul Moore * inside the kernel; NetLabel provides a mechanism for user space applications 5311a03f78SPaul Moore * to manage these mapping tables. 5411a03f78SPaul Moore * 5511a03f78SPaul Moore * NetLabel makes use of the Generic NETLINK mechanism as a transport layer to 5611a03f78SPaul Moore * send messages between kernel and user space. The general format of a 5711a03f78SPaul Moore * NetLabel message is shown below: 5811a03f78SPaul Moore * 5911a03f78SPaul Moore * +-----------------+-------------------+--------- --- -- - 6011a03f78SPaul Moore * | struct nlmsghdr | struct genlmsghdr | payload 6111a03f78SPaul Moore * +-----------------+-------------------+--------- --- -- - 6211a03f78SPaul Moore * 6311a03f78SPaul Moore * The 'nlmsghdr' and 'genlmsghdr' structs should be dealt with like normal. 6411a03f78SPaul Moore * The payload is dependent on the subsystem specified in the 6511a03f78SPaul Moore * 'nlmsghdr->nlmsg_type' and should be defined below, supporting functions 6611a03f78SPaul Moore * should be defined in the corresponding net/netlabel/netlabel_<subsys>.h|c 67fcd48280SPaul Moore * file. All of the fields in the NetLabel payload are NETLINK attributes, see 68fcd48280SPaul Moore * the include/net/netlink.h file for more information on NETLINK attributes. 6911a03f78SPaul Moore * 7011a03f78SPaul Moore */ 7111a03f78SPaul Moore 7211a03f78SPaul Moore /* 7311a03f78SPaul Moore * NetLabel NETLINK protocol 7411a03f78SPaul Moore */ 7511a03f78SPaul Moore 768cc44579SPaul Moore /* NetLabel NETLINK protocol version 778cc44579SPaul Moore * 1: initial version 788cc44579SPaul Moore * 2: added static labels for unlabeled connections 79d91d4079SPaul Moore * 3: network selectors added to the NetLabel/LSM domain mapping and the 80d91d4079SPaul Moore * CIPSO_V4_MAP_LOCAL CIPSO mapping was added 818cc44579SPaul Moore */ 8263c41688SPaul Moore #define NETLBL_PROTO_VERSION 3 8311a03f78SPaul Moore 8411a03f78SPaul Moore /* NetLabel NETLINK types/families */ 8511a03f78SPaul Moore #define NETLBL_NLTYPE_NONE 0 8611a03f78SPaul Moore #define NETLBL_NLTYPE_MGMT 1 8711a03f78SPaul Moore #define NETLBL_NLTYPE_MGMT_NAME "NLBL_MGMT" 8811a03f78SPaul Moore #define NETLBL_NLTYPE_RIPSO 2 8911a03f78SPaul Moore #define NETLBL_NLTYPE_RIPSO_NAME "NLBL_RIPSO" 9011a03f78SPaul Moore #define NETLBL_NLTYPE_CIPSOV4 3 9111a03f78SPaul Moore #define NETLBL_NLTYPE_CIPSOV4_NAME "NLBL_CIPSOv4" 9211a03f78SPaul Moore #define NETLBL_NLTYPE_CIPSOV6 4 9311a03f78SPaul Moore #define NETLBL_NLTYPE_CIPSOV6_NAME "NLBL_CIPSOv6" 9411a03f78SPaul Moore #define NETLBL_NLTYPE_UNLABELED 5 9511a03f78SPaul Moore #define NETLBL_NLTYPE_UNLABELED_NAME "NLBL_UNLBL" 9663c41688SPaul Moore #define NETLBL_NLTYPE_ADDRSELECT 6 9763c41688SPaul Moore #define NETLBL_NLTYPE_ADDRSELECT_NAME "NLBL_ADRSEL" 98cb72d382SHuw Davies #define NETLBL_NLTYPE_CALIPSO 7 99cb72d382SHuw Davies #define NETLBL_NLTYPE_CALIPSO_NAME "NLBL_CALIPSO" 10011a03f78SPaul Moore 10111a03f78SPaul Moore /* 10211a03f78SPaul Moore * NetLabel - Kernel API for accessing the network packet label mappings. 10311a03f78SPaul Moore * 10411a03f78SPaul Moore * The following functions are provided for use by other kernel modules, 10511a03f78SPaul Moore * specifically kernel LSM modules, to provide a consistent, transparent API 10611a03f78SPaul Moore * for dealing with explicit packet labeling protocols such as CIPSO and 10711a03f78SPaul Moore * RIPSO. The functions defined here are implemented in the 10811a03f78SPaul Moore * net/netlabel/netlabel_kapi.c file. 10911a03f78SPaul Moore * 11011a03f78SPaul Moore */ 11111a03f78SPaul Moore 11295d4e6beSPaul Moore /* NetLabel audit information */ 11395d4e6beSPaul Moore struct netlbl_audit { 11495d4e6beSPaul Moore u32 secid; 115e1760bd5SEric W. Biederman kuid_t loginuid; 1164440e854SEric Paris unsigned int sessionid; 11795d4e6beSPaul Moore }; 11895d4e6beSPaul Moore 11916efd454SPaul Moore /* 12016efd454SPaul Moore * LSM security attributes 12116efd454SPaul Moore */ 12216efd454SPaul Moore 12316efd454SPaul Moore /** 12416efd454SPaul Moore * struct netlbl_lsm_cache - NetLabel LSM security attribute cache 12516efd454SPaul Moore * @refcount: atomic reference counter 12616efd454SPaul Moore * @free: LSM supplied function to free the cache data 12716efd454SPaul Moore * @data: LSM supplied cache data 12816efd454SPaul Moore * 12916efd454SPaul Moore * Description: 13016efd454SPaul Moore * This structure is provided for LSMs which wish to make use of the NetLabel 13116efd454SPaul Moore * caching mechanism to store LSM specific data/attributes in the NetLabel 13216efd454SPaul Moore * cache. If the LSM has to perform a lot of translation from the NetLabel 13316efd454SPaul Moore * security attributes into it's own internal representation then the cache 13416efd454SPaul Moore * mechanism can provide a way to eliminate some or all of that translation 13516efd454SPaul Moore * overhead on a cache hit. 13616efd454SPaul Moore * 13716efd454SPaul Moore */ 13811a03f78SPaul Moore struct netlbl_lsm_cache { 139ffb733c6Spaul.moore@hp.com atomic_t refcount; 14011a03f78SPaul Moore void (*free) (const void *data); 14111a03f78SPaul Moore void *data; 14211a03f78SPaul Moore }; 14316efd454SPaul Moore 14416efd454SPaul Moore /** 1454fbe63d1SPaul Moore * struct netlbl_lsm_catmap - NetLabel LSM secattr category bitmap 14616efd454SPaul Moore * @startbit: the value of the lowest order bit in the bitmap 14716efd454SPaul Moore * @bitmap: the category bitmap 14816efd454SPaul Moore * @next: pointer to the next bitmap "node" or NULL 14916efd454SPaul Moore * 15016efd454SPaul Moore * Description: 15116efd454SPaul Moore * This structure is used to represent category bitmaps. Due to the large 15216efd454SPaul Moore * number of categories supported by most labeling protocols it is not 15316efd454SPaul Moore * practical to transfer a full bitmap internally so NetLabel adopts a sparse 15416efd454SPaul Moore * bitmap structure modeled after SELinux's ebitmap structure. 15516efd454SPaul Moore * The catmap bitmap field MUST be a power of two in length and large 15602752760SPaul Moore * enough to hold at least 240 bits. Special care (i.e. check the code!) 15702752760SPaul Moore * should be used when changing these values as the LSM implementation 15802752760SPaul Moore * probably has functions which rely on the sizes of these types to speed 15916efd454SPaul Moore * processing. 16016efd454SPaul Moore * 16116efd454SPaul Moore */ 16202752760SPaul Moore #define NETLBL_CATMAP_MAPTYPE u64 16302752760SPaul Moore #define NETLBL_CATMAP_MAPCNT 4 16402752760SPaul Moore #define NETLBL_CATMAP_MAPSIZE (sizeof(NETLBL_CATMAP_MAPTYPE) * 8) 16502752760SPaul Moore #define NETLBL_CATMAP_SIZE (NETLBL_CATMAP_MAPSIZE * \ 16602752760SPaul Moore NETLBL_CATMAP_MAPCNT) 16702752760SPaul Moore #define NETLBL_CATMAP_BIT (NETLBL_CATMAP_MAPTYPE)0x01 1684fbe63d1SPaul Moore struct netlbl_lsm_catmap { 16902752760SPaul Moore u32 startbit; 17002752760SPaul Moore NETLBL_CATMAP_MAPTYPE bitmap[NETLBL_CATMAP_MAPCNT]; 1714fbe63d1SPaul Moore struct netlbl_lsm_catmap *next; 17202752760SPaul Moore }; 17316efd454SPaul Moore 17416efd454SPaul Moore /** 17516efd454SPaul Moore * struct netlbl_lsm_secattr - NetLabel LSM security attributes 17600447872SPaul Moore * @flags: indicate structure attributes, see NETLBL_SECATTR_* 17716efd454SPaul Moore * @type: indicate the NLTYPE of the attributes 17816efd454SPaul Moore * @domain: the NetLabel LSM domain 17916efd454SPaul Moore * @cache: NetLabel LSM specific cache 18016efd454SPaul Moore * @attr.mls: MLS sensitivity label 18116efd454SPaul Moore * @attr.mls.cat: MLS category bitmap 18216efd454SPaul Moore * @attr.mls.lvl: MLS sensitivity level 18316efd454SPaul Moore * @attr.secid: LSM specific secid token 18416efd454SPaul Moore * 18516efd454SPaul Moore * Description: 18616efd454SPaul Moore * This structure is used to pass security attributes between NetLabel and the 18716efd454SPaul Moore * LSM modules. The flags field is used to specify which fields within the 18816efd454SPaul Moore * struct are valid and valid values can be created by bitwise OR'ing the 18916efd454SPaul Moore * NETLBL_SECATTR_* defines. The domain field is typically set by the LSM to 19016efd454SPaul Moore * specify domain specific configuration settings and is not usually used by 19116efd454SPaul Moore * NetLabel itself when returning security attributes to the LSM. 19216efd454SPaul Moore * 19316efd454SPaul Moore */ 19400447872SPaul Moore struct netlbl_lsm_secattr { 19500447872SPaul Moore u32 flags; 19600447872SPaul Moore /* bitmap values for 'flags' */ 197701a90baSPaul Moore #define NETLBL_SECATTR_NONE 0x00000000 198701a90baSPaul Moore #define NETLBL_SECATTR_DOMAIN 0x00000001 19900447872SPaul Moore #define NETLBL_SECATTR_DOMAIN_CPY (NETLBL_SECATTR_DOMAIN | \ 20000447872SPaul Moore NETLBL_SECATTR_FREE_DOMAIN) 201701a90baSPaul Moore #define NETLBL_SECATTR_CACHE 0x00000002 202701a90baSPaul Moore #define NETLBL_SECATTR_MLS_LVL 0x00000004 203701a90baSPaul Moore #define NETLBL_SECATTR_MLS_CAT 0x00000008 20416efd454SPaul Moore #define NETLBL_SECATTR_SECID 0x00000010 20500447872SPaul Moore /* bitmap meta-values for 'flags' */ 20600447872SPaul Moore #define NETLBL_SECATTR_FREE_DOMAIN 0x01000000 2079534f71cSPaul Moore #define NETLBL_SECATTR_CACHEABLE (NETLBL_SECATTR_MLS_LVL | \ 20816efd454SPaul Moore NETLBL_SECATTR_MLS_CAT | \ 20916efd454SPaul Moore NETLBL_SECATTR_SECID) 21016efd454SPaul Moore u32 type; 21111a03f78SPaul Moore char *domain; 212ffb733c6Spaul.moore@hp.com struct netlbl_lsm_cache *cache; 2138d75899dSPaul Moore struct { 21416efd454SPaul Moore struct { 2154fbe63d1SPaul Moore struct netlbl_lsm_catmap *cat; 21616efd454SPaul Moore u32 lvl; 21716efd454SPaul Moore } mls; 21816efd454SPaul Moore u32 secid; 21916efd454SPaul Moore } attr; 22011a03f78SPaul Moore }; 22111a03f78SPaul Moore 222cb72d382SHuw Davies /** 223cb72d382SHuw Davies * struct netlbl_calipso_ops - NetLabel CALIPSO operations 224cb72d382SHuw Davies * @doi_add: add a CALIPSO DOI 225cb72d382SHuw Davies * @doi_free: free a CALIPSO DOI 226a5e34490SHuw Davies * @doi_getdef: returns a reference to a DOI 227a5e34490SHuw Davies * @doi_putdef: releases a reference of a DOI 228e1ce69dfSHuw Davies * @doi_walk: enumerate the DOI list 229*ceba1832SHuw Davies * @sock_getattr: retrieve the socket's attr 230*ceba1832SHuw Davies * @sock_setattr: set the socket's attr 231*ceba1832SHuw Davies * @sock_delattr: remove the socket's attr 232cb72d382SHuw Davies * 233cb72d382SHuw Davies * Description: 234cb72d382SHuw Davies * This structure is filled out by the CALIPSO engine and passed 235cb72d382SHuw Davies * to the NetLabel core via a call to netlbl_calipso_ops_register(). 236cb72d382SHuw Davies * It enables the CALIPSO engine (and hence IPv6) to be compiled 237cb72d382SHuw Davies * as a module. 238cb72d382SHuw Davies */ 239cb72d382SHuw Davies struct netlbl_calipso_ops { 240cb72d382SHuw Davies int (*doi_add)(struct calipso_doi *doi_def, 241cb72d382SHuw Davies struct netlbl_audit *audit_info); 242cb72d382SHuw Davies void (*doi_free)(struct calipso_doi *doi_def); 243d7cce015SHuw Davies int (*doi_remove)(u32 doi, struct netlbl_audit *audit_info); 244a5e34490SHuw Davies struct calipso_doi *(*doi_getdef)(u32 doi); 245a5e34490SHuw Davies void (*doi_putdef)(struct calipso_doi *doi_def); 246e1ce69dfSHuw Davies int (*doi_walk)(u32 *skip_cnt, 247e1ce69dfSHuw Davies int (*callback)(struct calipso_doi *doi_def, void *arg), 248e1ce69dfSHuw Davies void *cb_arg); 249*ceba1832SHuw Davies int (*sock_getattr)(struct sock *sk, 250*ceba1832SHuw Davies struct netlbl_lsm_secattr *secattr); 251*ceba1832SHuw Davies int (*sock_setattr)(struct sock *sk, 252*ceba1832SHuw Davies const struct calipso_doi *doi_def, 253*ceba1832SHuw Davies const struct netlbl_lsm_secattr *secattr); 254*ceba1832SHuw Davies void (*sock_delattr)(struct sock *sk); 255cb72d382SHuw Davies }; 256cb72d382SHuw Davies 25711a03f78SPaul Moore /* 25823bcdc1aSPaul Moore * LSM security attribute operations (inline) 25911a03f78SPaul Moore */ 26011a03f78SPaul Moore 26111a03f78SPaul Moore /** 262ffb733c6Spaul.moore@hp.com * netlbl_secattr_cache_alloc - Allocate and initialize a secattr cache 263ffb733c6Spaul.moore@hp.com * @flags: the memory allocation flags 264ffb733c6Spaul.moore@hp.com * 265ffb733c6Spaul.moore@hp.com * Description: 266ffb733c6Spaul.moore@hp.com * Allocate and initialize a netlbl_lsm_cache structure. Returns a pointer 267ffb733c6Spaul.moore@hp.com * on success, NULL on failure. 268ffb733c6Spaul.moore@hp.com * 269ffb733c6Spaul.moore@hp.com */ 270645408d1SAl Viro static inline struct netlbl_lsm_cache *netlbl_secattr_cache_alloc(gfp_t flags) 271ffb733c6Spaul.moore@hp.com { 272ffb733c6Spaul.moore@hp.com struct netlbl_lsm_cache *cache; 273ffb733c6Spaul.moore@hp.com 274ffb733c6Spaul.moore@hp.com cache = kzalloc(sizeof(*cache), flags); 275ffb733c6Spaul.moore@hp.com if (cache) 276ffb733c6Spaul.moore@hp.com atomic_set(&cache->refcount, 1); 277ffb733c6Spaul.moore@hp.com return cache; 278ffb733c6Spaul.moore@hp.com } 279ffb733c6Spaul.moore@hp.com 280ffb733c6Spaul.moore@hp.com /** 281ffb733c6Spaul.moore@hp.com * netlbl_secattr_cache_free - Frees a netlbl_lsm_cache struct 282ffb733c6Spaul.moore@hp.com * @cache: the struct to free 283ffb733c6Spaul.moore@hp.com * 284ffb733c6Spaul.moore@hp.com * Description: 285ffb733c6Spaul.moore@hp.com * Frees @secattr including all of the internal buffers. 286ffb733c6Spaul.moore@hp.com * 287ffb733c6Spaul.moore@hp.com */ 288ffb733c6Spaul.moore@hp.com static inline void netlbl_secattr_cache_free(struct netlbl_lsm_cache *cache) 289ffb733c6Spaul.moore@hp.com { 290ffb733c6Spaul.moore@hp.com if (!atomic_dec_and_test(&cache->refcount)) 291ffb733c6Spaul.moore@hp.com return; 292ffb733c6Spaul.moore@hp.com 293ffb733c6Spaul.moore@hp.com if (cache->free) 294ffb733c6Spaul.moore@hp.com cache->free(cache->data); 295ffb733c6Spaul.moore@hp.com kfree(cache); 296ffb733c6Spaul.moore@hp.com } 297ffb733c6Spaul.moore@hp.com 298ffb733c6Spaul.moore@hp.com /** 2994fbe63d1SPaul Moore * netlbl_catmap_alloc - Allocate a LSM secattr catmap 30002752760SPaul Moore * @flags: memory allocation flags 30102752760SPaul Moore * 30202752760SPaul Moore * Description: 30302752760SPaul Moore * Allocate memory for a LSM secattr catmap, returns a pointer on success, NULL 30402752760SPaul Moore * on failure. 30502752760SPaul Moore * 30602752760SPaul Moore */ 3074fbe63d1SPaul Moore static inline struct netlbl_lsm_catmap *netlbl_catmap_alloc(gfp_t flags) 30802752760SPaul Moore { 3094fbe63d1SPaul Moore return kzalloc(sizeof(struct netlbl_lsm_catmap), flags); 31002752760SPaul Moore } 31102752760SPaul Moore 31202752760SPaul Moore /** 3134fbe63d1SPaul Moore * netlbl_catmap_free - Free a LSM secattr catmap 31402752760SPaul Moore * @catmap: the category bitmap 31502752760SPaul Moore * 31602752760SPaul Moore * Description: 31702752760SPaul Moore * Free a LSM secattr catmap. 31802752760SPaul Moore * 31902752760SPaul Moore */ 3204fbe63d1SPaul Moore static inline void netlbl_catmap_free(struct netlbl_lsm_catmap *catmap) 32102752760SPaul Moore { 3224fbe63d1SPaul Moore struct netlbl_lsm_catmap *iter; 32302752760SPaul Moore 3244b8feff2SPaul Moore while (catmap) { 32502752760SPaul Moore iter = catmap; 32602752760SPaul Moore catmap = catmap->next; 32702752760SPaul Moore kfree(iter); 3284b8feff2SPaul Moore } 32902752760SPaul Moore } 33002752760SPaul Moore 33102752760SPaul Moore /** 33211a03f78SPaul Moore * netlbl_secattr_init - Initialize a netlbl_lsm_secattr struct 33311a03f78SPaul Moore * @secattr: the struct to initialize 33411a03f78SPaul Moore * 33511a03f78SPaul Moore * Description: 336c6fa82a9SPaul Moore * Initialize an already allocated netlbl_lsm_secattr struct. 33711a03f78SPaul Moore * 33811a03f78SPaul Moore */ 339c6fa82a9SPaul Moore static inline void netlbl_secattr_init(struct netlbl_lsm_secattr *secattr) 34011a03f78SPaul Moore { 34116efd454SPaul Moore memset(secattr, 0, sizeof(*secattr)); 34211a03f78SPaul Moore } 34311a03f78SPaul Moore 34411a03f78SPaul Moore /** 34511a03f78SPaul Moore * netlbl_secattr_destroy - Clears a netlbl_lsm_secattr struct 34611a03f78SPaul Moore * @secattr: the struct to clear 34711a03f78SPaul Moore * 34811a03f78SPaul Moore * Description: 34911a03f78SPaul Moore * Destroys the @secattr struct, including freeing all of the internal buffers. 350ffb733c6Spaul.moore@hp.com * The struct must be reset with a call to netlbl_secattr_init() before reuse. 35111a03f78SPaul Moore * 35211a03f78SPaul Moore */ 353ffb733c6Spaul.moore@hp.com static inline void netlbl_secattr_destroy(struct netlbl_lsm_secattr *secattr) 35411a03f78SPaul Moore { 35500447872SPaul Moore if (secattr->flags & NETLBL_SECATTR_FREE_DOMAIN) 35611a03f78SPaul Moore kfree(secattr->domain); 35716efd454SPaul Moore if (secattr->flags & NETLBL_SECATTR_CACHE) 35816efd454SPaul Moore netlbl_secattr_cache_free(secattr->cache); 35916efd454SPaul Moore if (secattr->flags & NETLBL_SECATTR_MLS_CAT) 3604fbe63d1SPaul Moore netlbl_catmap_free(secattr->attr.mls.cat); 36111a03f78SPaul Moore } 36211a03f78SPaul Moore 36311a03f78SPaul Moore /** 36411a03f78SPaul Moore * netlbl_secattr_alloc - Allocate and initialize a netlbl_lsm_secattr struct 36511a03f78SPaul Moore * @flags: the memory allocation flags 36611a03f78SPaul Moore * 36711a03f78SPaul Moore * Description: 36811a03f78SPaul Moore * Allocate and initialize a netlbl_lsm_secattr struct. Returns a valid 36911a03f78SPaul Moore * pointer on success, or NULL on failure. 37011a03f78SPaul Moore * 37111a03f78SPaul Moore */ 3721f758d93SPaul Moore static inline struct netlbl_lsm_secattr *netlbl_secattr_alloc(gfp_t flags) 37311a03f78SPaul Moore { 37411a03f78SPaul Moore return kzalloc(sizeof(struct netlbl_lsm_secattr), flags); 37511a03f78SPaul Moore } 37611a03f78SPaul Moore 37711a03f78SPaul Moore /** 37811a03f78SPaul Moore * netlbl_secattr_free - Frees a netlbl_lsm_secattr struct 37911a03f78SPaul Moore * @secattr: the struct to free 38011a03f78SPaul Moore * 38111a03f78SPaul Moore * Description: 382ffb733c6Spaul.moore@hp.com * Frees @secattr including all of the internal buffers. 38311a03f78SPaul Moore * 38411a03f78SPaul Moore */ 385ffb733c6Spaul.moore@hp.com static inline void netlbl_secattr_free(struct netlbl_lsm_secattr *secattr) 38611a03f78SPaul Moore { 387ffb733c6Spaul.moore@hp.com netlbl_secattr_destroy(secattr); 38811a03f78SPaul Moore kfree(secattr); 38911a03f78SPaul Moore } 39011a03f78SPaul Moore 39102752760SPaul Moore #ifdef CONFIG_NETLABEL 39223bcdc1aSPaul Moore /* 393eda61d32SPaul Moore * LSM configuration operations 394eda61d32SPaul Moore */ 3956c2e8ac0SPaul Moore int netlbl_cfg_map_del(const char *domain, 3966c2e8ac0SPaul Moore u16 family, 3976c2e8ac0SPaul Moore const void *addr, 3986c2e8ac0SPaul Moore const void *mask, 399eda61d32SPaul Moore struct netlbl_audit *audit_info); 4006c2e8ac0SPaul Moore int netlbl_cfg_unlbl_map_add(const char *domain, 4016c2e8ac0SPaul Moore u16 family, 4026c2e8ac0SPaul Moore const void *addr, 4036c2e8ac0SPaul Moore const void *mask, 4046c2e8ac0SPaul Moore struct netlbl_audit *audit_info); 4056c2e8ac0SPaul Moore int netlbl_cfg_unlbl_static_add(struct net *net, 4066c2e8ac0SPaul Moore const char *dev_name, 4076c2e8ac0SPaul Moore const void *addr, 4086c2e8ac0SPaul Moore const void *mask, 4096c2e8ac0SPaul Moore u16 family, 4106c2e8ac0SPaul Moore u32 secid, 4116c2e8ac0SPaul Moore struct netlbl_audit *audit_info); 4126c2e8ac0SPaul Moore int netlbl_cfg_unlbl_static_del(struct net *net, 4136c2e8ac0SPaul Moore const char *dev_name, 4146c2e8ac0SPaul Moore const void *addr, 4156c2e8ac0SPaul Moore const void *mask, 4166c2e8ac0SPaul Moore u16 family, 4176c2e8ac0SPaul Moore struct netlbl_audit *audit_info); 4186c2e8ac0SPaul Moore int netlbl_cfg_cipsov4_add(struct cipso_v4_doi *doi_def, 4196c2e8ac0SPaul Moore struct netlbl_audit *audit_info); 4206c2e8ac0SPaul Moore void netlbl_cfg_cipsov4_del(u32 doi, struct netlbl_audit *audit_info); 4216c2e8ac0SPaul Moore int netlbl_cfg_cipsov4_map_add(u32 doi, 422eda61d32SPaul Moore const char *domain, 4236c2e8ac0SPaul Moore const struct in_addr *addr, 4246c2e8ac0SPaul Moore const struct in_addr *mask, 425eda61d32SPaul Moore struct netlbl_audit *audit_info); 426eda61d32SPaul Moore /* 42723bcdc1aSPaul Moore * LSM security attribute operations 42823bcdc1aSPaul Moore */ 4294fbe63d1SPaul Moore int netlbl_catmap_walk(struct netlbl_lsm_catmap *catmap, u32 offset); 4304fbe63d1SPaul Moore int netlbl_catmap_walkrng(struct netlbl_lsm_catmap *catmap, u32 offset); 4314fbe63d1SPaul Moore int netlbl_catmap_getlong(struct netlbl_lsm_catmap *catmap, 4324b8feff2SPaul Moore u32 *offset, 4334b8feff2SPaul Moore unsigned long *bitmap); 4344fbe63d1SPaul Moore int netlbl_catmap_setbit(struct netlbl_lsm_catmap **catmap, 43502752760SPaul Moore u32 bit, 43602752760SPaul Moore gfp_t flags); 4374fbe63d1SPaul Moore int netlbl_catmap_setrng(struct netlbl_lsm_catmap **catmap, 43802752760SPaul Moore u32 start, 43902752760SPaul Moore u32 end, 44002752760SPaul Moore gfp_t flags); 4414fbe63d1SPaul Moore int netlbl_catmap_setlong(struct netlbl_lsm_catmap **catmap, 4424b8feff2SPaul Moore u32 offset, 4434b8feff2SPaul Moore unsigned long bitmap, 4444b8feff2SPaul Moore gfp_t flags); 44523bcdc1aSPaul Moore 4463faa8f98SHuw Davies /* Bitmap functions 4473faa8f98SHuw Davies */ 4483faa8f98SHuw Davies int netlbl_bitmap_walk(const unsigned char *bitmap, u32 bitmap_len, 4493faa8f98SHuw Davies u32 offset, u8 state); 4503faa8f98SHuw Davies void netlbl_bitmap_setbit(unsigned char *bitmap, u32 bit, u8 state); 4513faa8f98SHuw Davies 45223bcdc1aSPaul Moore /* 45316efd454SPaul Moore * LSM protocol operations (NetLabel LSM/kernel API) 45423bcdc1aSPaul Moore */ 45523bcdc1aSPaul Moore int netlbl_enabled(void); 45623bcdc1aSPaul Moore int netlbl_sock_setattr(struct sock *sk, 457389fb800SPaul Moore u16 family, 45823bcdc1aSPaul Moore const struct netlbl_lsm_secattr *secattr); 459014ab19aSPaul Moore void netlbl_sock_delattr(struct sock *sk); 46023bcdc1aSPaul Moore int netlbl_sock_getattr(struct sock *sk, 46123bcdc1aSPaul Moore struct netlbl_lsm_secattr *secattr); 462014ab19aSPaul Moore int netlbl_conn_setattr(struct sock *sk, 463014ab19aSPaul Moore struct sockaddr *addr, 464014ab19aSPaul Moore const struct netlbl_lsm_secattr *secattr); 465389fb800SPaul Moore int netlbl_req_setattr(struct request_sock *req, 466389fb800SPaul Moore const struct netlbl_lsm_secattr *secattr); 46707feee8fSPaul Moore void netlbl_req_delattr(struct request_sock *req); 468948bf85cSPaul Moore int netlbl_skbuff_setattr(struct sk_buff *skb, 469948bf85cSPaul Moore u16 family, 470948bf85cSPaul Moore const struct netlbl_lsm_secattr *secattr); 47123bcdc1aSPaul Moore int netlbl_skbuff_getattr(const struct sk_buff *skb, 47275e22910SPaul Moore u16 family, 47323bcdc1aSPaul Moore struct netlbl_lsm_secattr *secattr); 474dfaebe98SPaul Moore void netlbl_skbuff_err(struct sk_buff *skb, int error, int gateway); 47523bcdc1aSPaul Moore 47623bcdc1aSPaul Moore /* 47723bcdc1aSPaul Moore * LSM label mapping cache operations 47823bcdc1aSPaul Moore */ 47923bcdc1aSPaul Moore void netlbl_cache_invalidate(void); 48023bcdc1aSPaul Moore int netlbl_cache_add(const struct sk_buff *skb, 48123bcdc1aSPaul Moore const struct netlbl_lsm_secattr *secattr); 4826c2e8ac0SPaul Moore 4836c2e8ac0SPaul Moore /* 4846c2e8ac0SPaul Moore * Protocol engine operations 4856c2e8ac0SPaul Moore */ 4866c2e8ac0SPaul Moore struct audit_buffer *netlbl_audit_start(int type, 4876c2e8ac0SPaul Moore struct netlbl_audit *audit_info); 48802752760SPaul Moore #else 489eda61d32SPaul Moore static inline int netlbl_cfg_map_del(const char *domain, 4906c2e8ac0SPaul Moore u16 family, 4916c2e8ac0SPaul Moore const void *addr, 4926c2e8ac0SPaul Moore const void *mask, 493eda61d32SPaul Moore struct netlbl_audit *audit_info) 494eda61d32SPaul Moore { 495eda61d32SPaul Moore return -ENOSYS; 496eda61d32SPaul Moore } 4976c2e8ac0SPaul Moore static inline int netlbl_cfg_unlbl_map_add(const char *domain, 4986c2e8ac0SPaul Moore u16 family, 4996c2e8ac0SPaul Moore void *addr, 5006c2e8ac0SPaul Moore void *mask, 501eda61d32SPaul Moore struct netlbl_audit *audit_info) 502eda61d32SPaul Moore { 503eda61d32SPaul Moore return -ENOSYS; 504eda61d32SPaul Moore } 5056c2e8ac0SPaul Moore static inline int netlbl_cfg_unlbl_static_add(struct net *net, 5066c2e8ac0SPaul Moore const char *dev_name, 5076c2e8ac0SPaul Moore const void *addr, 5086c2e8ac0SPaul Moore const void *mask, 5096c2e8ac0SPaul Moore u16 family, 5106c2e8ac0SPaul Moore u32 secid, 5116c2e8ac0SPaul Moore struct netlbl_audit *audit_info) 5126c2e8ac0SPaul Moore { 5136c2e8ac0SPaul Moore return -ENOSYS; 5146c2e8ac0SPaul Moore } 5156c2e8ac0SPaul Moore static inline int netlbl_cfg_unlbl_static_del(struct net *net, 5166c2e8ac0SPaul Moore const char *dev_name, 5176c2e8ac0SPaul Moore const void *addr, 5186c2e8ac0SPaul Moore const void *mask, 5196c2e8ac0SPaul Moore u16 family, 5206c2e8ac0SPaul Moore struct netlbl_audit *audit_info) 5216c2e8ac0SPaul Moore { 5226c2e8ac0SPaul Moore return -ENOSYS; 5236c2e8ac0SPaul Moore } 5246c2e8ac0SPaul Moore static inline int netlbl_cfg_cipsov4_add(struct cipso_v4_doi *doi_def, 5256c2e8ac0SPaul Moore struct netlbl_audit *audit_info) 5266c2e8ac0SPaul Moore { 5276c2e8ac0SPaul Moore return -ENOSYS; 5286c2e8ac0SPaul Moore } 5296c2e8ac0SPaul Moore static inline void netlbl_cfg_cipsov4_del(u32 doi, 5306c2e8ac0SPaul Moore struct netlbl_audit *audit_info) 5316c2e8ac0SPaul Moore { 5326c2e8ac0SPaul Moore return; 5336c2e8ac0SPaul Moore } 5346c2e8ac0SPaul Moore static inline int netlbl_cfg_cipsov4_map_add(u32 doi, 535eda61d32SPaul Moore const char *domain, 5366c2e8ac0SPaul Moore const struct in_addr *addr, 5376c2e8ac0SPaul Moore const struct in_addr *mask, 538eda61d32SPaul Moore struct netlbl_audit *audit_info) 539eda61d32SPaul Moore { 540eda61d32SPaul Moore return -ENOSYS; 541eda61d32SPaul Moore } 5424fbe63d1SPaul Moore static inline int netlbl_catmap_walk(struct netlbl_lsm_catmap *catmap, 54302752760SPaul Moore u32 offset) 54402752760SPaul Moore { 54502752760SPaul Moore return -ENOENT; 54602752760SPaul Moore } 5474fbe63d1SPaul Moore static inline int netlbl_catmap_walkrng(struct netlbl_lsm_catmap *catmap, 54802752760SPaul Moore u32 offset) 54902752760SPaul Moore { 55002752760SPaul Moore return -ENOENT; 55102752760SPaul Moore } 5524fbe63d1SPaul Moore static inline int netlbl_catmap_getlong(struct netlbl_lsm_catmap *catmap, 5534b8feff2SPaul Moore u32 *offset, 5544b8feff2SPaul Moore unsigned long *bitmap) 5554b8feff2SPaul Moore { 5564b8feff2SPaul Moore return 0; 5574b8feff2SPaul Moore } 5584fbe63d1SPaul Moore static inline int netlbl_catmap_setbit(struct netlbl_lsm_catmap **catmap, 55902752760SPaul Moore u32 bit, 56002752760SPaul Moore gfp_t flags) 56102752760SPaul Moore { 56202752760SPaul Moore return 0; 56302752760SPaul Moore } 5644fbe63d1SPaul Moore static inline int netlbl_catmap_setrng(struct netlbl_lsm_catmap **catmap, 56502752760SPaul Moore u32 start, 56602752760SPaul Moore u32 end, 56702752760SPaul Moore gfp_t flags) 56802752760SPaul Moore { 56902752760SPaul Moore return 0; 57002752760SPaul Moore } 571bc7e6edbSPaul Moore static inline int netlbl_catmap_setlong(struct netlbl_lsm_catmap **catmap, 5724b8feff2SPaul Moore u32 offset, 5734b8feff2SPaul Moore unsigned long bitmap, 5744b8feff2SPaul Moore gfp_t flags) 5754b8feff2SPaul Moore { 5764b8feff2SPaul Moore return 0; 5774b8feff2SPaul Moore } 57823bcdc1aSPaul Moore static inline int netlbl_enabled(void) 57923bcdc1aSPaul Moore { 58023bcdc1aSPaul Moore return 0; 58123bcdc1aSPaul Moore } 582ba6ff9f2SPaul Moore static inline int netlbl_sock_setattr(struct sock *sk, 583389fb800SPaul Moore u16 family, 58411a03f78SPaul Moore const struct netlbl_lsm_secattr *secattr) 58511a03f78SPaul Moore { 58611a03f78SPaul Moore return -ENOSYS; 58711a03f78SPaul Moore } 588014ab19aSPaul Moore static inline void netlbl_sock_delattr(struct sock *sk) 589014ab19aSPaul Moore { 590014ab19aSPaul Moore } 59114a72f53SPaul Moore static inline int netlbl_sock_getattr(struct sock *sk, 59214a72f53SPaul Moore struct netlbl_lsm_secattr *secattr) 59314a72f53SPaul Moore { 59414a72f53SPaul Moore return -ENOSYS; 59514a72f53SPaul Moore } 596014ab19aSPaul Moore static inline int netlbl_conn_setattr(struct sock *sk, 597014ab19aSPaul Moore struct sockaddr *addr, 598014ab19aSPaul Moore const struct netlbl_lsm_secattr *secattr) 599014ab19aSPaul Moore { 600014ab19aSPaul Moore return -ENOSYS; 601014ab19aSPaul Moore } 602389fb800SPaul Moore static inline int netlbl_req_setattr(struct request_sock *req, 603389fb800SPaul Moore const struct netlbl_lsm_secattr *secattr) 604389fb800SPaul Moore { 605389fb800SPaul Moore return -ENOSYS; 606389fb800SPaul Moore } 60707feee8fSPaul Moore static inline void netlbl_req_delattr(struct request_sock *req) 60807feee8fSPaul Moore { 60907feee8fSPaul Moore return; 61007feee8fSPaul Moore } 611948bf85cSPaul Moore static inline int netlbl_skbuff_setattr(struct sk_buff *skb, 612948bf85cSPaul Moore u16 family, 613948bf85cSPaul Moore const struct netlbl_lsm_secattr *secattr) 614948bf85cSPaul Moore { 615948bf85cSPaul Moore return -ENOSYS; 616948bf85cSPaul Moore } 61711a03f78SPaul Moore static inline int netlbl_skbuff_getattr(const struct sk_buff *skb, 61875e22910SPaul Moore u16 family, 61911a03f78SPaul Moore struct netlbl_lsm_secattr *secattr) 62011a03f78SPaul Moore { 62111a03f78SPaul Moore return -ENOSYS; 62211a03f78SPaul Moore } 623dfaebe98SPaul Moore static inline void netlbl_skbuff_err(struct sk_buff *skb, 624dfaebe98SPaul Moore int error, 625dfaebe98SPaul Moore int gateway) 62611a03f78SPaul Moore { 62711a03f78SPaul Moore return; 62811a03f78SPaul Moore } 62911a03f78SPaul Moore static inline void netlbl_cache_invalidate(void) 63011a03f78SPaul Moore { 63111a03f78SPaul Moore return; 63211a03f78SPaul Moore } 63311a03f78SPaul Moore static inline int netlbl_cache_add(const struct sk_buff *skb, 63411a03f78SPaul Moore const struct netlbl_lsm_secattr *secattr) 63511a03f78SPaul Moore { 63611a03f78SPaul Moore return 0; 63711a03f78SPaul Moore } 6386c2e8ac0SPaul Moore static inline struct audit_buffer *netlbl_audit_start(int type, 6396c2e8ac0SPaul Moore struct netlbl_audit *audit_info) 6406c2e8ac0SPaul Moore { 6416c2e8ac0SPaul Moore return NULL; 6426c2e8ac0SPaul Moore } 64311a03f78SPaul Moore #endif /* CONFIG_NETLABEL */ 64411a03f78SPaul Moore 645cb72d382SHuw Davies const struct netlbl_calipso_ops * 646cb72d382SHuw Davies netlbl_calipso_ops_register(const struct netlbl_calipso_ops *ops); 647cb72d382SHuw Davies 64811a03f78SPaul Moore #endif /* _NETLABEL_H */ 649