From 3378b3ca12057897627dca77adfa6c12acb3a81e Mon Sep 17 00:00:00 2001 From: Casey Schaufler Date: Tue, 14 Nov 2023 09:26:03 -0800 Subject: [PATCH] UBUNTU: SAUCE: apparmor4.0.0 [28/90]: LSM stacking v39: LSM: Improve logic in security_getprocattr BugLink: http://bugs.launchpad.net/bugs/2028253 The conditional in security_getprocattr() can be simplified and made clearer. This change does that. Signed-off-by: Casey Schaufler (cherry picked from commit 5f2df36aeb13d0d659d4355fd399e028c64de737 https://git.launchpad.net/~apparmor-dev/ubuntu-kernel-next) Signed-off-by: Paolo Pisati --- security/security.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/security/security.c b/security/security.c index 2338f9c68f1e..b0e08573257f 100644 --- a/security/security.c +++ b/security/security.c @@ -4126,11 +4126,10 @@ int security_getprocattr(struct task_struct *p, int lsmid, const char *name, { struct security_hook_list *hp; - hlist_for_each_entry(hp, &security_hook_heads.getprocattr, list) { - if (lsmid != 0 && lsmid != hp->lsmid->id) - continue; - return hp->hook.getprocattr(p, name, value); - } + hlist_for_each_entry(hp, &security_hook_heads.getprocattr, list) + if (lsmid == LSM_ID_UNDEF || lsmid == hp->lsmid->id) + return hp->hook.getprocattr(p, name, value); + return LSM_RET_DEFAULT(getprocattr); }