* [PATCH 1/7] net, smack: Create a function to set secmarks
2026-08-13 20:48 ` [PATCH 0/7] Change skb secmarks to x-array indexes Casey Schaufler
@ 2026-08-13 20:48 ` Casey Schaufler
2026-08-13 20:48 ` [PATCH 2/7] LSM: Implement x array functions for secmarks Casey Schaufler
` (4 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Casey Schaufler @ 2026-08-13 20:48 UTC (permalink / raw)
To: casey, paul, linux-security-module, pablo, fw, phil
Cc: linux-kernel, netfilter-devel, coreteam, jmorris, serge, keescook,
john.johansen, penguin-kernel, stephen.smalley.work, selinux
Rather than open coding assignments to skb->secmark, use a helper function
secxa_set_secmark(). This allows for a case where assigning a secmark
is more complex than a simple assignment. The version of the function
here does the legacy simple assignment.
Change the functions that currently assign values to skb->secmark to
use this function.
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
---
include/linux/lsm_secxa.h | 22 ++++++++++++++++++++++
net/netfilter/nft_meta.c | 5 +++--
net/netfilter/xt_CONNSECMARK.c | 3 ++-
net/netfilter/xt_SECMARK.c | 3 ++-
security/smack/smack_netfilter.c | 3 ++-
5 files changed, 31 insertions(+), 5 deletions(-)
create mode 100644 include/linux/lsm_secxa.h
diff --git a/include/linux/lsm_secxa.h b/include/linux/lsm_secxa.h
new file mode 100644
index 000000000000..f4c732d26680
--- /dev/null
+++ b/include/linux/lsm_secxa.h
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+/*
+ * Copyright (C) 2026 Casey Schaufler <casey@schaufler-ca.com>
+ */
+
+#ifndef __LINUX_LSM_SECXA_H
+#define __LINUX_LSM_SECXA_H
+
+#ifdef CONFIG_SECURITY
+
+#include <linux/security.h>
+#include <linux/skbuff.h>
+
+static inline void secxa_set_secmark(struct sk_buff *skb, u32 secxa)
+{
+ skb->secmark = secxa;
+}
+
+#endif /* CONFIG_SECURITY */
+
+#endif /* __LINUX_LSM_SECXA_H */
diff --git a/net/netfilter/nft_meta.c b/net/netfilter/nft_meta.c
index 0a43e0787a68..bd0f7a0931f4 100644
--- a/net/netfilter/nft_meta.c
+++ b/net/netfilter/nft_meta.c
@@ -17,6 +17,7 @@
#include <linux/random.h>
#include <linux/smp.h>
#include <linux/static_key.h>
+#include <linux/lsm_secxa.h>
#include <net/dst.h>
#include <net/ip.h>
#include <net/sock.h>
@@ -502,7 +503,7 @@ void nft_meta_set_eval(const struct nft_expr *expr,
break;
#ifdef CONFIG_NETWORK_SECMARK
case NFT_META_SECMARK:
- skb->secmark = value;
+ secxa_set_secmark(skb, value);
break;
#endif
default:
@@ -950,7 +951,7 @@ static void nft_secmark_obj_eval(struct nft_object *obj, struct nft_regs *regs,
const struct nft_secmark *priv = nft_obj_data(obj);
struct sk_buff *skb = pkt->skb;
- skb->secmark = priv->secid;
+ secxa_set_secmark(skb, priv->secid);
}
static int nft_secmark_obj_init(const struct nft_ctx *ctx,
diff --git a/net/netfilter/xt_CONNSECMARK.c b/net/netfilter/xt_CONNSECMARK.c
index 1494b3ee30e1..9d799d2459dc 100644
--- a/net/netfilter/xt_CONNSECMARK.c
+++ b/net/netfilter/xt_CONNSECMARK.c
@@ -14,6 +14,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <linux/skbuff.h>
+#include <linux/lsm_secxa.h>
#include <linux/netfilter/x_tables.h>
#include <linux/netfilter/xt_CONNSECMARK.h>
#include <net/netfilter/nf_conntrack.h>
@@ -55,7 +56,7 @@ static void secmark_restore(struct sk_buff *skb)
ct = nf_ct_get(skb, &ctinfo);
if (ct && ct->secmark)
- skb->secmark = ct->secmark;
+ secxa_set_secmark(skb, ct->secmark);
}
}
diff --git a/net/netfilter/xt_SECMARK.c b/net/netfilter/xt_SECMARK.c
index 5bc5ea505eb9..ea67aa92ddc2 100644
--- a/net/netfilter/xt_SECMARK.c
+++ b/net/netfilter/xt_SECMARK.c
@@ -11,6 +11,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <linux/security.h>
+#include <linux/lsm_secxa.h>
#include <linux/skbuff.h>
#include <linux/netfilter/x_tables.h>
#include <linux/netfilter/xt_SECMARK.h>
@@ -36,7 +37,7 @@ secmark_tg(struct sk_buff *skb, const struct xt_secmark_target_info_v1 *info)
BUG();
}
- skb->secmark = secmark;
+ secxa_set_secmark(skb, secmark);
return XT_CONTINUE;
}
diff --git a/security/smack/smack_netfilter.c b/security/smack/smack_netfilter.c
index 17ba578b1308..b363c42f252e 100644
--- a/security/smack/smack_netfilter.c
+++ b/security/smack/smack_netfilter.c
@@ -14,6 +14,7 @@
#include <linux/netfilter_ipv4.h>
#include <linux/netfilter_ipv6.h>
#include <linux/netdevice.h>
+#include <linux/lsm_secxa.h>
#include <net/inet_sock.h>
#include <net/net_namespace.h>
#include "smack.h"
@@ -29,7 +30,7 @@ static unsigned int smack_ip_output(void *priv,
if (sk) {
ssp = smack_sock(sk);
skp = ssp->smk_out;
- skb->secmark = skp->smk_secid;
+ secxa_set_secmark(skb, skp->smk_secid);
}
return NF_ACCEPT;
--
2.54.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 2/7] LSM: Implement x array functions for secmarks
2026-08-13 20:48 ` [PATCH 0/7] Change skb secmarks to x-array indexes Casey Schaufler
2026-08-13 20:48 ` [PATCH 1/7] net, smack: Create a function to set secmarks Casey Schaufler
@ 2026-08-13 20:48 ` Casey Schaufler
2026-08-13 20:48 ` [PATCH 3/7] LSM: Two hooks for manipulating struct lsm_prop Casey Schaufler
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Casey Schaufler @ 2026-08-13 20:48 UTC (permalink / raw)
To: casey, paul, linux-security-module, pablo, fw, phil
Cc: linux-kernel, netfilter-devel, coreteam, jmorris, serge, keescook,
john.johansen, penguin-kernel, stephen.smalley.work, selinux
Implement, but don't use (yet) the functions required to use
xarray indexes in secmarks.
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
---
include/linux/lsm_secxa.h | 10 ++--
security/Makefile | 1 +
security/lsm_secxa.c | 107 ++++++++++++++++++++++++++++++++++++++
3 files changed, 113 insertions(+), 5 deletions(-)
create mode 100644 security/lsm_secxa.c
diff --git a/include/linux/lsm_secxa.h b/include/linux/lsm_secxa.h
index f4c732d26680..ffdc354b93fc 100644
--- a/include/linux/lsm_secxa.h
+++ b/include/linux/lsm_secxa.h
@@ -10,12 +10,12 @@
#ifdef CONFIG_SECURITY
#include <linux/security.h>
-#include <linux/skbuff.h>
-static inline void secxa_set_secmark(struct sk_buff *skb, u32 secxa)
-{
- skb->secmark = secxa;
-}
+struct sk_buff;
+
+int secxa_from_lsmprop(struct lsm_prop *prop);
+int secxa_get_lsmprop(struct lsm_prop **pro, u32 secxa);
+void secxa_set_secmark(struct sk_buff *skb, u32 secxa);
#endif /* CONFIG_SECURITY */
diff --git a/security/Makefile b/security/Makefile
index 4601230ba442..e93be00bb6ae 100644
--- a/security/Makefile
+++ b/security/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_KEYS) += keys/
# always enable default capabilities
obj-y += commoncap.o
obj-$(CONFIG_SECURITY) += lsm_syscalls.o
+obj-$(CONFIG_NETWORK_SECMARK) += lsm_secxa.o
obj-$(CONFIG_MMU) += min_addr.o
# Object file lists
diff --git a/security/lsm_secxa.c b/security/lsm_secxa.c
new file mode 100644
index 000000000000..5b67d8218fd2
--- /dev/null
+++ b/security/lsm_secxa.c
@@ -0,0 +1,107 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+/*
+ * Implement functions supporting an x array for LSM properties.
+ *
+ * Copyright (C) 2026 Casey Schaufler <casey@schaufler-ca.com>
+ */
+#define pr_fmt(fmt) "secxa: "fmt
+
+#include <linux/xarray.h>
+#include <linux/export.h>
+#include <linux/security.h>
+#include <linux/lsm_secxa.h>
+#include <linux/skbuff.h>
+
+/*
+ * An Xarray of lsm_prop structures.
+ */
+struct xarray secxa_xa;
+
+/**
+ * secxa_init - initialize the xarry of lsm_prop structures.
+ */
+static int __init secxa_init(void)
+{
+ xa_init_flags(&secxa_xa, XA_FLAGS_ALLOC1);
+
+ return 0;
+}
+core_initcall(secxa_init);
+
+/**
+ * secxa_get_lsmprop - get the lsm_prop associated with a secxa
+ * @pro: destination for the lsm_prop pointer
+ * @secxa: index to look up
+ *
+ * Find the lsm_prop associated with @secxa and place a pointer
+ * to it in @pro.
+ *
+ * Returns 0, or -EINVAL if the mapping can't be found.
+ */
+int secxa_get_lsmprop(struct lsm_prop **pro, u32 secxa)
+{
+ struct lsm_prop *lp;
+
+ if (!secxa)
+ return -EINVAL;
+
+ lp = xa_load(&secxa_xa, secxa);
+ if (!lp)
+ return -EINVAL;
+
+ *pro = lp;
+ return 0;
+}
+EXPORT_SYMBOL(secxa_get_lsmprop);
+
+/**
+ * secxa_from_lsmprop - get the secxa associated with a lsm_prop
+ * @prop: lsm_prop pointer
+ *
+ * Find the secxa associated with @prop. If there is none, create it.
+ *
+ * Returns 0, or an error if the mapping cannot be created
+ */
+int secxa_from_lsmprop(struct lsm_prop *prop)
+{
+ struct lsm_prop *lp;
+ unsigned long il;
+ unsigned int index = 0;
+ int rc;
+
+ xa_for_each(&secxa_xa, il, lp) {
+ if (!memcmp(prop, lp, sizeof(*prop)))
+ pr_info("%s found at index %lu\n", __func__, il);
+ if (!memcmp(prop, lp, sizeof(*prop)))
+ return il;
+ }
+
+ lp = kzalloc(sizeof(*lp), GFP_ATOMIC);
+ if (!lp)
+ return -ENOMEM;
+
+ rc = xa_alloc(&secxa_xa, &index, lp, xa_limit_32b, GFP_ATOMIC);
+ if (rc) {
+ kfree(lp);
+ return -EINVAL;
+ }
+ *lp = *prop;
+
+ return index;
+}
+EXPORT_SYMBOL(secxa_from_lsmprop);
+
+/**
+ * secxa_set_secmark - add LSM information to a secmark
+ * @skb: buffer with the secmark
+ * @secxa: index of the information to add
+ *
+ * If the secmark in @skb is not set, set it to @secxa.
+ */
+void secxa_set_secmark(struct sk_buff *skb, u32 secxa)
+{
+ if (!skb->secmark)
+ skb->secmark = secxa;
+}
+EXPORT_SYMBOL(secxa_set_secmark);
--
2.54.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 3/7] LSM: Two hooks for manipulating struct lsm_prop
2026-08-13 20:48 ` [PATCH 0/7] Change skb secmarks to x-array indexes Casey Schaufler
2026-08-13 20:48 ` [PATCH 1/7] net, smack: Create a function to set secmarks Casey Schaufler
2026-08-13 20:48 ` [PATCH 2/7] LSM: Implement x array functions for secmarks Casey Schaufler
@ 2026-08-13 20:48 ` Casey Schaufler
2026-08-13 20:48 ` [PATCH 4/7] SELinux: hooks for secctx_to_lsmprop and update_lsmprop Casey Schaufler
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Casey Schaufler @ 2026-08-13 20:48 UTC (permalink / raw)
To: casey, paul, linux-security-module, pablo, fw, phil
Cc: linux-kernel, netfilter-devel, coreteam, jmorris, serge, keescook,
john.johansen, penguin-kernel, stephen.smalley.work, selinux
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@schaufler-ca.com>
---
include/linux/lsm_hook_defs.h | 4 ++++
include/linux/security.h | 17 +++++++++++++++++
security/security.c | 32 ++++++++++++++++++++++++++++++++
3 files changed, 53 insertions(+)
diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h
index 65c9609ec207..3666d821b8a1 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(int, -EOPNOTSUPP, 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, 0, 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..b209d681e79a 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);
+
+int 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,12 @@ static inline int security_lsmprop_to_secctx(struct lsm_prop *prop,
return -EOPNOTSUPP;
}
+static inline int security_update_lsmprop(struct lsm_prop *dest,
+ struct lsm_prop *src, int lsmid)
+{
+ return -EOPNOTSUPP;
+}
+
static inline int security_secctx_to_secid(const char *secdata,
u32 seclen,
u32 *secid)
@@ -1588,6 +1599,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..932a2eca28b3 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);
+int security_update_lsmprop(struct lsm_prop *dest, struct lsm_prop *src,
+ int lsmid)
+{
+ return call_int_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
--
2.54.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 4/7] SELinux: hooks for secctx_to_lsmprop and update_lsmprop
2026-08-13 20:48 ` [PATCH 0/7] Change skb secmarks to x-array indexes Casey Schaufler
` (2 preceding siblings ...)
2026-08-13 20:48 ` [PATCH 3/7] LSM: Two hooks for manipulating struct lsm_prop Casey Schaufler
@ 2026-08-13 20:48 ` Casey Schaufler
2026-08-13 20:48 ` [PATCH 5/7] Smack: " Casey Schaufler
2026-08-13 20:48 ` [PATCH 6/7] Apparmor: " Casey Schaufler
5 siblings, 0 replies; 8+ messages in thread
From: Casey Schaufler @ 2026-08-13 20:48 UTC (permalink / raw)
To: casey, paul, linux-security-module, pablo, fw, phil
Cc: linux-kernel, netfilter-devel, coreteam, jmorris, serge, keescook,
john.johansen, penguin-kernel, stephen.smalley.work, selinux
Implement these hooks.
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
---
security/selinux/hooks.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 8d6945edae7a..c05c05e71078 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -6946,6 +6946,15 @@ static int selinux_ismaclabel(const char *name)
return (strcmp(name, XATTR_SELINUX_SUFFIX) == 0);
}
+static int selinux_update_lsmprop(struct lsm_prop *dest, struct lsm_prop *src,
+ int lsmid)
+{
+ if (lsmid == LSM_ID_SELINUX || lsmid == LSM_ID_UNDEF)
+ dest->selinux.secid = src->selinux.secid;
+
+ return 0;
+}
+
static int selinux_secid_to_secctx(u32 secid, struct lsm_context *cp)
{
u32 seclen;
@@ -6964,6 +6973,13 @@ static int selinux_secid_to_secctx(u32 secid, struct lsm_context *cp)
return seclen;
}
+static int selinux_secctx_to_lsmprop(const char *secdata, u32 seclen,
+ struct lsm_prop *prop)
+{
+ return security_context_to_sid(secdata, seclen, &prop->selinux.secid,
+ GFP_KERNEL);
+}
+
static int selinux_lsmprop_to_secctx(struct lsm_prop *prop,
struct lsm_context *cp)
{
@@ -7694,6 +7710,7 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {
LSM_HOOK_INIT(ismaclabel, selinux_ismaclabel),
LSM_HOOK_INIT(secctx_to_secid, selinux_secctx_to_secid),
+ LSM_HOOK_INIT(secctx_to_lsmprop, selinux_secctx_to_lsmprop),
LSM_HOOK_INIT(release_secctx, selinux_release_secctx),
LSM_HOOK_INIT(inode_invalidate_secctx, selinux_inode_invalidate_secctx),
LSM_HOOK_INIT(inode_notifysecctx, selinux_inode_notifysecctx),
@@ -7812,6 +7829,7 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {
LSM_HOOK_INIT(sem_alloc_security, selinux_sem_alloc_security),
LSM_HOOK_INIT(secid_to_secctx, selinux_secid_to_secctx),
LSM_HOOK_INIT(lsmprop_to_secctx, selinux_lsmprop_to_secctx),
+ LSM_HOOK_INIT(update_lsmprop, selinux_update_lsmprop),
LSM_HOOK_INIT(inode_getsecctx, selinux_inode_getsecctx),
LSM_HOOK_INIT(sk_alloc_security, selinux_sk_alloc_security),
LSM_HOOK_INIT(tun_dev_alloc_security, selinux_tun_dev_alloc_security),
--
2.54.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 5/7] Smack: hooks for secctx_to_lsmprop and update_lsmprop
2026-08-13 20:48 ` [PATCH 0/7] Change skb secmarks to x-array indexes Casey Schaufler
` (3 preceding siblings ...)
2026-08-13 20:48 ` [PATCH 4/7] SELinux: hooks for secctx_to_lsmprop and update_lsmprop Casey Schaufler
@ 2026-08-13 20:48 ` Casey Schaufler
2026-08-13 20:48 ` [PATCH 6/7] Apparmor: " Casey Schaufler
5 siblings, 0 replies; 8+ messages in thread
From: Casey Schaufler @ 2026-08-13 20:48 UTC (permalink / raw)
To: casey, paul, linux-security-module, pablo, fw, phil
Cc: linux-kernel, netfilter-devel, coreteam, jmorris, serge, keescook,
john.johansen, penguin-kernel, stephen.smalley.work, selinux
Implement these hooks.
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
---
security/smack/smack_lsm.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index ff115068c5c0..8e3ab61dfdd9 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -4909,6 +4909,40 @@ static int smack_lsmprop_to_secctx(struct lsm_prop *prop,
return smack_to_secctx(prop->smack.skp, cp);
}
+/**
+ * smack_secctx_to_lsmprop - add the smack label to an lsmprop
+ * @secdata: smack label
+ * @seclen: how long label is
+ * @prop: where to put the result
+ *
+ * Exists for audit and networking code.
+ */
+static int smack_secctx_to_lsmprop(const char *secdata, u32 seclen,
+ struct lsm_prop *prop)
+{
+ prop->smack.skp = smk_find_entry(secdata);
+
+ return 0;
+}
+
+/**
+ * smack_update_lsmprop - set the smack label in an lsmprop
+ * @dest: destination properties
+ * @src: source properties
+ * @lsmid: which LSM is relevant.
+ *
+ * Set the Smack entry in the @dest if appropriate.
+ * Returns 0.
+ */
+static int smack_update_lsmprop(struct lsm_prop *dest, struct lsm_prop *src,
+ int lsmid)
+{
+ if (lsmid == LSM_ID_SMACK || lsmid == LSM_ID_UNDEF)
+ dest->smack.skp = src->smack.skp;
+
+ return 0;
+}
+
/**
* smack_secctx_to_secid - return the secid for a smack label
* @secdata: smack label
@@ -5269,6 +5303,8 @@ static struct security_hook_list smack_hooks[] __ro_after_init = {
LSM_HOOK_INIT(secid_to_secctx, smack_secid_to_secctx),
LSM_HOOK_INIT(lsmprop_to_secctx, smack_lsmprop_to_secctx),
LSM_HOOK_INIT(secctx_to_secid, smack_secctx_to_secid),
+ LSM_HOOK_INIT(secctx_to_lsmprop, smack_secctx_to_lsmprop),
+ LSM_HOOK_INIT(update_lsmprop, smack_update_lsmprop),
LSM_HOOK_INIT(inode_notifysecctx, smack_inode_notifysecctx),
LSM_HOOK_INIT(inode_setsecctx, smack_inode_setsecctx),
LSM_HOOK_INIT(inode_getsecctx, smack_inode_getsecctx),
--
2.54.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 6/7] Apparmor: hooks for secctx_to_lsmprop and update_lsmprop
2026-08-13 20:48 ` [PATCH 0/7] Change skb secmarks to x-array indexes Casey Schaufler
` (4 preceding siblings ...)
2026-08-13 20:48 ` [PATCH 5/7] Smack: " Casey Schaufler
@ 2026-08-13 20:48 ` Casey Schaufler
5 siblings, 0 replies; 8+ messages in thread
From: Casey Schaufler @ 2026-08-13 20:48 UTC (permalink / raw)
To: casey, paul, linux-security-module, pablo, fw, phil
Cc: linux-kernel, netfilter-devel, coreteam, jmorris, serge, keescook,
john.johansen, penguin-kernel, stephen.smalley.work, selinux
Implement these hooks.
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
---
security/apparmor/include/secid.h | 4 ++++
security/apparmor/lsm.c | 2 ++
security/apparmor/secid.c | 23 +++++++++++++++++++++++
3 files changed, 29 insertions(+)
diff --git a/security/apparmor/include/secid.h b/security/apparmor/include/secid.h
index 6025d3849cf8..b290ae8f9b01 100644
--- a/security/apparmor/include/secid.h
+++ b/security/apparmor/include/secid.h
@@ -28,6 +28,10 @@ struct aa_label *aa_secid_to_label(u32 secid);
int apparmor_secid_to_secctx(u32 secid, struct lsm_context *cp);
int apparmor_lsmprop_to_secctx(struct lsm_prop *prop, struct lsm_context *cp);
int apparmor_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid);
+int apparmor_secctx_to_lsmprop(const char *secdata, u32 seclen,
+ struct lsm_prop *prop);
+int apparmor_update_lsmprop(struct lsm_prop *dest, struct lsm_prop *src,
+ int lsmid);
void apparmor_release_secctx(struct lsm_context *cp);
diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
index 88d12e89d115..1f304b88eaf9 100644
--- a/security/apparmor/lsm.c
+++ b/security/apparmor/lsm.c
@@ -1766,6 +1766,8 @@ static struct security_hook_list apparmor_hooks[] __ro_after_init = {
LSM_HOOK_INIT(secid_to_secctx, apparmor_secid_to_secctx),
LSM_HOOK_INIT(lsmprop_to_secctx, apparmor_lsmprop_to_secctx),
LSM_HOOK_INIT(secctx_to_secid, apparmor_secctx_to_secid),
+ LSM_HOOK_INIT(secctx_to_lsmprop, apparmor_secctx_to_lsmprop),
+ LSM_HOOK_INIT(update_lsmprop, apparmor_update_lsmprop),
LSM_HOOK_INIT(release_secctx, apparmor_release_secctx),
#ifdef CONFIG_IO_URING
diff --git a/security/apparmor/secid.c b/security/apparmor/secid.c
index 28caf66b9033..51f3e4ab053e 100644
--- a/security/apparmor/secid.c
+++ b/security/apparmor/secid.c
@@ -106,6 +106,29 @@ int apparmor_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
return 0;
}
+int apparmor_secctx_to_lsmprop(const char *secdata, u32 seclen,
+ struct lsm_prop *prop)
+{
+ struct aa_label *label;
+
+ label = aa_label_strn_parse(&root_ns->unconfined->label, secdata,
+ seclen, GFP_KERNEL, false, false);
+ if (IS_ERR(label))
+ return PTR_ERR(label);
+ prop->apparmor.label = label;
+
+ return 0;
+}
+
+int apparmor_update_lsmprop(struct lsm_prop *dest, struct lsm_prop *src,
+ int lsmid)
+{
+ if (lsmid == LSM_ID_APPARMOR || lsmid == LSM_ID_UNDEF)
+ dest->apparmor.label = src->apparmor.label;
+
+ return 0;
+}
+
void apparmor_release_secctx(struct lsm_context *cp)
{
if (cp->id == LSM_ID_APPARMOR) {
--
2.54.0
^ permalink raw reply related [flat|nested] 8+ messages in thread