···151151 * @name name of the last path component used to create file152152 * @ctx pointer to place the pointer to the resulting context in.153153 * @ctxlen point to place the length of the resulting context.154154+ * @dentry_create_files_as:155155+ * Compute a context for a dentry as the inode is not yet available156156+ * and set that context in passed in creds so that new files are157157+ * created using that context. Context is calculated using the158158+ * passed in creds and not the creds of the caller.159159+ * @dentry dentry to use in calculating the context.160160+ * @mode mode used to determine resource type.161161+ * @name name of the last path component used to create file162162+ * @old creds which should be used for context calculation163163+ * @new creds to modify154164 *155165 *156166 * Security hooks for inode operations.···411401 * @inode contains a pointer to the inode.412402 * @secid contains a pointer to the location where result will be saved.413403 * In case of failure, @secid will be set to zero.404404+ * @inode_copy_up:405405+ * A file is about to be copied up from lower layer to upper layer of406406+ * overlay filesystem. Security module can prepare a set of new creds407407+ * and modify as need be and return new creds. Caller will switch to408408+ * new creds temporarily to create new file and release newly allocated409409+ * creds.410410+ * @src indicates the union dentry of file that is being copied up.411411+ * @new pointer to pointer to return newly allocated creds.412412+ * Returns 0 on success or a negative error code on error.413413+ * @inode_copy_up_xattr:414414+ * Filter the xattrs being copied up when a unioned file is copied415415+ * up from a lower layer to the union/overlay layer.416416+ * @name indicates the name of the xattr.417417+ * Returns 0 to accept the xattr, 1 to discard the xattr, -EOPNOTSUPP if418418+ * security module does not know about attribute or a negative error code419419+ * to abort the copy up. Note that the caller is responsible for reading420420+ * and writing the xattrs as this hook is merely a filter.414421 *415422 * Security hooks for file operations416423 *···13851358 int (*dentry_init_security)(struct dentry *dentry, int mode,13861359 const struct qstr *name, void **ctx,13871360 u32 *ctxlen);13611361+ int (*dentry_create_files_as)(struct dentry *dentry, int mode,13621362+ struct qstr *name,13631363+ const struct cred *old,13641364+ struct cred *new);138813651389136613901367#ifdef CONFIG_SECURITY_PATH···14561425 int (*inode_listsecurity)(struct inode *inode, char *buffer,14571426 size_t buffer_size);14581427 void (*inode_getsecid)(struct inode *inode, u32 *secid);14281428+ int (*inode_copy_up)(struct dentry *src, struct cred **new);14291429+ int (*inode_copy_up_xattr)(const char *name);1459143014601431 int (*file_permission)(struct file *file, int mask);14611432 int (*file_alloc_security)(struct file *file);···16881655 struct list_head sb_clone_mnt_opts;16891656 struct list_head sb_parse_opts_str;16901657 struct list_head dentry_init_security;16581658+ struct list_head dentry_create_files_as;16911659#ifdef CONFIG_SECURITY_PATH16921660 struct list_head path_unlink;16931661 struct list_head path_mkdir;···17291695 struct list_head inode_setsecurity;17301696 struct list_head inode_listsecurity;17311697 struct list_head inode_getsecid;16981698+ struct list_head inode_copy_up;16991699+ struct list_head inode_copy_up_xattr;17321700 struct list_head file_permission;17331701 struct list_head file_alloc_security;17341702 struct list_head file_free_security;
···9393 via /selinux/checkreqprot if authorized by policy.94949595 If you are unsure how to answer this question, answer 0.9696-9797-config SECURITY_SELINUX_POLICYDB_VERSION_MAX9898- bool "NSA SELinux maximum supported policy format version"9999- depends on SECURITY_SELINUX100100- default n101101- help102102- This option enables the maximum policy format version supported103103- by SELinux to be set to a particular value. This value is reported104104- to userspace via /selinux/policyvers and used at policy load time.105105- It can be adjusted downward to support legacy userland (init) that106106- does not correctly handle kernels that support newer policy versions.107107-108108- Examples:109109- For the Fedora Core 3 or 4 Linux distributions, enable this option110110- and set the value via the next option. For Fedora Core 5 and later,111111- do not enable this option.112112-113113- If you are unsure how to answer this question, answer N.114114-115115-config SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE116116- int "NSA SELinux maximum supported policy format version value"117117- depends on SECURITY_SELINUX_POLICYDB_VERSION_MAX118118- range 15 23119119- default 19120120- help121121- This option sets the value for the maximum policy format version122122- supported by SELinux.123123-124124- Examples:125125- For Fedora Core 3, use 18.126126- For Fedora Core 4, use 19.127127-128128- If you are unsure how to answer this question, look for the129129- policy format version supported by your policy toolchain, by130130- running 'checkpolicy -V'. Or look at what policy you have131131- installed under /etc/selinux/$SELINUXTYPE/policy, where132132- SELINUXTYPE is defined in your /etc/selinux/config.133133-
+75-15
security/selinux/hooks.c
···18081808/*18091809 * Determine the label for an inode that might be unioned.18101810 */18111811-static int selinux_determine_inode_label(struct inode *dir,18121812- const struct qstr *name,18131813- u16 tclass,18141814- u32 *_new_isid)18111811+static int18121812+selinux_determine_inode_label(const struct task_security_struct *tsec,18131813+ struct inode *dir,18141814+ const struct qstr *name, u16 tclass,18151815+ u32 *_new_isid)18151816{18161817 const struct superblock_security_struct *sbsec = dir->i_sb->s_security;18171817- const struct task_security_struct *tsec = current_security();1818181818191819 if ((sbsec->flags & SE_SBINITIALIZED) &&18201820 (sbsec->behavior == SECURITY_FS_USE_MNTPOINT)) {···18571857 if (rc)18581858 return rc;1859185918601860- rc = selinux_determine_inode_label(dir, &dentry->d_name, tclass,18611861- &newsid);18601860+ rc = selinux_determine_inode_label(current_security(), dir,18611861+ &dentry->d_name, tclass, &newsid);18621862 if (rc)18631863 return rc;18641864···28382838 u32 newsid;28392839 int rc;2840284028412841- rc = selinux_determine_inode_label(d_inode(dentry->d_parent), name,28412841+ rc = selinux_determine_inode_label(current_security(),28422842+ d_inode(dentry->d_parent), name,28422843 inode_mode_to_security_class(mode),28432844 &newsid);28442845 if (rc)28452846 return rc;2846284728472848 return security_sid_to_context(newsid, (char **)ctx, ctxlen);28492849+}28502850+28512851+static int selinux_dentry_create_files_as(struct dentry *dentry, int mode,28522852+ struct qstr *name,28532853+ const struct cred *old,28542854+ struct cred *new)28552855+{28562856+ u32 newsid;28572857+ int rc;28582858+ struct task_security_struct *tsec;28592859+28602860+ rc = selinux_determine_inode_label(old->security,28612861+ d_inode(dentry->d_parent), name,28622862+ inode_mode_to_security_class(mode),28632863+ &newsid);28642864+ if (rc)28652865+ return rc;28662866+28672867+ tsec = new->security;28682868+ tsec->create_sid = newsid;28692869+ return 0;28482870}2849287128502872static int selinux_inode_init_security(struct inode *inode, struct inode *dir,···28852863 sid = tsec->sid;28862864 newsid = tsec->create_sid;2887286528882888- rc = selinux_determine_inode_label(28662866+ rc = selinux_determine_inode_label(current_security(),28892867 dir, qstr,28902868 inode_mode_to_security_class(inode->i_mode),28912869 &newsid);···33133291{33143292 struct inode_security_struct *isec = inode_security_novalidate(inode);33153293 *secid = isec->sid;32943294+}32953295+32963296+static int selinux_inode_copy_up(struct dentry *src, struct cred **new)32973297+{32983298+ u32 sid;32993299+ struct task_security_struct *tsec;33003300+ struct cred *new_creds = *new;33013301+33023302+ if (new_creds == NULL) {33033303+ new_creds = prepare_creds();33043304+ if (!new_creds)33053305+ return -ENOMEM;33063306+ }33073307+33083308+ tsec = new_creds->security;33093309+ /* Get label from overlay inode and set it in create_sid */33103310+ selinux_inode_getsecid(d_inode(src), &sid);33113311+ tsec->create_sid = sid;33123312+ *new = new_creds;33133313+ return 0;33143314+}33153315+33163316+static int selinux_inode_copy_up_xattr(const char *name)33173317+{33183318+ /* The copy_up hook above sets the initial context on an inode, but we33193319+ * don't then want to overwrite it by blindly copying all the lower33203320+ * xattrs up. Instead, we have to filter out SELinux-related xattrs.33213321+ */33223322+ if (strcmp(name, XATTR_NAME_SELINUX) == 0)33233323+ return 1; /* Discard */33243324+ /*33253325+ * Any other attribute apart from SELINUX is not claimed, supported33263326+ * by selinux.33273327+ */33283328+ return -EOPNOTSUPP;33163329}3317333033183331/* file security operations */···40413984 return ret;40423985}4043398640444044-#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)39873987+#if IS_ENABLED(CONFIG_IPV6)4045398840463989/* Returns error only if unable to parse addresses */40473990static int selinux_parse_skb_ipv6(struct sk_buff *skb,···41324075 &ad->u.net->v4info.daddr);41334076 goto okay;4134407741354135-#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)40784078+#if IS_ENABLED(CONFIG_IPV6)41364079 case PF_INET6:41374080 ret = selinux_parse_skb_ipv6(skb, ad, proto);41384081 if (ret)···50865029 return selinux_ip_forward(skb, state->in, PF_INET);50875030}5088503150895089-#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)50325032+#if IS_ENABLED(CONFIG_IPV6)50905033static unsigned int selinux_ipv6_forward(void *priv,50915034 struct sk_buff *skb,50925035 const struct nf_hook_state *state)···51445087 return selinux_ip_output(skb, PF_INET);51455088}5146508951475147-#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)50905090+#if IS_ENABLED(CONFIG_IPV6)51485091static unsigned int selinux_ipv6_output(void *priv,51495092 struct sk_buff *skb,51505093 const struct nf_hook_state *state)···53305273 return selinux_ip_postroute(skb, state->out, PF_INET);53315274}5332527553335333-#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)52765276+#if IS_ENABLED(CONFIG_IPV6)53345277static unsigned int selinux_ipv6_postroute(void *priv,53355278 struct sk_buff *skb,53365279 const struct nf_hook_state *state)···61196062 LSM_HOOK_INIT(sb_parse_opts_str, selinux_parse_opts_str),6120606361216064 LSM_HOOK_INIT(dentry_init_security, selinux_dentry_init_security),60656065+ LSM_HOOK_INIT(dentry_create_files_as, selinux_dentry_create_files_as),6122606661236067 LSM_HOOK_INIT(inode_alloc_security, selinux_inode_alloc_security),61246068 LSM_HOOK_INIT(inode_free_security, selinux_inode_free_security),···61466088 LSM_HOOK_INIT(inode_setsecurity, selinux_inode_setsecurity),61476089 LSM_HOOK_INIT(inode_listsecurity, selinux_inode_listsecurity),61486090 LSM_HOOK_INIT(inode_getsecid, selinux_inode_getsecid),60916091+ LSM_HOOK_INIT(inode_copy_up, selinux_inode_copy_up),60926092+ LSM_HOOK_INIT(inode_copy_up_xattr, selinux_inode_copy_up_xattr),6149609361506094 LSM_HOOK_INIT(file_permission, selinux_file_permission),61516095 LSM_HOOK_INIT(file_alloc_security, selinux_file_alloc_security),···63776317 .hooknum = NF_INET_LOCAL_OUT,63786318 .priority = NF_IP_PRI_SELINUX_FIRST,63796319 },63806380-#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)63206320+#if IS_ENABLED(CONFIG_IPV6)63816321 {63826322 .hook = selinux_ipv6_postroute,63836323 .pf = NFPROTO_IPV6,
-4
security/selinux/include/security.h
···39394040/* Range of policy versions we understand*/4141#define POLICYDB_VERSION_MIN POLICYDB_VERSION_BASE4242-#ifdef CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX4343-#define POLICYDB_VERSION_MAX CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE4444-#else4542#define POLICYDB_VERSION_MAX POLICYDB_VERSION_XPERMS_IOCTL4646-#endif47434844/* Mask for just the mount related flags */4945#define SE_MNTMASK 0x0f