Skip to content

Commit de2f4b3

Browse files
author
James Morris
committed
Merge branch 'stable-4.9' of git://git.infradead.org/users/pcmoore/selinux into next
2 parents e350e24 + 9b6a9ec commit de2f4b3

13 files changed

Lines changed: 211 additions & 65 deletions

File tree

‎fs/overlayfs/copy_up.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ int ovl_copy_xattr(struct dentry *old, struct dentry *new)
103103
goto retry;
104104
}
105105

106+
error = security_inode_copy_up_xattr(name);
107+
if (error < 0 && error != -EOPNOTSUPP)
108+
break;
109+
if (error == 1) {
110+
error = 0;
111+
continue; /* Discard */
112+
}
106113
error = vfs_setxattr(new, name, value, size, 0);
107114
if (error)
108115
break;
@@ -246,6 +253,8 @@ static int ovl_copy_up_locked(struct dentry *workdir, struct dentry *upperdir,
246253
struct dentry *upper = NULL;
247254
umode_t mode = stat->mode;
248255
int err;
256+
const struct cred *old_creds = NULL;
257+
struct cred *new_creds = NULL;
249258

250259
newdentry = ovl_lookup_temp(workdir, dentry);
251260
err = PTR_ERR(newdentry);
@@ -258,10 +267,23 @@ static int ovl_copy_up_locked(struct dentry *workdir, struct dentry *upperdir,
258267
if (IS_ERR(upper))
259268
goto out1;
260269

270+
err = security_inode_copy_up(dentry, &new_creds);
271+
if (err < 0)
272+
goto out2;
273+
274+
if (new_creds)
275+
old_creds = override_creds(new_creds);
276+
261277
/* Can't properly set mode on creation because of the umask */
262278
stat->mode &= S_IFMT;
263279
err = ovl_create_real(wdir, newdentry, stat, link, NULL, true);
264280
stat->mode = mode;
281+
282+
if (new_creds) {
283+
revert_creds(old_creds);
284+
put_cred(new_creds);
285+
}
286+
265287
if (err)
266288
goto out2;
267289

‎fs/overlayfs/dir.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,15 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,
435435
if (override_cred) {
436436
override_cred->fsuid = inode->i_uid;
437437
override_cred->fsgid = inode->i_gid;
438+
if (!hardlink) {
439+
err = security_dentry_create_files_as(dentry,
440+
stat->mode, &dentry->d_name, old_cred,
441+
override_cred);
442+
if (err) {
443+
put_cred(override_cred);
444+
goto out_revert_creds;
445+
}
446+
}
438447
put_cred(override_creds(override_cred));
439448
put_cred(override_cred);
440449

@@ -445,6 +454,7 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,
445454
err = ovl_create_over_whiteout(dentry, inode, stat,
446455
link, hardlink);
447456
}
457+
out_revert_creds:
448458
revert_creds(old_cred);
449459
if (!err) {
450460
struct inode *realinode = d_inode(ovl_dentry_upper(dentry));

‎include/linux/lsm_hooks.h‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,16 @@
151151
* @name name of the last path component used to create file
152152
* @ctx pointer to place the pointer to the resulting context in.
153153
* @ctxlen point to place the length of the resulting context.
154+
* @dentry_create_files_as:
155+
* Compute a context for a dentry as the inode is not yet available
156+
* and set that context in passed in creds so that new files are
157+
* created using that context. Context is calculated using the
158+
* passed in creds and not the creds of the caller.
159+
* @dentry dentry to use in calculating the context.
160+
* @mode mode used to determine resource type.
161+
* @name name of the last path component used to create file
162+
* @old creds which should be used for context calculation
163+
* @new creds to modify
154164
*
155165
*
156166
* Security hooks for inode operations.
@@ -401,6 +411,23 @@
401411
* @inode contains a pointer to the inode.
402412
* @secid contains a pointer to the location where result will be saved.
403413
* In case of failure, @secid will be set to zero.
414+
* @inode_copy_up:
415+
* A file is about to be copied up from lower layer to upper layer of
416+
* overlay filesystem. Security module can prepare a set of new creds
417+
* and modify as need be and return new creds. Caller will switch to
418+
* new creds temporarily to create new file and release newly allocated
419+
* creds.
420+
* @src indicates the union dentry of file that is being copied up.
421+
* @new pointer to pointer to return newly allocated creds.
422+
* Returns 0 on success or a negative error code on error.
423+
* @inode_copy_up_xattr:
424+
* Filter the xattrs being copied up when a unioned file is copied
425+
* up from a lower layer to the union/overlay layer.
426+
* @name indicates the name of the xattr.
427+
* Returns 0 to accept the xattr, 1 to discard the xattr, -EOPNOTSUPP if
428+
* security module does not know about attribute or a negative error code
429+
* to abort the copy up. Note that the caller is responsible for reading
430+
* and writing the xattrs as this hook is merely a filter.
404431
*
405432
* Security hooks for file operations
406433
*
@@ -1358,6 +1385,10 @@ union security_list_options {
13581385
int (*dentry_init_security)(struct dentry *dentry, int mode,
13591386
const struct qstr *name, void **ctx,
13601387
u32 *ctxlen);
1388+
int (*dentry_create_files_as)(struct dentry *dentry, int mode,
1389+
struct qstr *name,
1390+
const struct cred *old,
1391+
struct cred *new);
13611392

13621393

13631394
#ifdef CONFIG_SECURITY_PATH
@@ -1425,6 +1456,8 @@ union security_list_options {
14251456
int (*inode_listsecurity)(struct inode *inode, char *buffer,
14261457
size_t buffer_size);
14271458
void (*inode_getsecid)(struct inode *inode, u32 *secid);
1459+
int (*inode_copy_up)(struct dentry *src, struct cred **new);
1460+
int (*inode_copy_up_xattr)(const char *name);
14281461

14291462
int (*file_permission)(struct file *file, int mask);
14301463
int (*file_alloc_security)(struct file *file);
@@ -1655,6 +1688,7 @@ struct security_hook_heads {
16551688
struct list_head sb_clone_mnt_opts;
16561689
struct list_head sb_parse_opts_str;
16571690
struct list_head dentry_init_security;
1691+
struct list_head dentry_create_files_as;
16581692
#ifdef CONFIG_SECURITY_PATH
16591693
struct list_head path_unlink;
16601694
struct list_head path_mkdir;
@@ -1695,6 +1729,8 @@ struct security_hook_heads {
16951729
struct list_head inode_setsecurity;
16961730
struct list_head inode_listsecurity;
16971731
struct list_head inode_getsecid;
1732+
struct list_head inode_copy_up;
1733+
struct list_head inode_copy_up_xattr;
16981734
struct list_head file_permission;
16991735
struct list_head file_alloc_security;
17001736
struct list_head file_free_security;

‎include/linux/security.h‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ int security_sb_parse_opts_str(char *options, struct security_mnt_opts *opts);
242242
int security_dentry_init_security(struct dentry *dentry, int mode,
243243
const struct qstr *name, void **ctx,
244244
u32 *ctxlen);
245+
int security_dentry_create_files_as(struct dentry *dentry, int mode,
246+
struct qstr *name,
247+
const struct cred *old,
248+
struct cred *new);
245249

246250
int security_inode_alloc(struct inode *inode);
247251
void security_inode_free(struct inode *inode);
@@ -282,6 +286,8 @@ int security_inode_getsecurity(struct inode *inode, const char *name, void **buf
282286
int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags);
283287
int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size);
284288
void security_inode_getsecid(struct inode *inode, u32 *secid);
289+
int security_inode_copy_up(struct dentry *src, struct cred **new);
290+
int security_inode_copy_up_xattr(const char *name);
285291
int security_file_permission(struct file *file, int mask);
286292
int security_file_alloc(struct file *file);
287293
void security_file_free(struct file *file);
@@ -597,6 +603,14 @@ static inline int security_dentry_init_security(struct dentry *dentry,
597603
return -EOPNOTSUPP;
598604
}
599605

606+
static inline int security_dentry_create_files_as(struct dentry *dentry,
607+
int mode, struct qstr *name,
608+
const struct cred *old,
609+
struct cred *new)
610+
{
611+
return 0;
612+
}
613+
600614

601615
static inline int security_inode_init_security(struct inode *inode,
602616
struct inode *dir,
@@ -757,6 +771,16 @@ static inline void security_inode_getsecid(struct inode *inode, u32 *secid)
757771
*secid = 0;
758772
}
759773

774+
static inline int security_inode_copy_up(struct dentry *src, struct cred **new)
775+
{
776+
return 0;
777+
}
778+
779+
static inline int security_inode_copy_up_xattr(const char *name)
780+
{
781+
return -EOPNOTSUPP;
782+
}
783+
760784
static inline int security_file_permission(struct file *file, int mask)
761785
{
762786
return 0;

‎security/lsm_audit.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ int ipv4_skb_to_auditdata(struct sk_buff *skb,
9999
}
100100
return ret;
101101
}
102-
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
102+
#if IS_ENABLED(CONFIG_IPV6)
103103
/**
104104
* ipv6_skb_to_auditdata : fill auditdata from skb
105105
* @skb : the skb
@@ -257,7 +257,7 @@ static void dump_common_audit_data(struct audit_buffer *ab,
257257
audit_log_format(ab, " ino=%lu", inode->i_ino);
258258
}
259259

260-
audit_log_format(ab, " ioctlcmd=%hx", a->u.op->cmd);
260+
audit_log_format(ab, " ioctlcmd=0x%hx", a->u.op->cmd);
261261
break;
262262
}
263263
case LSM_AUDIT_DATA_DENTRY: {

‎security/security.c‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,15 @@ int security_dentry_init_security(struct dentry *dentry, int mode,
364364
}
365365
EXPORT_SYMBOL(security_dentry_init_security);
366366

367+
int security_dentry_create_files_as(struct dentry *dentry, int mode,
368+
struct qstr *name,
369+
const struct cred *old, struct cred *new)
370+
{
371+
return call_int_hook(dentry_create_files_as, 0, dentry, mode,
372+
name, old, new);
373+
}
374+
EXPORT_SYMBOL(security_dentry_create_files_as);
375+
367376
int security_inode_init_security(struct inode *inode, struct inode *dir,
368377
const struct qstr *qstr,
369378
const initxattrs initxattrs, void *fs_data)
@@ -748,6 +757,18 @@ void security_inode_getsecid(struct inode *inode, u32 *secid)
748757
call_void_hook(inode_getsecid, inode, secid);
749758
}
750759

760+
int security_inode_copy_up(struct dentry *src, struct cred **new)
761+
{
762+
return call_int_hook(inode_copy_up, 0, src, new);
763+
}
764+
EXPORT_SYMBOL(security_inode_copy_up);
765+
766+
int security_inode_copy_up_xattr(const char *name)
767+
{
768+
return call_int_hook(inode_copy_up_xattr, -EOPNOTSUPP, name);
769+
}
770+
EXPORT_SYMBOL(security_inode_copy_up_xattr);
771+
751772
int security_file_permission(struct file *file, int mask)
752773
{
753774
int ret;
@@ -1623,6 +1644,8 @@ struct security_hook_heads security_hook_heads = {
16231644
LIST_HEAD_INIT(security_hook_heads.sb_parse_opts_str),
16241645
.dentry_init_security =
16251646
LIST_HEAD_INIT(security_hook_heads.dentry_init_security),
1647+
.dentry_create_files_as =
1648+
LIST_HEAD_INIT(security_hook_heads.dentry_create_files_as),
16261649
#ifdef CONFIG_SECURITY_PATH
16271650
.path_unlink = LIST_HEAD_INIT(security_hook_heads.path_unlink),
16281651
.path_mkdir = LIST_HEAD_INIT(security_hook_heads.path_mkdir),
@@ -1684,6 +1707,10 @@ struct security_hook_heads security_hook_heads = {
16841707
LIST_HEAD_INIT(security_hook_heads.inode_listsecurity),
16851708
.inode_getsecid =
16861709
LIST_HEAD_INIT(security_hook_heads.inode_getsecid),
1710+
.inode_copy_up =
1711+
LIST_HEAD_INIT(security_hook_heads.inode_copy_up),
1712+
.inode_copy_up_xattr =
1713+
LIST_HEAD_INIT(security_hook_heads.inode_copy_up_xattr),
16871714
.file_permission =
16881715
LIST_HEAD_INIT(security_hook_heads.file_permission),
16891716
.file_alloc_security =

‎security/selinux/Kconfig‎

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -93,41 +93,3 @@ config SECURITY_SELINUX_CHECKREQPROT_VALUE
9393
via /selinux/checkreqprot if authorized by policy.
9494

9595
If you are unsure how to answer this question, answer 0.
96-
97-
config SECURITY_SELINUX_POLICYDB_VERSION_MAX
98-
bool "NSA SELinux maximum supported policy format version"
99-
depends on SECURITY_SELINUX
100-
default n
101-
help
102-
This option enables the maximum policy format version supported
103-
by SELinux to be set to a particular value. This value is reported
104-
to userspace via /selinux/policyvers and used at policy load time.
105-
It can be adjusted downward to support legacy userland (init) that
106-
does not correctly handle kernels that support newer policy versions.
107-
108-
Examples:
109-
For the Fedora Core 3 or 4 Linux distributions, enable this option
110-
and set the value via the next option. For Fedora Core 5 and later,
111-
do not enable this option.
112-
113-
If you are unsure how to answer this question, answer N.
114-
115-
config SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE
116-
int "NSA SELinux maximum supported policy format version value"
117-
depends on SECURITY_SELINUX_POLICYDB_VERSION_MAX
118-
range 15 23
119-
default 19
120-
help
121-
This option sets the value for the maximum policy format version
122-
supported by SELinux.
123-
124-
Examples:
125-
For Fedora Core 3, use 18.
126-
For Fedora Core 4, use 19.
127-
128-
If you are unsure how to answer this question, look for the
129-
policy format version supported by your policy toolchain, by
130-
running 'checkpolicy -V'. Or look at what policy you have
131-
installed under /etc/selinux/$SELINUXTYPE/policy, where
132-
SELINUXTYPE is defined in your /etc/selinux/config.
133-

0 commit comments

Comments
 (0)