Skip to content

Commit b3aa112

Browse files
committed
Merge tag 'selinux-pr-20200330' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux
Pull SELinux updates from Paul Moore: "We've got twenty SELinux patches for the v5.7 merge window, the highlights are below: - Deprecate setting /sys/fs/selinux/checkreqprot to 1. This flag was originally created to deal with legacy userspace and the READ_IMPLIES_EXEC personality flag. We changed the default from 1 to 0 back in Linux v4.4 and now we are taking the next step of deprecating it, at some point in the future we will take the final step of rejecting 1. - Allow kernfs symlinks to inherit the SELinux label of the parent directory. In order to preserve backwards compatibility this is protected by the genfs_seclabel_symlinks SELinux policy capability. - Optimize how we store filename transitions in the kernel, resulting in some significant improvements to policy load times. - Do a better job calculating our internal hash table sizes which resulted in additional policy load improvements and likely general SELinux performance improvements as well. - Remove the unused initial SIDs (labels) and improve how we handle initial SIDs. - Enable per-file labeling for the bpf filesystem. - Ensure that we properly label NFS v4.2 filesystems to avoid a temporary unlabeled condition. - Add some missing XFS quota command types to the SELinux quota access controls. - Fix a problem where we were not updating the seq_file position index correctly in selinuxfs. - We consolidate some duplicated code into helper functions. - A number of list to array conversions. - Update Stephen Smalley's email address in MAINTAINERS" * tag 'selinux-pr-20200330' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux: selinux: clean up indentation issue with assignment statement NFS: Ensure security label is set for root inode MAINTAINERS: Update my email address selinux: avtab_init() and cond_policydb_init() return void selinux: clean up error path in policydb_init() selinux: remove unused initial SIDs and improve handling selinux: reduce the use of hard-coded hash sizes selinux: Add xfs quota command types selinux: optimize storage of filename transitions selinux: factor out loop body from filename_trans_read() security: selinux: allow per-file labeling for bpffs selinux: generalize evaluate_cond_node() selinux: convert cond_expr to array selinux: convert cond_av_list to array selinux: convert cond_list to array selinux: sel_avc_get_stat_idx should increase position index selinux: allow kernfs symlinks to inherit parent directory context selinux: simplify evaluate_cond_node() Documentation,selinux: deprecate setting checkreqprot to 1 selinux: move status variables out of selinux_ss
2 parents 674d85e + c753924 commit b3aa112

File tree

26 files changed

+521
-490
lines changed

26 files changed

+521
-490
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
What: /sys/fs/selinux/checkreqprot
2+
Date: April 2005 (predates git)
3+
KernelVersion: 2.6.12-rc2 (predates git)
4+
5+
Description:
6+
7+
The selinuxfs "checkreqprot" node allows SELinux to be configured
8+
to check the protection requested by userspace for mmap/mprotect
9+
calls instead of the actual protection applied by the kernel.
10+
This was a compatibility mechanism for legacy userspace and
11+
for the READ_IMPLIES_EXEC personality flag. However, if set to
12+
1, it weakens security by allowing mappings to be made executable
13+
without authorization by policy. The default value of checkreqprot
14+
at boot was changed starting in Linux v4.4 to 0 (i.e. check the
15+
actual protection), and Android and Linux distributions have been
16+
explicitly writing a "0" to /sys/fs/selinux/checkreqprot during
17+
initialization for some time. Support for setting checkreqprot to 1
18+
will be removed in a future kernel release, at which point the kernel
19+
will always cease using checkreqprot internally and will always
20+
check the actual protections being applied upon mmap/mprotect calls.
21+
The checkreqprot selinuxfs node will remain for backward compatibility
22+
but will discard writes of the "0" value and will reject writes of the
23+
"1" value when this mechanism is removed.

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@
525525
Default value is set via a kernel config option.
526526
Value can be changed at runtime via
527527
/sys/fs/selinux/checkreqprot.
528+
Setting checkreqprot to 1 is deprecated.
528529

529530
cio_ignore= [S390]
530531
See Documentation/s390/common_io.rst for details.

MAINTAINERS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15027,7 +15027,7 @@ X: security/selinux/
1502715027

1502815028
SELINUX SECURITY MODULE
1502915029
M: Paul Moore <[email protected]>
15030-
M: Stephen Smalley <[email protected]>
15030+
M: Stephen Smalley <[email protected]>
1503115031
M: Eric Paris <[email protected]>
1503215032
1503315033
W: https://selinuxproject.org
@@ -15039,6 +15039,7 @@ F: security/selinux/
1503915039
F: scripts/selinux/
1504015040
F: Documentation/admin-guide/LSM/SELinux.rst
1504115041
F: Documentation/ABI/obsolete/sysfs-selinux-disable
15042+
F: Documentation/ABI/obsolete/sysfs-selinux-checkreqprot
1504215043

1504315044
SENSABLE PHANTOM
1504415045
M: Jiri Slaby <[email protected]>

fs/nfs/getroot.c

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ int nfs_get_root(struct super_block *s, struct fs_context *fc)
7373
struct inode *inode;
7474
char *name;
7575
int error = -ENOMEM;
76+
unsigned long kflags = 0, kflags_out = 0;
7677

