selinux: Streamline type determination in security_compute_sid
PATCH 1/1 selinux: Streamline type determination in security_compute_sid
Simplifies the logic for determining the security context type in security_compute_sid, enhancing readability and efficiency.
Consolidates default type assignment logic next to type transition checks, removing redundancy and improving code flow.
---
v2:
Modify the format to follow the generally accepted style for multi-line comments in the Linux kernel.
--- security/selinux/ss/services.c | 36 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 17 deletions(-)
security/selinux/ss/services.c +19 -17
@@ -1804,22 +1804,9 @@ static int security_compute_sid(u32 ssid, newcontext.role =OBJECT_R_VAL ; } -/* Set the type to default values. */ -if (cladatum && cladatum->default_type ==DEFAULT_SOURCE ) { - newcontext.type = scontext->type; - }else if (cladatum && cladatum->default_type ==DEFAULT_TARGET ) { - newcontext.type = tcontext->type; - }else { -if ((tclass == policydb->process_class) || sock) { -/* Use the type of process. */ - newcontext.type = scontext->type; - }else { -/* Use the type of the related object. */ - newcontext.type = tcontext->type; - } - } - -/* Look for a type transition/member/change rule. */ +/* Set the type. +* Look for a type transition/member/change rule. +*/ avkey.source_type = scontext->type; avkey.target_type = tcontext->type; avkey.target_class = tclass;
@@ -1837,9 +1824,24 @@ static int security_compute_sid(u32 ssid, } } +/* If a permanent rule is found, use the type from +* the type transition/member/change rule. Otherwise, +* set the type to its default values. +*/ if (avnode) { -/* Use the type from the type transition/member/change rule. */ newcontext.type = avnode->datum.u.data; + }else if (cladatum && cladatum->default_type ==DEFAULT_SOURCE ) { + newcontext.type = scontext->type; + }else if (cladatum && cladatum->default_type ==DEFAULT_TARGET ) { + newcontext.type = tcontext->type; + }else { +if ((tclass == policydb->process_class) || sock) { +/* Use the type of process. */ + newcontext.type = scontext->type; + }else { +/* Use the type of the related object. */ + newcontext.type = tcontext->type; + } }/* if we have a objname this is a file trans check so check those rules */
Signature · 1 line
2.20.1
Paul Moore
maintainerQuoted 7 lines · Canfeng Guo
Simplifies the logic for determining the security context type in
security_compute_sid, enhancing readability and efficiency.Consolidates default type assignment logic next to type transition checks, removing redundancy and improving code flow.
Quoted 8 lines
Signed-off-by Canfeng Guo <[email protected]>---
v2:
Modify the format to follow the generally accepted style for multi-line comments in the Linux kernel.--- security/selinux/ss/services.c | 36 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 17 deletions(-)
Thanks for the revised patch, it looks good to me, but it is too late in the development cycle to merge it into the selinux/dev branch; I'm going to merge it into selinux/dev-staging for testing and I'll move it to the selinux/dev branch after the upcoming merge window closes.
Signature · 1 line
paul-moore.com
Paul Moore
maintainerQuoted 17 lines · Paul Moore
Quoted 7 lines · Canfeng Guo
Simplifies the logic for determining the security context type in
security_compute_sid, enhancing readability and efficiency.Consolidates default type assignment logic next to type transition checks, removing redundancy and improving code flow.
Quoted 8 lines
Signed-off-by Canfeng Guo <[email protected]>---
v2:
Modify the format to follow the generally accepted style for multi-line comments in the Linux kernel.--- security/selinux/ss/services.c | 36 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 17 deletions(-)
Quoted 4 lines
Thanks for the revised patch, it looks good to me, but it is too late in the development cycle to merge it into the selinux/dev branch; I'm going to merge it into selinux/dev-staging for testing and I'll move it to the selinux/dev branch after the upcoming merge window closes.
A quick note to let you know that this is now in the selinux/dev branch, thanks!
Signature · 1 line
paul-moore.com