mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/1] selinux: simplify avc_xperms_audit_required()
@ 2024-08-22 14:08 Zhen Lei
  2024-08-28 17:42 ` Paul Moore
  0 siblings, 1 reply; 2+ messages in thread
From: Zhen Lei @ 2024-08-22 14:08 UTC (permalink / raw)
  To: Paul Moore, Stephen Smalley, Ondrej Mosnacek, selinux, linux-kernel
  Cc: Zhen Lei

By associative and commutative laws, the result of the two 'audited' is
zero. Take the second 'audited' as an example:
  1) audited = requested & avd->auditallow;
  2) audited &= ~requested;
  ==> audited = ~requested & (requested & avd->auditallow);
  ==> audited = (~requested & requested) & avd->auditallow;
  ==> audited = 0 & avd->auditallow;
  ==> audited = 0;

In fact, it is more readable to directly write zero. The value of the
first 'audited' is 0 because AUDIT is not allowed. The second 'audited'
is zero because there is no AUDITALLOW permission.

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
 security/selinux/avc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/security/selinux/avc.c b/security/selinux/avc.c
index b49c44869dc4627..21f5bbba50caaeb 100644
--- a/security/selinux/avc.c
+++ b/security/selinux/avc.c
@@ -396,7 +396,7 @@ static inline u32 avc_xperms_audit_required(u32 requested,
 		audited = denied & avd->auditdeny;
 		if (audited && xpd) {
 			if (avc_xperms_has_perm(xpd, perm, XPERMS_DONTAUDIT))
-				audited &= ~requested;
+				audited = 0;
 		}
 	} else if (result) {
 		audited = denied = requested;
@@ -404,7 +404,7 @@ static inline u32 avc_xperms_audit_required(u32 requested,
 		audited = requested & avd->auditallow;
 		if (audited && xpd) {
 			if (!avc_xperms_has_perm(xpd, perm, XPERMS_AUDITALLOW))
-				audited &= ~requested;
+				audited = 0;
 		}
 	}
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] selinux: simplify avc_xperms_audit_required()
  2024-08-22 14:08 [PATCH 1/1] selinux: simplify avc_xperms_audit_required() Zhen Lei
@ 2024-08-28 17:42 ` Paul Moore
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Moore @ 2024-08-28 17:42 UTC (permalink / raw)
  To: Zhen Lei, Stephen Smalley, Ondrej Mosnacek, selinux, linux-kernel
  Cc: Zhen Lei

On Aug 22, 2024 Zhen Lei <thunder.leizhen@huawei.com> wrote:
> 
> By associative and commutative laws, the result of the two 'audited' is
> zero. Take the second 'audited' as an example:
>   1) audited = requested & avd->auditallow;
>   2) audited &= ~requested;
>   ==> audited = ~requested & (requested & avd->auditallow);
>   ==> audited = (~requested & requested) & avd->auditallow;
>   ==> audited = 0 & avd->auditallow;
>   ==> audited = 0;
> 
> In fact, it is more readable to directly write zero. The value of the
> first 'audited' is 0 because AUDIT is not allowed. The second 'audited'
> is zero because there is no AUDITALLOW permission.
> 
> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
> ---
>  security/selinux/avc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Looks good to me, merged into selinux/dev, thanks!

--
paul-moore.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-08-28 17:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-22 14:08 [PATCH 1/1] selinux: simplify avc_xperms_audit_required() Zhen Lei
2024-08-28 17:42 ` Paul Moore

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®