From: Casey Schaufler <casey@schaufler-ca.com>
To: Paul Moore <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,
selinux@vger.kernel.org, mic@digikod.net,
Casey Schaufler <casey@schaufler-ca.com>
Subject: Re: [PATCH v2 3/13] LSM: Add lsmblob_to_secctx hook
Date: Tue, 3 Sep 2024 18:15:22 -0700 [thread overview]
Message-ID: <61b60364-72e7-40f2-90dd-255d5714b9e7@schaufler-ca.com> (raw)
In-Reply-To: <faf28485e8d2846e78f89c39d2f737ac@paul-moore.com>
On 9/3/2024 5:18 PM, Paul Moore wrote:
> On Aug 29, 2024 Casey Schaufler <casey@schaufler-ca.com> wrote:
>> Add a new hook security_lsmblob_to_secctx() and its LSM specific
>> implementations. The LSM specific code will use the lsmblob element
>> allocated for that module. This allows for the possibility that more
>> than one module may be called upon to translate a secid to a string,
>> as can occur in the audit code.
>>
>> Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
>> ---
>> include/linux/lsm_hook_defs.h | 2 ++
>> include/linux/security.h | 11 ++++++++++-
>> security/apparmor/include/secid.h | 2 ++
>> security/apparmor/lsm.c | 1 +
>> security/apparmor/secid.c | 25 +++++++++++++++++++++++--
>> security/security.c | 30 ++++++++++++++++++++++++++++++
>> security/selinux/hooks.c | 16 ++++++++++++++--
>> security/smack/smack_lsm.c | 31 ++++++++++++++++++++++++++-----
>> 8 files changed, 108 insertions(+), 10 deletions(-)
> ..
>
>> diff --git a/security/security.c b/security/security.c
>> index 64a6d6bbd1f4..bb541a3be410 100644
>> --- a/security/security.c
>> +++ b/security/security.c
>> @@ -4192,6 +4192,36 @@ int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
>> }
>> EXPORT_SYMBOL(security_secid_to_secctx);
>>
>> +/**
>> + * security_lsmblob_to_secctx() - Convert a lsmblob to a secctx
>> + * @blob: lsm specific information
>> + * @secdata: secctx
>> + * @seclen: secctx length
>> + *
>> + * Convert a @blob entry to security context. If @secdata is NULL the
>> + * length of the result will be returned in @seclen, but no @secdata
>> + * will be returned. This does mean that the length could change between
>> + * calls to check the length and the next call which actually allocates
>> + * and returns the @secdata.
>> + *
>> + * Return: Return 0 on success, error on failure.
>> + */
>> +int security_lsmblob_to_secctx(struct lsmblob *blob, char **secdata,
>> + u32 *seclen)
>> +{
>> + struct security_hook_list *hp;
>> + int rc;
>> +
>> + hlist_for_each_entry(hp, &security_hook_heads.secid_to_secctx, list) {
>> + rc = hp->hook.lsmblob_to_secctx(blob, secdata, seclen);
>> + if (rc != LSM_RET_DEFAULT(secid_to_secctx))
> Wrong default value/hook, but see below ...
>
>> + return rc;
>> + }
>> +
>> + return LSM_RET_DEFAULT(secid_to_secctx);
> Same problem, I'm guessing a cut-n-paste-o.
>
>> +}
>> +EXPORT_SYMBOL(security_lsmblob_to_secctx);
> We should be using the call_int_hook() macro instead of open coding using
> hlist_for_each_entry() and I believe the code above could be converted
> without any difficulty.
>
> It should also solve the compile problem seen when using lsm/dev or
> lsm/next as the base.
Yup, sorry for being sloppy. Will get fixed in v3.
>
>> /**
>> * security_secctx_to_secid() - Convert a secctx to a secid
>> * @secdata: secctx
>> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
>> index 55c78c318ccd..102489e6d579 100644
>> --- a/security/selinux/hooks.c
>> +++ b/security/selinux/hooks.c
>> @@ -6610,8 +6610,19 @@ static int selinux_ismaclabel(const char *name)
>>
>> static int selinux_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
>> {
>> - return security_sid_to_context(secid,
>> - secdata, seclen);
>> + return security_sid_to_context(secid, secdata, seclen);
>> +}
>> +
>> +static int selinux_lsmblob_to_secctx(struct lsmblob *blob, char **secdata,
>> + u32 *seclen)
>> +{
>> + u32 secid = blob->selinux.secid;
>> +
>> + /* scaffolding */
>> + if (!secid)
>> + secid = blob->scaffold.secid;
>> +
>> + return security_sid_to_context(secid, secdata, seclen);
> We should probably just call selinux_secid_to_secctx() here so we limit
> the code dup/sync issues.
In SELinux code I'll defer to your style choices.
>> }
> --
> paul-moore.com
>
next prev parent reply other threads:[~2024-09-04 1:15 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20240830003411.16818-1-casey.ref@schaufler-ca.com>
2024-08-30 0:33 ` [PATCH v2 00/13] LSM: Move away from secids Casey Schaufler
2024-08-30 0:33 ` [PATCH v2 01/13] LSM: Add the lsmblob data structure Casey Schaufler
2024-09-04 0:18 ` [PATCH v2 1/13] " Paul Moore
2024-09-04 0:53 ` Casey Schaufler
2024-09-04 20:00 ` Paul Moore
2024-09-04 20:28 ` Casey Schaufler
2024-09-04 20:36 ` Paul Moore
2024-08-30 0:34 ` [PATCH v2 02/13] LSM: Use lsmblob in security_audit_rule_match Casey Schaufler
2024-08-30 22:48 ` kernel test robot
2024-08-30 0:34 ` [PATCH v2 03/13] LSM: Add lsmblob_to_secctx hook Casey Schaufler
2024-09-04 0:18 ` [PATCH v2 3/13] " Paul Moore
2024-09-04 1:15 ` Casey Schaufler [this message]
2024-08-30 0:34 ` [PATCH v2 04/13] Audit: maintain an lsmblob in audit_context Casey Schaufler
2024-09-04 0:18 ` [PATCH v2 4/13] " Paul Moore
2024-09-04 1:18 ` Casey Schaufler
2024-08-30 0:34 ` [PATCH v2 05/13] LSM: Use lsmblob in security_ipc_getsecid Casey Schaufler
2024-09-04 0:18 ` [PATCH v2 5/13] " Paul Moore
2024-09-04 1:24 ` Casey Schaufler
2024-08-30 0:34 ` [PATCH v2 06/13] Audit: Update shutdown LSM data Casey Schaufler
2024-08-30 0:34 ` [PATCH v2 07/13] LSM: Use lsmblob in security_current_getsecid Casey Schaufler
2024-08-30 0:34 ` [PATCH v2 08/13] LSM: Use lsmblob in security_inode_getsecid Casey Schaufler
2024-08-30 0:34 ` [PATCH v2 09/13] Audit: use an lsmblob in audit_names Casey Schaufler
2024-08-30 0:34 ` [PATCH v2 10/13] LSM: Create new security_cred_getlsmblob LSM hook Casey Schaufler
2024-08-30 15:26 ` kernel test robot
2024-08-30 15:26 ` kernel test robot
2024-08-30 0:34 ` [PATCH v2 11/13] Audit: Change context data from secid to lsmblob Casey Schaufler
2024-08-30 0:34 ` [PATCH v2 12/13] Netlabel: Use lsmblob for audit data Casey Schaufler
2024-08-30 0:34 ` [PATCH v2 13/13] LSM: Remove lsmblob scaffolding Casey Schaufler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=61b60364-72e7-40f2-90dd-255d5714b9e7@schaufler-ca.com \
--to=casey@schaufler-ca.com \
--cc=jmorris@namei.org \
--cc=john.johansen@canonical.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=mic@digikod.net \
--cc=paul@paul-moore.com \
--cc=penguin-kernel@i-love.sakura.ne.jp \
--cc=selinux@vger.kernel.org \
--cc=serge@hallyn.com \
--cc=stephen.smalley.work@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®