[PATCH v2 3/7] LSM: Two hooks for manipulating struct lsm_prop
John Johansen
john.johansen at canonical.com
Thu Sep 3 09:40:14 UTC 2026
On 9/2/26 15:01, Casey Schaufler wrote:
> security_update_lsmprop() updates the property of the
> specified LSM in the @dest structure with that in the @src.
>
> security_secctx_to_lsmprop() sets the @prop field associated
> with the LSM specified to the value of the passed security
> context.
>
> LSM specific implementations of these hooks to follow.
>
> Signed-off-by: Casey Schaufler <casey at schaufler-ca.com>
lgtm
Reviewed-by: John Johansen <john.johansen at canonical.com>
> ---
> include/linux/lsm_hook_defs.h | 4 ++++
> include/linux/security.h | 16 ++++++++++++++++
> security/security.c | 32 ++++++++++++++++++++++++++++++++
> 3 files changed, 52 insertions(+)
>
> diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h
> index 65c9609ec207..679c40a8e127 100644
> --- a/include/linux/lsm_hook_defs.h
> +++ b/include/linux/lsm_hook_defs.h
> @@ -305,7 +305,11 @@ LSM_HOOK(int, 0, ismaclabel, const char *name)
> LSM_HOOK(int, -EOPNOTSUPP, secid_to_secctx, u32 secid, struct lsm_context *cp)
> LSM_HOOK(int, -EOPNOTSUPP, lsmprop_to_secctx, struct lsm_prop *prop,
> struct lsm_context *cp)
> +LSM_HOOK(void, LSM_RET_VOID, update_lsmprop, struct lsm_prop *dest,
> + struct lsm_prop *src, int lsmid)
> LSM_HOOK(int, 0, secctx_to_secid, const char *secdata, u32 seclen, u32 *secid)
> +LSM_HOOK(int, -EINVAL, secctx_to_lsmprop, const char *secdata, u32 seclen,
> + struct lsm_prop *prop)
> LSM_HOOK(void, LSM_RET_VOID, release_secctx, struct lsm_context *cp)
> LSM_HOOK(void, LSM_RET_VOID, inode_invalidate_secctx, struct inode *inode)
> LSM_HOOK(int, 0, inode_notifysecctx, struct inode *inode, void *ctx, u32 ctxlen)
> diff --git a/include/linux/security.h b/include/linux/security.h
> index 153e9043058f..19adc19eb9af 100644
> --- a/include/linux/security.h
> +++ b/include/linux/security.h
> @@ -576,6 +576,11 @@ int security_secid_to_secctx(u32 secid, struct lsm_context *cp);
> int security_lsmprop_to_secctx(struct lsm_prop *prop, struct lsm_context *cp,
> int lsmid);
> int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid);
> +int security_secctx_to_lsmprop(const char *secdata, u32 seclen,
> + struct lsm_prop *prop, int lsmid);
> +
> +void security_update_lsmprop(struct lsm_prop *dest, struct lsm_prop *src,
> + int lsmid);
> void security_release_secctx(struct lsm_context *cp);
> void security_inode_invalidate_secctx(struct inode *inode);
> int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen);
> @@ -1581,6 +1586,11 @@ static inline int security_lsmprop_to_secctx(struct lsm_prop *prop,
> return -EOPNOTSUPP;
> }
>
> +static inline void security_update_lsmprop(struct lsm_prop *dest,
> + struct lsm_prop *src, int lsmid)
> +{
> +}
> +
> static inline int security_secctx_to_secid(const char *secdata,
> u32 seclen,
> u32 *secid)
> @@ -1588,6 +1598,12 @@ static inline int security_secctx_to_secid(const char *secdata,
> return -EOPNOTSUPP;
> }
>
> +static inline int security_secctx_to_lsmprop(const char *secdata, u32 seclen,
> + struct lsm_prop *prop, int lsmid)
> +{
> + return -EOPNOTSUPP;
> +}
> +
> static inline void security_release_secctx(struct lsm_context *cp)
> {
> }
> diff --git a/security/security.c b/security/security.c
> index 71aea8fdf014..1dec0037370b 100644
> --- a/security/security.c
> +++ b/security/security.c
> @@ -3965,6 +3965,13 @@ int security_lsmprop_to_secctx(struct lsm_prop *prop, struct lsm_context *cp,
> }
> EXPORT_SYMBOL(security_lsmprop_to_secctx);
>
> +void security_update_lsmprop(struct lsm_prop *dest, struct lsm_prop *src,
> + int lsmid)
> +{
> + call_void_hook(update_lsmprop, dest, src, lsmid);
> +}
> +EXPORT_SYMBOL(security_update_lsmprop);
> +
> /**
> * security_secctx_to_secid() - Convert a secctx to a secid
> * @secdata: secctx
> @@ -3982,6 +3989,31 @@ int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
> }
> EXPORT_SYMBOL(security_secctx_to_secid);
>
> +/**
> + * security_secctx_to_lsmprop() - Convert a secctx to a lsmprop
> + * @secdata: secctx
> + * @seclen: length of secctx
> + * @prop: prop
> + * @lsmid: which LSM the context is appropriate to.
> + *
> + * Convert security context to an lsmprop.
> + *
> + * Return: Returns 0 on success, error on failure.
> + */
> +int security_secctx_to_lsmprop(const char *secdata, u32 seclen,
> + struct lsm_prop *prop, int lsmid)
> +{
> + struct lsm_static_call *scall;
> +
> + lsm_for_each_hook(scall, secctx_to_lsmprop) {
> + if (lsmid != LSM_ID_UNDEF && lsmid != scall->hl->lsmid->id)
> + continue;
> + return scall->hl->hook.secctx_to_lsmprop(secdata, seclen, prop);
> + }
> + return LSM_RET_DEFAULT(secctx_to_lsmprop);
> +}
> +EXPORT_SYMBOL(security_secctx_to_lsmprop);
> +
> /**
> * security_release_secctx() - Free a secctx buffer
> * @cp: the security context
More information about the Linux-security-module-archive
mailing list