History

Merge tag 'selinux-pr-20221003' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux

Pull SELinux updates from Paul Moore: "Six SELinux patches, all are simple and easily understood, but a list of the highlights is below: - Use 'grep -E' instead of 'egrep' in the SELinux policy install script. Fun fact, this seems to be GregKH's *second* dedicated SELinux patch since we transitioned to git (ignoring merges, the SPDX stuff, and a trivial fs reference removal when lustre was yanked); the first was back in 2011 when selinuxfs was placed in /sys/fs/selinux. Oh, the memories ... - Convert the SELinux policy boolean values to use signed integer types throughout the SELinux kernel code. Prior to this we were using a mix of signed and unsigned integers which was probably okay in this particular case, but it is definitely not a good idea in general. - Remove a reference to the SELinux runtime disable functionality in /etc/selinux/config as we are in the process of deprecating that. See [1] for more background on this if you missed the previous notes on the deprecation. - Minor cleanups: remove unneeded variables and function parameter constification" Link: https://github.com/SELinuxProject/selinux-kernel/wiki/DEPRECATE-runtime-disable [1] * tag 'selinux-pr-20221003' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux: selinux: remove runtime disable message in the install_policy.sh script selinux: use "grep -E" instead of "egrep" selinux: remove the unneeded result variable selinux: declare read-only parameters const selinux: use int arrays for boolean values selinux: remove an unneeded variable in sel_make_class_dir_entries()

Linus Torvalds committed 4 years ago

Commit e816da22 parents eafb121 2fe2fb47 files · +48 −56Browse files

Unified · Split

7 files
  1. scripts/selinux/install_policy.sh +2 −3
  2. security/selinux/hooks.c +9 −15
  3. security/selinux/selinuxfs.c +6 −9
  4. security/selinux/ss/context.h +9 −8
  5. security/selinux/ss/ebitmap.c +11 −10
  6. security/selinux/ss/ebitmap.h +9 −9
  7. security/selinux/ss/mls_types.h +2 −2
