Skip to contentSkip to conversation

selinux: stop returning node from avc_insert

PATCH In review Stephen Smalley 2 participants 2 messages Apr 3, 2023 – Apr 4, 2023 SELinux security module

lore
Share & tools
lore

Stephen Smalley

author maintainer
#0 lore raw

PATCH 1/1 selinux: stop returning node from avc_insert

The callers haven't used the returned node since
commit 21193dcd1f3570dd ("SELinux: more careful use of avd in avc_has_perm_noaudit") and the return value assignments were removed in commit 0a9876f36b08706d ("selinux: Remove redundant assignments"). Stop returning the node altogether and make the functions return void.

---
 security/selinux/avc.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
security/selinux/avc.c +12 -13
index c162e51fb43c..ad2afc17b633 100644
@@ -603,12 +603,11 @@ static int avc_latest_notif_update(int seqno, int is_insert)
  * response to a security_compute_av() call.  If the
  * sequence number @avd->seqno is not less than the latest
  * revocation notification, then the function copies
- * the access vectors into a cache entry, returns
- * avc_node inserted. Otherwise, this function returns NULL.
+ * the access vectors into a cache entry.
  */
-static struct avc_node *avc_insert(u32 ssid, u32 tsid, u16 tclass,
-				   struct av_decision *avd,
-				   struct avc_xperms_node *xp_node)
+static void avc_insert(u32 ssid, u32 tsid, u16 tclass,
+		struct av_decision *avd,
+		struct avc_xperms_node *xp_node)
 {
 	struct avc_node *pos, *node = NULL;
 	int hvalue;
@@ -617,16 +616,16 @@ static struct avc_node *avc_insert(u32 ssid, u32 tsid, u16 tclass,
 	struct hlist_head *head;
 
 	if (avc_latest_notif_update(avd->seqno, 1))
-		return NULL;
+		return;
 
 	node = avc_alloc_node();
 	if (!node)
-		return NULL;
+		return;
 
 	avc_node_populate(node, ssid, tsid, tclass, avd);
 	if (avc_xperms_populate(node, xp_node)) {
 		avc_node_kill(node);
-		return NULL;
+		return;
 	}
 
 	hvalue = avc_hash(ssid, tsid, tclass);
@@ -644,7 +643,7 @@ static struct avc_node *avc_insert(u32 ssid, u32 tsid, u16 tclass,
 	hlist_add_head_rcu(&node->list, head);
 found:
 	spin_unlock_irqrestore(lock, flag);
-	return node;
+	return;
 }
 
 /**
@@ -984,13 +983,13 @@ int avc_ss_reset(u32 seqno)
  * fails.  Don't inline this, since it's the slow-path and just results in a
  * bigger stack frame.
  */
-static noinline struct avc_node *avc_compute_av(u32 ssid, u32 tsid, u16 tclass,
-						struct av_decision *avd,
-						struct avc_xperms_node *xp_node)
+static noinline void avc_compute_av(u32 ssid, u32 tsid, u16 tclass,
+				struct av_decision *avd,
+				struct avc_xperms_node *xp_node)
 {
 	INIT_LIST_HEAD(&xp_node->xpd_head);
 	security_compute_av(ssid, tsid, tclass, avd, &xp_node->xp);
-	return avc_insert(ssid, tsid, tclass, avd, xp_node);
+	avc_insert(ssid, tsid, tclass, avd, xp_node);
 }
 
 static noinline int avc_denied(u32 ssid, u32 tsid,
Signature · 1 line
2.39.2
maintainer
#1 lore raw
Quoted 20 lines · Stephen Smalley

The callers haven't used the returned node since
commit 21193dcd1f3570dd ("SELinux: more careful use of avd in avc_has_perm_noaudit") and the return value assignments were removed in commit 0a9876f36b08706d ("selinux: Remove redundant assignments"). Stop returning the node altogether and make the functions return void.

---
 security/selinux/avc.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
security/selinux/avc.c +0 -0
index c162e51fb43c..ad2afc17b633 100644
@@ -603,12 +603,11 @@ static int avc_latest_notif_update(int seqno, int is_insert)
  * response to a security_compute_av() call.  If the
  * sequence number @avd->seqno is not less than the latest
  * revocation notification, then the function copies

security/selinux/avc.c static int avc_latest_notif_update(int seqno, int is_insert) · line 610

Quoted 10 lines
security/selinux/avc.c +4 -5
- * the access vectors into a cache entry, returns
- * avc_node inserted. Otherwise, this function returns NULL.
+ * the access vectors into a cache entry.
  */
-static struct avc_node *avc_insert(u32 ssid, u32 tsid, u16 tclass,
-                                  struct av_decision *avd,
-                                  struct avc_xperms_node *xp_node)
+static void avc_insert(u32 ssid, u32 tsid, u16 tclass,
+               struct av_decision *avd,
+               struct avc_xperms_node *xp_node)

Thanks Stephen, I just merged this into selinux/next, but I do have a couple of small style nitpicks for future reference.

When writing a patch subject line with a function name, please add parenthesis to the name to help make it clear it is a function, e.g. "avc_insert()" instead of "avc_insert".

When the argument list spills to multiple lines, please make sure they are aligned (look at the committed patch for an example).

Signature · 1 line
paul-moore.com