From patchwork Fri Dec 15 22:16:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 13495162 X-Patchwork-Delegate: paul@paul-moore.com Received: from sonic302-28.consmr.mail.ne1.yahoo.com (sonic302-28.consmr.mail.ne1.yahoo.com [66.163.186.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4E3B18EA7 for ; Fri, 15 Dec 2023 22:38:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=schaufler-ca.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=schaufler-ca.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=yahoo.com header.i=@yahoo.com header.b="s8E7a9Ht" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1702679938; bh=vw4D+BEaDQJfSHAGsDrE6ropoXZ857wJv+qK1Uq2Fhw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=s8E7a9HtnwBj2iiRElPv7y2OTlbx0dCRAAA6Or5I/05O5N4cr6J1nrWYTkW6kVIbRI2i/KYtGGPGF6pH0JQ4Gzx6xHG62xwnWN4SxNrYpR2OZKP1lUykR2lPd/javdaj3N+znlS1+3IO8z+1JzCIy/hC9M7sjLwGrb6X1UfXBDoaG3EzcErxgWfioyVoTkjesWsKFyRuqrwbmNM3p99JfS02u/U7za4IJb1FyIKF4EXBsS7Q4tk2KYk2uwgqU57CoQLAGG1CLBtYhVqCgnfo7fNHrnzbwCyNVfnpXwlTUwMpgnSY5rfDppPAFNvYnQF/sx+3TY7rK1eQhK4bS7PNyw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1702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pjs.v18WB3L0L0Aowpp5nZePzKElyMmTEDE8n TWsaE8EYCnmTUplsnE8idnnKDZx8MmD.TIvFtxof98bJu_kz8ypvBBkrEC7EjsiYD6y0SUlc_05p eu_MuDcrn0WCZSOh7RZ_ATZZfE40kf6qfK2FycR0E.WGcRsK.F2v4wFHr3bxWtQMXo.bxZ2euJ02 zSzJuUQBYgzaSa47VXlM9cDmKtIR7ijgfS_Uwc.7pLea66fkbptD2vW4mw1FqnB_2l.iC1udenJk C_vAz5oYhBvgytwh16qeHZHGo49D08N9bEYLMD7.QVfCrUbORu1cJJT3zbjv9IxJw8AFBhnHwzcj DAYhTxAFcNQiZU6edrIBJD5EOQVlowYurYtjo7ZMQbBy75lbIK0bKvpNZ8dkoygMlzA5z5qybYxa 1Idac7UNmr3RwZLOZWzDc0frBzJNlA4vYkKMbSBBgn0jusSM8mdJxwaYZBpIbnf3URPT2oPwHdf5 xiFFMMiLXbSY7GczQ6F5Z.0SD6jLkjoZ2wQDct2FMI1QjVeuV85YI68Fugh5s6kEV59svyA0UXoM JSXGtfKEd1LTAU8pJmUNVuhIwUJiyhpsqPlQeHnLHufJhjHA4vNFm_EjPy3OznnLQHNTjQ4ii8ia zXrMrUIikzIyzmeMacTEuWMl78iM- X-Sonic-MF: X-Sonic-ID: e49cc921-3fa7-4678-8a0e-ca413b7682da Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.ne1.yahoo.com with HTTP; Fri, 15 Dec 2023 22:38:58 +0000 Received: by hermes--production-gq1-6949d6d8f9-q7525 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 522caf1ff66b851381e701962a25c33e; Fri, 15 Dec 2023 22:38:54 +0000 (UTC) From: Casey Schaufler To: casey@schaufler-ca.com, paul@paul-moore.com, linux-security-module@vger.kernel.org Cc: jmorris@namei.org, serge@hallyn.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, stephen.smalley.work@gmail.com, linux-kernel@vger.kernel.org, mic@digikod.net Subject: [PATCH v39 28/42] LSM: Improve logic in security_getprocattr Date: Fri, 15 Dec 2023 14:16:22 -0800 Message-ID: <20231215221636.105680-29-casey@schaufler-ca.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231215221636.105680-1-casey@schaufler-ca.com> References: <20231215221636.105680-1-casey@schaufler-ca.com> Precedence: bulk X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The conditional in security_getprocattr() can be simplified and made clearer. This change does that. Signed-off-by: Casey Schaufler --- security/security.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/security/security.c b/security/security.c index 8ff6cef26e6c..f2ef6032a925 100644 --- a/security/security.c +++ b/security/security.c @@ -4107,11 +4107,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); }