Skip to contentSkip to conversation

selinux: remove redundant msg_msg_alloc_security

PATCH Applied Huaisheng Ye 5 participants 6 messages Jan 10, 2020 – Jan 12, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selinux: remove redundant msg_msg_alloc_security

From: Huaisheng Ye <[email protected]>

selinux_msg_msg_alloc_security only calls msg_msg_alloc_security but do nothing else. And also msg_msg_alloc_security is just used by the former.

Remove the redundant function to simplify the code.

---
 security/selinux/hooks.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)
security/selinux/hooks.c +6 -11
index 9625b99..fb1b9da 100644
@@ -5882,16 +5882,6 @@ static void ipc_init_security(struct ipc_security_struct *isec, u16 sclass)
 	isec->sid = current_sid();
 }
 
-static int msg_msg_alloc_security(struct msg_msg *msg)
-{
-	struct msg_security_struct *msec;
-
-	msec = selinux_msg_msg(msg);
-	msec->sid = SECINITSID_UNLABELED;
-
-	return 0;
-}
-
 static int ipc_has_perm(struct kern_ipc_perm *ipc_perms,
 			u32 perms)
 {
@@ -5910,7 +5900,12 @@ static int ipc_has_perm(struct kern_ipc_perm *ipc_perms,
 
 static int selinux_msg_msg_alloc_security(struct msg_msg *msg)
 {
-	return msg_msg_alloc_security(msg);
+	struct msg_security_struct *msec;
+
+	msec = selinux_msg_msg(msg);
+	msec->sid = SECINITSID_UNLABELED;
+
+	return 0;
 }
 
 /* message queue security operations */
Signature · 1 line
1.8.3.1
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Huaisheng Ye

From: Huaisheng Ye <[email protected]>

selinux_msg_msg_alloc_security only calls msg_msg_alloc_security but do nothing else. And also msg_msg_alloc_security is just used by the former.

Remove the redundant function to simplify the code.

This seems to also be true of other _alloc_security functions, probably due to historical reasons. Further, at least some of these functions no longer perform any allocation; they are just initialization functions now that allocation has been taken to the LSM framework, so possibly could be renamed and made to return void at some point.

Quoted 2 lines
Quoted 40 lines
---
  security/selinux/hooks.c | 17 ++++++-----------
  1 file changed, 6 insertions(+), 11 deletions(-)
security/selinux/hooks.c +6 -11
index 9625b99..fb1b9da 100644
@@ -5882,16 +5882,6 @@ static void ipc_init_security(struct ipc_security_struct *isec, u16 sclass)
  	isec->sid = current_sid();
  }
 
-static int msg_msg_alloc_security(struct msg_msg *msg)
-{
-	struct msg_security_struct *msec;
-
-	msec = selinux_msg_msg(msg);
-	msec->sid = SECINITSID_UNLABELED;
-
-	return 0;
-}
-
  static int ipc_has_perm(struct kern_ipc_perm *ipc_perms,
  			u32 perms)
  {
@@ -5910,7 +5900,12 @@ static int ipc_has_perm(struct kern_ipc_perm *ipc_perms,
 
  static int selinux_msg_msg_alloc_security(struct msg_msg *msg)
  {
-	return msg_msg_alloc_security(msg);
+	struct msg_security_struct *msec;
+
+	msec = selinux_msg_msg(msg);
+	msec->sid = SECINITSID_UNLABELED;
+
+	return 0;
  }
 
  /* message queue security operations */
#2 lore raw
Quoted 10 lines · Stephen Smalley
Quoted 7 lines · Huaisheng Ye

From: Huaisheng Ye <[email protected]>

selinux_msg_msg_alloc_security only calls msg_msg_alloc_security but do nothing else. And also msg_msg_alloc_security is just used by the former.

Remove the redundant function to simplify the code.

This seems to also be true of other _alloc_security functions, probably due to historical reasons.  Further, at least some of these functions no longer perform any allocation; they are just initialization functions now that allocation has been taken to the LSM framework, so possibly could be renamed and made to return void at some point.

That's something I've been eyeing. I'm not 100% sure that no module will ever fail doing the new style initialization. The int to void and name change will probably happen after the next round of modules come in and we can see that failure of initialization isn't a rational situation.

Quoted 45 lines
Quoted 3 lines
Quoted 37 lines

---
  security/selinux/hooks.c | 17 ++++++-----------

  1 file changed, 6 insertions(+), 11 deletions(-)
security/selinux/hooks.c +6 -10
index 9625b99..fb1b9da 100644
@@ -5882,16 +5882,6 @@ static void ipc_init_security(struct ipc_security_struct *isec, u16 sclass)
       isec->sid = current_sid();
   }
   -static int msg_msg_alloc_security(struct msg_msg *msg)
-{
-    struct msg_security_struct *msec;
-
-    msec = selinux_msg_msg(msg);
-    msec->sid = SECINITSID_UNLABELED;
-
-    return 0;
-}
-
   static int ipc_has_perm(struct kern_ipc_perm *ipc_perms,
               u32 perms)
   {
@@ -5910,7 +5900,12 @@ static int ipc_has_perm(struct kern_ipc_perm *ipc_perms,
     static int selinux_msg_msg_alloc_security(struct msg_msg *msg)
   {
-    return msg_msg_alloc_security(msg);
+    struct msg_security_struct *msec;
+
+    msec = selinux_msg_msg(msg);
+    msec->sid = SECINITSID_UNLABELED;
+
+    return 0;
   }
     /* message queue security operations */
 
maintainer
#3 lore raw
In reply to Stephen Smalley
Quoted 7 lines · Stephen Smalley
Quoted 6 lines · Huaisheng Ye

From: Huaisheng Ye <[email protected]>

selinux_msg_msg_alloc_security only calls msg_msg_alloc_security but do nothing else. And also msg_msg_alloc_security is just used by the former.

Quoted 7 lines
Quoted 1 line

Remove the redundant function to simplify the code.

This seems to also be true of other _alloc_security functions, probably due to historical reasons. Further, at least some of these functions no longer perform any allocation; they are just initialization functions now that allocation has been taken to the LSM framework, so possibly could be renamed and made to return void at some point.

I've noticed the same thing on a few occasions, I've just never bothered to put the fixes into a patch. We might as well do that now, at least for the redundant code bits; I'll leave the return code issue for another time as that would cross LSM boundaries and that really isn't appropriate in the -rc5 timeframe IMHO.

I'll put something together once I finish up the patch/review backlog from the past few days. Looking quickly with a regex, it would appear that inode_alloc_security(), file_alloc_security(), and superblock_alloc_security() are all candidates. While not an allocator, we can probably get rid of inode_doinit() as well.

Signature · 2 lines
paul moore
www.paul-moore.com
#4 lore raw
Quoted 25 lines

-----Original Message-----
From: Paul Moore <[email protected]>
Sent: Saturday, January 11, 2020 12:50 AM

Quoted 7 lines · Stephen Smalley
Quoted 6 lines · Huaisheng Ye

From: Huaisheng Ye <[email protected]>

selinux_msg_msg_alloc_security only calls msg_msg_alloc_security but do nothing else. And also msg_msg_alloc_security is just used by the former.

Quoted 7 lines
Quoted 1 line

Remove the redundant function to simplify the code.

This seems to also be true of other _alloc_security functions, probably due to historical reasons. Further, at least some of these functions no longer perform any allocation; they are just initialization functions now that allocation has been taken to the LSM framework, so possibly could be renamed and made to return void at some point.

I've noticed the same thing on a few occasions, I've just never bothered to put the fixes into a patch. We might as well do that now, at least for the redundant code bits; I'll leave the return code issue for another time as that would cross LSM boundaries and that really isn't appropriate in the -rc5 timeframe IMHO.

Quoted 5 lines

I'll put something together once I finish up the patch/review backlog from the past few days. Looking quickly with a regex, it would appear that inode_alloc_security(), file_alloc_security(), and superblock_alloc_security() are all candidates. While not an allocator, we can probably get rid of inode_doinit() as well.

Besides, it looks like selinux_nlmsg_perm is candidate too. Just send a patch for this function.

Cheers,
Huaisheng Ye

maintainer Applied
#5 lore raw
In reply to Huaisheng Ye
Quoted 6 lines · Huaisheng Ye

From: Huaisheng Ye <[email protected]>

selinux_msg_msg_alloc_security only calls msg_msg_alloc_security but do nothing else. And also msg_msg_alloc_security is just used by the former.

Quoted 6 lines

Remove the redundant function to simplify the code.

---
 security/selinux/hooks.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

Merged into selinux/next, thanks!

Signature · 2 lines
paul moore
www.paul-moore.com