scripts/selinux/install_policy.sh+2−3
@@ -31,8 +31,7 @@ fi · 30 unmodified lines
3131 if selinuxenabled; then
3232 echo "SELinux is already enabled"
3333 echo "This prevents safely relabeling all files."
34− echo "Boot with selinux=0 on the kernel command-line or"
35− echo "SELINUX=disabled in /etc/selinux/config."
34+ echo "Boot with selinux=0 on the kernel command-line."
3635 exit 1
3736 fi
3837
@@ -78,7 +77,7 @@ cd /etc/selinux/dummy/contexts/files · 39 unmodified lines
7877 $SF -F file_contexts /
7978
8079 mounts=`cat /proc/$$/mounts | \
81− egrep "ext[234]|jfs|xfs|reiserfs|jffs2|gfs2|btrfs|f2fs|ocfs2" | \
80+ grep -E "ext[234]|jfs|xfs|reiserfs|jffs2|gfs2|btrfs|f2fs|ocfs2" | \
8281 awk '{ print $2 '}`
8382 $SF -F file_contexts $mounts
8483
security/selinux/hooks.c+9−15
@@ -5987,7 +5987,6 @@ static int selinux_msg_queue_alloc_security(struct kern_ipc_perm *msq) · 5986 unmodified lines
59875987 struct ipc_security_struct *isec;
59885988 struct common_audit_data ad;
59895989 u32 sid = current_sid();
5990− int rc;
59915990
59925991 isec = selinux_ipc(msq);
59935992 ipc_init_security(isec, SECCLASS_MSGQ);
@@ -5995,10 +5994,9 @@ static int selinux_msg_queue_alloc_security(struct kern_ipc_perm *msq) · 1 unmodified line
59955994 ad.type = LSM_AUDIT_DATA_IPC;
59965995 ad.u.ipc_id = msq->key;
59975996
5998− rc = avc_has_perm(&selinux_state,
5999− sid, isec->sid, SECCLASS_MSGQ,
6000− MSGQ__CREATE, &ad);
6001− return rc;
5997+ return avc_has_perm(&selinux_state,
5998+ sid, isec->sid, SECCLASS_MSGQ,
5999+ MSGQ__CREATE, &ad);
60026000 }
60036001
60046002 static int selinux_msg_queue_associate(struct kern_ipc_perm *msq, int msqflg)
@@ -6126,7 +6124,6 @@ static int selinux_shm_alloc_security(struct kern_ipc_perm *shp) · 121 unmodified lines
61266124 struct ipc_security_struct *isec;
61276125 struct common_audit_data ad;
61286126 u32 sid = current_sid();
6129− int rc;
61306127
61316128 isec = selinux_ipc(shp);
61326129 ipc_init_security(isec, SECCLASS_SHM);
@@ -6134,10 +6131,9 @@ static int selinux_shm_alloc_security(struct kern_ipc_perm *shp) · 1 unmodified line
61346131 ad.type = LSM_AUDIT_DATA_IPC;
61356132 ad.u.ipc_id = shp->key;
61366133
6137− rc = avc_has_perm(&selinux_state,
6138− sid, isec->sid, SECCLASS_SHM,
6139− SHM__CREATE, &ad);
6140− return rc;
6134+ return avc_has_perm(&selinux_state,
6135+ sid, isec->sid, SECCLASS_SHM,
6136+ SHM__CREATE, &ad);
61416137 }
61426138
61436139 static int selinux_shm_associate(struct kern_ipc_perm *shp, int shmflg)
@@ -6211,7 +6207,6 @@ static int selinux_sem_alloc_security(struct kern_ipc_perm *sma) · 67 unmodified lines
62116207 struct ipc_security_struct *isec;
62126208 struct common_audit_data ad;
62136209 u32 sid = current_sid();
6214− int rc;
62156210
62166211 isec = selinux_ipc(sma);
62176212 ipc_init_security(isec, SECCLASS_SEM);
@@ -6219,10 +6214,9 @@ static int selinux_sem_alloc_security(struct kern_ipc_perm *sma) · 1 unmodified line
62196214 ad.type = LSM_AUDIT_DATA_IPC;
62206215 ad.u.ipc_id = sma->key;
62216216
6222− rc = avc_has_perm(&selinux_state,
6223− sid, isec->sid, SECCLASS_SEM,
6224− SEM__CREATE, &ad);
6225− return rc;
6217+ return avc_has_perm(&selinux_state,
6218+ sid, isec->sid, SECCLASS_SEM,
6219+ SEM__CREATE, &ad);
62266220 }
62276221
62286222 static int selinux_sem_associate(struct kern_ipc_perm *sma, int semflg)
security/selinux/selinuxfs.c+6−9
@@ -71,7 +71,7 @@ struct selinux_fs_info { · 70 unmodified lines
7171 struct dentry *bool_dir;
7272 unsigned int bool_num;
7373 char **bool_pending_names;
74− unsigned int *bool_pending_values;
74+ int *bool_pending_values;
7575 struct dentry *class_dir;
7676 unsigned long last_class_ino;
7777 bool policy_opened;
@@ -356,7 +356,7 @@ static const struct file_operations sel_policyvers_ops = { · 278 unmodified lines
356356 /* declaration for sel_write_load */
357357 static int sel_make_bools(struct selinux_policy *newpolicy, struct dentry *bool_dir,
358358 unsigned int *bool_num, char ***bool_pending_names,
359− unsigned int **bool_pending_values);
359+ int **bool_pending_values);
360360 static int sel_make_classes(struct selinux_policy *newpolicy,
361361 struct dentry *class_dir,
362362 unsigned long *last_class_ino);
@@ -527,7 +527,7 @@ static const struct file_operations sel_policy_ops = { · 164 unmodified lines
527527 };
528528
529529 static void sel_remove_old_bool_data(unsigned int bool_num, char **bool_names,
530− unsigned int *bool_values)
530+ int *bool_values)
531531 {
532532 u32 i;
533533
@@ -545,7 +545,7 @@ static int sel_make_policy_nodes(struct selinux_fs_info *fsi, · 11 unmodified lines
545545 struct dentry *tmp_parent, *tmp_bool_dir, *tmp_class_dir, *old_dentry;
546546 unsigned int tmp_bool_num, old_bool_num;
547547 char **tmp_bool_names, **old_bool_names;
548− unsigned int *tmp_bool_values, *old_bool_values;
548+ int *tmp_bool_values, *old_bool_values;
549549 unsigned long tmp_ino = fsi->last_ino; /* Don't increment last_ino in this function */
550550
551551 tmp_parent = sel_make_disconnected_dir(fsi->sb, &tmp_ino);
@@ -1423,7 +1423,7 @@ static void sel_remove_entries(struct dentry *de) · 871 unmodified lines
14231423
14241424 static int sel_make_bools(struct selinux_policy *newpolicy, struct dentry *bool_dir,
14251425 unsigned int *bool_num, char ***bool_pending_names,
1426− unsigned int **bool_pending_values)
1426+ int **bool_pending_values)
14271427 {
14281428 int ret;
14291429 ssize_t len;
@@ -1917,7 +1917,6 @@ static int sel_make_class_dir_entries(struct selinux_policy *newpolicy, · 487 unmodified lines
19171917 struct selinux_fs_info *fsi = sb->s_fs_info;
19181918 struct dentry *dentry = NULL;
19191919 struct inode *inode = NULL;
1920− int rc;
19211920
19221921 dentry = d_alloc_name(dir, "index");
19231922 if (!dentry)
@@ -1937,9 +1936,7 @@ static int sel_make_class_dir_entries(struct selinux_policy *newpolicy, · 13 unmodified lines
19371936 if (IS_ERR(dentry))
19381937 return PTR_ERR(dentry);
19391938
1940− rc = sel_make_perm_files(newpolicy, classname, index, dentry);
1941−
1942− return rc;
1939+ return sel_make_perm_files(newpolicy, classname, index, dentry);
19431940 }
19441941
19451942 static int sel_make_classes(struct selinux_policy *newpolicy,
security/selinux/ss/context.h+9−8
@@ -38,7 +38,7 @@ static inline void mls_context_init(struct context *c) · 37 unmodified lines
3838 memset(&c->range, 0, sizeof(c->range));
3939 }
4040
41−static inline int mls_context_cpy(struct context *dst, struct context *src)
41+static inline int mls_context_cpy(struct context *dst, const struct context *src)
4242 {
4343 int rc;
4444
@@ -58,7 +58,7 @@ out: · 13 unmodified lines
5858 /*
5959 * Sets both levels in the MLS range of 'dst' to the low level of 'src'.
6060 */
61−static inline int mls_context_cpy_low(struct context *dst, struct context *src)
61+static inline int mls_context_cpy_low(struct context *dst, const struct context *src)
6262 {
6363 int rc;
6464
@@ -78,7 +78,7 @@ out: · 13 unmodified lines
7878 /*
7979 * Sets both levels in the MLS range of 'dst' to the high level of 'src'.
8080 */
81−static inline int mls_context_cpy_high(struct context *dst, struct context *src)
81+static inline int mls_context_cpy_high(struct context *dst, const struct context *src)
8282 {
8383 int rc;
8484
@@ -97,9 +97,10 @@ out: · 12 unmodified lines
9797
9898
9999 static inline int mls_context_glblub(struct context *dst,
100− struct context *c1, struct context *c2)
100+ const struct context *c1, const struct context *c2)
101101 {
102− struct mls_range *dr = &dst->range, *r1 = &c1->range, *r2 = &c2->range;
102+ struct mls_range *dr = &dst->range;
103+ const struct mls_range *r1 = &c1->range, *r2 = &c2->range;
103104 int rc = 0;
104105
105106 if (r1->level[1].sens < r2->level[0].sens ||
@@ -127,7 +128,7 @@ out: · 21 unmodified lines
127128 return rc;
128129 }
129130
130−static inline int mls_context_cmp(struct context *c1, struct context *c2)
131+static inline int mls_context_cmp(const struct context *c1, const struct context *c2)
131132 {
132133 return ((c1->range.level[0].sens == c2->range.level[0].sens) &&
133134 ebitmap_cmp(&c1->range.level[0].cat, &c2->range.level[0].cat) &&
@@ -147,7 +148,7 @@ static inline void context_init(struct context *c) · 13 unmodified lines
147148 memset(c, 0, sizeof(*c));
148149 }
149150
150−static inline int context_cpy(struct context *dst, struct context *src)
151+static inline int context_cpy(struct context *dst, const struct context *src)
151152 {
152153 int rc;
153154
@@ -180,7 +181,7 @@ static inline void context_destroy(struct context *c) · 26 unmodified lines
180181 mls_context_destroy(c);
181182 }
182183
183−static inline int context_cmp(struct context *c1, struct context *c2)
184+static inline int context_cmp(const struct context *c1, const struct context *c2)
184185 {
185186 if (c1->len && c2->len)
186187 return (c1->len == c2->len && !strcmp(c1->str, c2->str));
security/selinux/ss/ebitmap.c+11−10
@@ -28,9 +28,9 @@ · 27 unmodified lines
2828
2929 static struct kmem_cache *ebitmap_node_cachep __ro_after_init;
3030
31−int ebitmap_cmp(struct ebitmap *e1, struct ebitmap *e2)
31+int ebitmap_cmp(const struct ebitmap *e1, const struct ebitmap *e2)
3232 {
33− struct ebitmap_node *n1, *n2;
33+ const struct ebitmap_node *n1, *n2;
3434
3535 if (e1->highbit != e2->highbit)
3636 return 0;
@@ -50,9 +50,10 @@ int ebitmap_cmp(struct ebitmap *e1, struct ebitmap *e2) · 13 unmodified lines
5050 return 1;
5151 }
5252
53−int ebitmap_cpy(struct ebitmap *dst, struct ebitmap *src)
53+int ebitmap_cpy(struct ebitmap *dst, const struct ebitmap *src)
5454 {
55− struct ebitmap_node *n, *new, *prev;
55+ struct ebitmap_node *new, *prev;
56+ const struct ebitmap_node *n;
5657
5758 ebitmap_init(dst);
5859 n = src->node;
@@ -78,7 +79,7 @@ int ebitmap_cpy(struct ebitmap *dst, struct ebitmap *src) · 19 unmodified lines
7879 return 0;
7980 }
8081
81−int ebitmap_and(struct ebitmap *dst, struct ebitmap *e1, struct ebitmap *e2)
82+int ebitmap_and(struct ebitmap *dst, const struct ebitmap *e1, const struct ebitmap *e2)
8283 {
8384 struct ebitmap_node *n;
8485 int bit, rc;
@@ -217,9 +218,9 @@ netlbl_import_failure: · 132 unmodified lines
217218 * if last_e2bit is non-zero, the highest set bit in e2 cannot exceed
218219 * last_e2bit.
219220 */
220−int ebitmap_contains(struct ebitmap *e1, struct ebitmap *e2, u32 last_e2bit)
221+int ebitmap_contains(const struct ebitmap *e1, const struct ebitmap *e2, u32 last_e2bit)
221222 {
222− struct ebitmap_node *n1, *n2;
223+ const struct ebitmap_node *n1, *n2;
223224 int i;
224225
225226 if (e1->highbit < e2->highbit)
@@ -258,9 +259,9 @@ int ebitmap_contains(struct ebitmap *e1, struct ebitmap *e2, u32 last_e2bit) · 32 unmodified lines
258259 return 1;
259260 }
260261
261−int ebitmap_get_bit(struct ebitmap *e, unsigned long bit)
262+int ebitmap_get_bit(const struct ebitmap *e, unsigned long bit)
262263 {
263− struct ebitmap_node *n;
264+ const struct ebitmap_node *n;
264265
265266 if (e->highbit < bit)
266267 return 0;
@@ -467,7 +468,7 @@ bad: · 200 unmodified lines
467468 goto out;
468469 }
469470
470−int ebitmap_write(struct ebitmap *e, void *fp)
471+int ebitmap_write(const struct ebitmap *e, void *fp)
471472 {
472473 struct ebitmap_node *n;
473474 u32 count;
security/selinux/ss/ebitmap.h+9−9
@@ -44,7 +44,7 @@ struct ebitmap { · 43 unmodified lines
4444
4545 #define ebitmap_length(e) ((e)->highbit)
4646
47−static inline unsigned int ebitmap_start_positive(struct ebitmap *e,
47+static inline unsigned int ebitmap_start_positive(const struct ebitmap *e,
4848 struct ebitmap_node **n)
4949 {
5050 unsigned int ofs;
@@ -62,7 +62,7 @@ static inline void ebitmap_init(struct ebitmap *e) · 11 unmodified lines
6262 memset(e, 0, sizeof(*e));
6363 }
6464
65−static inline unsigned int ebitmap_next_positive(struct ebitmap *e,
65+static inline unsigned int ebitmap_next_positive(const struct ebitmap *e,
6666 struct ebitmap_node **n,
6767 unsigned int bit)
6868 {
@@ -85,7 +85,7 @@ static inline unsigned int ebitmap_next_positive(struct ebitmap *e, · 16 unmodified lines
8585 #define EBITMAP_NODE_OFFSET(node, bit) \
8686 (((bit) - (node)->startbit) % EBITMAP_UNIT_SIZE)
8787
88−static inline int ebitmap_node_get_bit(struct ebitmap_node *n,
88+static inline int ebitmap_node_get_bit(const struct ebitmap_node *n,
8989 unsigned int bit)
9090 {
9191 unsigned int index = EBITMAP_NODE_INDEX(n, bit);
@@ -122,15 +122,15 @@ static inline void ebitmap_node_clr_bit(struct ebitmap_node *n, · 30 unmodified lines
122122 (bit) < ebitmap_length(e); \
123123 (bit) = ebitmap_next_positive(e, &(n), bit)) \
124124
125−int ebitmap_cmp(struct ebitmap *e1, struct ebitmap *e2);
126−int ebitmap_cpy(struct ebitmap *dst, struct ebitmap *src);
127−int ebitmap_and(struct ebitmap *dst, struct ebitmap *e1, struct ebitmap *e2);
128−int ebitmap_contains(struct ebitmap *e1, struct ebitmap *e2, u32 last_e2bit);
129−int ebitmap_get_bit(struct ebitmap *e, unsigned long bit);
125+int ebitmap_cmp(const struct ebitmap *e1, const struct ebitmap *e2);
126+int ebitmap_cpy(struct ebitmap *dst, const struct ebitmap *src);
127+int ebitmap_and(struct ebitmap *dst, const struct ebitmap *e1, const struct ebitmap *e2);
128+int ebitmap_contains(const struct ebitmap *e1, const struct ebitmap *e2, u32 last_e2bit);
129+int ebitmap_get_bit(const struct ebitmap *e, unsigned long bit);
130130 int ebitmap_set_bit(struct ebitmap *e, unsigned long bit, int value);
131131 void ebitmap_destroy(struct ebitmap *e);
132132 int ebitmap_read(struct ebitmap *e, void *fp);
133−int ebitmap_write(struct ebitmap *e, void *fp);
133+int ebitmap_write(const struct ebitmap *e, void *fp);
134134 u32 ebitmap_hash(const struct ebitmap *e, u32 hash);
135135
136136 #ifdef CONFIG_NETLABEL
security/selinux/ss/mls_types.h+2−2
@@ -27,13 +27,13 @@ struct mls_range { · 26 unmodified lines
2727 struct mls_level level[2]; /* low == level[0], high == level[1] */
2828 };
2929
30−static inline int mls_level_eq(struct mls_level *l1, struct mls_level *l2)
30+static inline int mls_level_eq(const struct mls_level *l1, const struct mls_level *l2)
3131 {
3232 return ((l1->sens == l2->sens) &&
3333 ebitmap_cmp(&l1->cat, &l2->cat));
3434 }
3535
36−static inline int mls_level_dom(struct mls_level *l1, struct mls_level *l2)
36+static inline int mls_level_dom(const struct mls_level *l1, const struct mls_level *l2)
3737 {
3838 return ((l1->sens >= l2->sens) &&
3939 ebitmap_contains(&l1->cat, &l2->cat, 0));