7778
name = kstrdup(fc->source, GFP_KERNEL);
7879
if (!name)
@@ -83,24 +84,27 @@ int nfs_get_root(struct super_block *s, struct fs_context *fc)
8384
if (fsinfo.fattr == NULL)
8485
goto out_name;
8586

87+
fsinfo.fattr->label = nfs4_label_alloc(server, GFP_KERNEL);
88+
if (IS_ERR(fsinfo.fattr->label))
89+
goto out_fattr;
8690
error = server->nfs_client->rpc_ops->getroot(server, ctx->mntfh, &fsinfo);
8791
if (error < 0) {
8892
dprintk("nfs_get_root: getattr error = %d\n", -error);
8993
nfs_errorf(fc, "NFS: Couldn't getattr on root");
90-
goto out_fattr;
94+
goto out_label;
9195
}
9296

9397
inode = nfs_fhget(s, ctx->mntfh, fsinfo.fattr, NULL);
9498
if (IS_ERR(inode)) {
9599
dprintk("nfs_get_root: get root inode failed\n");
96100
error = PTR_ERR(inode);
97101
nfs_errorf(fc, "NFS: Couldn't get root inode");
98-
goto out_fattr;
102+
goto out_label;
99103
}
100104

101105
error = nfs_superblock_set_dummy_root(s, inode);
102106
if (error != 0)
103-
goto out_fattr;
107+
goto out_label;
104108

105109
/* root dentries normally start off anonymous and get spliced in later
106110
* if the dentry tree reaches them; however if the dentry already
@@ -111,7 +115,7 @@ int nfs_get_root(struct super_block *s, struct fs_context *fc)
111115
dprintk("nfs_get_root: get root dentry failed\n");
112116
error = PTR_ERR(root);
113117
nfs_errorf(fc, "NFS: Couldn't get root dentry");
114-
goto out_fattr;
118+
goto out_label;
115119
}
116120

117121
security_d_instantiate(root, inode);
@@ -123,12 +127,39 @@ int nfs_get_root(struct super_block *s, struct fs_context *fc)
123127
}
124128
spin_unlock(&root->d_lock);
125129
fc->root = root;
130+
if (NFS_SB(s)->caps & NFS_CAP_SECURITY_LABEL)
131+
kflags |= SECURITY_LSM_NATIVE_LABELS;
132+
if (ctx->clone_data.sb) {
133+
if (d_inode(fc->root)->i_fop != &nfs_dir_operations) {
134+
error = -ESTALE;
135+
goto error_splat_root;
136+
}
137+
/* clone lsm security options from the parent to the new sb */
138+
error = security_sb_clone_mnt_opts(ctx->clone_data.sb,
139+
s, kflags, &kflags_out);
140+
} else {
141+
error = security_sb_set_mnt_opts(s, fc->security,
142+
kflags, &kflags_out);
143+
}
144+
if (error)
145+
goto error_splat_root;
146+
if (NFS_SB(s)->caps & NFS_CAP_SECURITY_LABEL &&
147+
!(kflags_out & SECURITY_LSM_NATIVE_LABELS))
148+
NFS_SB(s)->caps &= ~NFS_CAP_SECURITY_LABEL;
149+
150+
nfs_setsecurity(inode, fsinfo.fattr, fsinfo.fattr->label);
126151
error = 0;
127152

153+
out_label:
154+
nfs4_label_free(fsinfo.fattr->label);
128155
out_fattr:
129156
nfs_free_fattr(fsinfo.fattr);
130157
out_name:
131158
kfree(name);
132159
out:
133160
return error;
161+
error_splat_root:
162+
dput(fc->root);
163+
fc->root = NULL;
164+
goto out_label;
134165
}

fs/nfs/nfs4proc.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4002,31 +4002,25 @@ static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh,
40024002
{
40034003
int error;
40044004
struct nfs_fattr *fattr = info->fattr;
4005-
struct nfs4_label *label = NULL;
4005+
struct nfs4_label *label = fattr->label;
40064006

40074007
error = nfs4_server_capabilities(server, mntfh);
40084008
if (error < 0) {
40094009
dprintk("nfs4_get_root: getcaps error = %d\n", -error);
40104010
return error;
40114011
}
40124012

4013-
label = nfs4_label_alloc(server, GFP_KERNEL);
4014-
if (IS_ERR(label))
4015-
return PTR_ERR(label);
4016-
40174013
error = nfs4_proc_getattr(server, mntfh, fattr, label, NULL);
40184014
if (error < 0) {
40194015
dprintk("nfs4_get_root: getattr error = %d\n", -error);
4020-
goto err_free_label;
4016+
goto out;
40214017
}
40224018

40234019
if (fattr->valid & NFS_ATTR_FATTR_FSID &&
40244020
!nfs_fsid_equal(&server->fsid, &fattr->fsid))
40254021
memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid));
40264022

4027-
err_free_label:
4028-
nfs4_label_free(label);
4029-
4023+
out:
40304024
return error;
40314025
}
40324026

