Re: [PATCH v9 02/11] LSM: Maintain a table of LSM attribute data
From: Casey Schaufler <casey@schaufler-ca.com>
Date: 2023-04-27 15:31:52
Also in:
linux-security-module, lkml
On 4/21/2023 12:20 PM, Kees Cook wrote:
On Fri, Apr 21, 2023 at 10:42:50AM -0700, Casey Schaufler wrote:quoted
As LSMs are registered add their lsm_id pointers to a table. This will be used later for attribute reporting. Determine the number of possible security modules based on their respective CONFIG options. This allows the number to be known at build time. This allows data structures and tables to use the constant. Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>Reviewed-by: Kees Cook <redacted> Nit below...quoted
[...]@@ -513,6 +531,15 @@ void __init security_add_hooks(struct security_hook_list *hooks, int count, { int i; + if (lsm_active_cnt >= LSM_COUNT) + panic("%s Too many LSMs registered.\n", __func__); + /* + * A security module may call security_add_hooks() more + * than once. Landlock is one such case. + */ + if (lsm_active_cnt == 0 || lsm_idlist[lsm_active_cnt - 1] != lsmid) + lsm_idlist[lsm_active_cnt++] = lsmid; +I find this logic hard to parse. I think this might be better, since lsm_idlist will be entirely initialized to LSM_UNDEF, yes? /* * A security module may call security_add_hooks() more * than once during initialization, and LSM initialization * is serialized. Landlock is one such case. */ if (lsm_idlist[lsm_active_cnt] != lsmid) lsm_idlist[lsm_active_cnt++] = lsmid;
This code won't do the job. lsm_active_count indexes the first unset entry, not the last set entry.