fs/nfs/super.c

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,6 @@ int nfs_get_tree_common(struct fs_context *fc)
11791179
struct super_block *s;
11801180
int (*compare_super)(struct super_block *, struct fs_context *) = nfs_compare_super;
11811181
struct nfs_server *server = ctx->server;
1182-
unsigned long kflags = 0, kflags_out = 0;
11831182
int error;
11841183

11851184
ctx->server = NULL;
@@ -1239,26 +1238,6 @@ int nfs_get_tree_common(struct fs_context *fc)
12391238
goto error_splat_super;
12401239
}
12411240

1242-
if (NFS_SB(s)->caps & NFS_CAP_SECURITY_LABEL)
1243-
kflags |= SECURITY_LSM_NATIVE_LABELS;
1244-
if (ctx->clone_data.sb) {
1245-
if (d_inode(fc->root)->i_fop != &nfs_dir_operations) {
1246-
error = -ESTALE;
1247-
goto error_splat_root;
1248-
}
1249-
/* clone any lsm security options from the parent to the new sb */
1250-
error = security_sb_clone_mnt_opts(ctx->clone_data.sb, s, kflags,
1251-
&kflags_out);
1252-
} else {
1253-
error = security_sb_set_mnt_opts(s, fc->security,
1254-
kflags, &kflags_out);
1255-
}
1256-
if (error)
1257-
goto error_splat_root;
1258-
if (NFS_SB(s)->caps & NFS_CAP_SECURITY_LABEL &&
1259-
!(kflags_out & SECURITY_LSM_NATIVE_LABELS))
1260-
NFS_SB(s)->caps &= ~NFS_CAP_SECURITY_LABEL;
1261-
12621241
s->s_flags |= SB_ACTIVE;
12631242
error = 0;
12641243

@@ -1268,10 +1247,6 @@ int nfs_get_tree_common(struct fs_context *fc)
12681247
out_err_nosb:
12691248
nfs_free_server(server);
12701249
goto out;
1271-
1272-
error_splat_root:
1273-
dput(fc->root);
1274-
fc->root = NULL;
12751250
error_splat_super:
12761251
deactivate_locked_super(s);
12771252
goto out;

include/linux/nfs_xdr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ struct nfs_fattr {
7575
struct nfs4_string *owner_name;
7676
struct nfs4_string *group_name;
7777
struct nfs4_threshold *mdsthreshold; /* pNFS threshold hints */
78+
struct nfs4_label *label;
7879
};
7980

8081
#define NFS_ATTR_FATTR_TYPE (1U << 0)

scripts/selinux/genheaders/genheaders.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,12 @@ int main(int argc, char *argv[])
6767
}
6868

6969
isids_len = sizeof(initial_sid_to_string) / sizeof (char *);
70-
for (i = 1; i < isids_len; i++)
71-
initial_sid_to_string[i] = stoupperx(initial_sid_to_string[i]);
70+
for (i = 1; i < isids_len; i++) {
71+
const char *s = initial_sid_to_string[i];
72+
73+
if (s)
74+
initial_sid_to_string[i] = stoupperx(s);
75+
}
7276

7377
fprintf(fout, "/* This file is automatically generated. Do not edit. */\n");
7478
fprintf(fout, "#ifndef _SELINUX_FLASK_H_\n#define _SELINUX_FLASK_H_\n\n");
@@ -82,7 +86,8 @@ int main(int argc, char *argv[])
8286

8387
for (i = 1; i < isids_len; i++) {
8488
const char *s = initial_sid_to_string[i];
85-
fprintf(fout, "#define SECINITSID_%-39s %2d\n", s, i);
89+
if (s)
90+
fprintf(fout, "#define SECINITSID_%-39s %2d\n", s, i);
8691
}
8792
fprintf(fout, "\n#define SECINITSID_NUM %d\n", i-1);
8893
fprintf(fout, "\nstatic inline bool security_is_socket_class(u16 kern_tclass)\n");

security/selinux/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ config SECURITY_SELINUX_CHECKREQPROT_VALUE
8888
'checkreqprot=' boot parameter. It may also be changed at runtime
8989
via /sys/fs/selinux/checkreqprot if authorized by policy.
9090

91+
WARNING: this option is deprecated and will be removed in a future
92+
kernel release.
93+
9194
If you are unsure how to answer this question, answer 0.
9295

9396
config SECURITY_SELINUX_SIDTAB_HASH_BITS

security/selinux/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
obj-$(CONFIG_SECURITY_SELINUX) := selinux.o
77

88
selinux-y := avc.o hooks.o selinuxfs.o netlink.o nlmsgtab.o netif.o \
9-
netnode.o netport.o \
9+
netnode.o netport.o status.o \
1010
ss/ebitmap.o ss/hashtab.o ss/symtab.o ss/sidtab.o ss/avtab.o \
11-
ss/policydb.o ss/services.o ss/conditional.o ss/mls.o ss/status.o
11+
ss/policydb.o ss/services.o ss/conditional.o ss/mls.o
1212

1313
selinux-$(CONFIG_SECURITY_NETWORK_XFRM) += xfrm.o
1414

0 commit comments

Comments
 (0)