All of lore.kernel.org
 help / color / mirror / Atom feed
From: sergeh@kernel.org
To: Stephen Smalley <stephen.smalley.work@gmail.com>
Cc: selinux@vger.kernel.org, paul@paul-moore.com, omosnace@redhat.com
Subject: Re: [RFC PATCH 06/44] selinux: support per-task/cred selinux namespace
Date: Mon, 27 Jan 2025 03:41:03 +0000	[thread overview]
Message-ID: <Z5cAT7xpQJFOrjGf@lei> (raw)
In-Reply-To: <20250102164509.25606-7-stephen.smalley.work@gmail.com>

On Thu, Jan 02, 2025 at 11:44:31AM -0500, Stephen Smalley wrote:
> Extend the task security structure to include a reference to
> the associated selinux namespace, and to also contain a
> pointer to the cred in the parent namespace.  The current selinux
> namespace is changed to the per-task/cred selinux namespace
> for the current task/cred.
> 
> This change makes it possible to support per-cred selinux namespaces,
> but does not yet introduce a mechanism for unsharing of the selinux
> namespace.  Thus, by itself, this change does not alter the existing
> situation with respect to all processes still using a single init
> selinux namespace.
> 
> An alternative would be to hang the selinux namespace off of the
> user namespace, which itself is associated with the cred.  This
> seems undesirable however since DAC and MAC are orthogonal, and
> there appear to be real use cases where one will want to use selinux
> namespaces without user namespaces and vice versa. However, one
> advantage of hanging off the user namespace would be that it is already
> associated with other namespaces, such as the network namespace, thus
> potentially facilitating looking up the relevant selinux namespace from
> the network input/forward hooks.  In most cases however, it appears that
> we could instead copy a reference to the creating task selinux namespace
> to sock security structures and use that in those hooks.
> 
> Introduce a task_security() helper to obtain the correct task/cred
> security structure from the hooks, and update the hooks to use it.
> This returns a pointer to the security structure for the task in
> the same selinux namespace as the caller, or if there is none, a
> fake security structure with the well-defined unlabeled SIDs.  This
> ensures that we return a valid result that can be used for permission
> checks and for returning contexts from e.g. reading /proc/pid/attr files.
> 
> Signed-off-by: Stephen Smalley <stephen.smalley.work@gmail.com>
> ---
>  security/selinux/hooks.c            | 50 +++++++++++++++++++++++++----
>  security/selinux/include/objsec.h   | 23 -------------
>  security/selinux/include/security.h | 32 +++++++++++++++++-
>  3 files changed, 75 insertions(+), 30 deletions(-)
> 
> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> index ad8172ae7fda..ddaf1f527fe3 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -108,9 +108,6 @@
>  
>  #define SELINUX_INODE_INIT_XATTRS 1
>  
> -static struct selinux_state *init_selinux_state;
> -struct selinux_state *current_selinux_state;
> -
>  /* SECMARK reference count */
>  static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
>  
> @@ -207,6 +204,8 @@ static int selinux_lsm_notifier_avc_callback(u32 event)
>  	return 0;
>  }
>  
> +static struct selinux_state *init_selinux_state;
> +
>  /*
>   * initialise the security for the init task
>   */
> @@ -216,6 +215,7 @@ static void cred_init_security(void)
>  
>  	tsec = selinux_cred(unrcu_pointer(current->real_cred));
>  	tsec->osid = tsec->sid = SECINITSID_KERNEL;
> +	tsec->state = get_selinux_state(init_selinux_state);
>  }
>  
>  /*
> @@ -229,6 +229,24 @@ static inline u32 cred_sid(const struct cred *cred)
>  	return tsec->sid;
>  }
>  
> +static struct task_security_struct unlabeled_task_security = {
> +	.osid = SECINITSID_UNLABELED,
> +	.sid = SECINITSID_UNLABELED,
> +};
> +

I don't know the selinux coding style, but I would think it worth
mentioning that a caller of task_security() must hold rcu_read_lock.
As callers you introduce here do.

> +static const struct task_security_struct *task_security(
> +	const struct task_struct *p)
> +{
> +	const struct task_security_struct *tsec;
> +
> +	tsec = selinux_cred(__task_cred(p));
> +	while (tsec->state != current_selinux_state && tsec->parent_cred)
> +		tsec = selinux_cred(tsec->parent_cred);
> +	if (tsec->state != current_selinux_state)
> +		return &unlabeled_task_security;
> +	return tsec;
> +}
> +
>  static void __ad_net_init(struct common_audit_data *ad,
>  			  struct lsm_network_audit *net,
>  			  int ifindex, struct sock *sk, u16 family)

  reply	other threads:[~2025-01-27  3:41 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-02 16:44 [RFC PATCH 00/44] SELinux namespace support Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 01/44] selinux: restore passing of selinux_state Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 02/44] selinux: introduce current_selinux_state Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 03/44] selinux: support multiple selinuxfs instances Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 04/44] selinux: dynamically allocate selinux namespace Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 05/44] netstate,selinux: create the selinux netlink socket per network namespace Stephen Smalley
2025-01-27  3:30   ` sergeh
2025-01-27 15:00     ` Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 06/44] selinux: support per-task/cred selinux namespace Stephen Smalley
2025-01-27  3:41   ` sergeh [this message]
2025-01-27 15:07     ` Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 07/44] selinux: introduce cred_selinux_state() and use it Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 08/44] selinux: add a selinuxfs interface to unshare selinux namespace Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 09/44] selinuxfs: restrict write operations to the same " Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 10/44] selinux: introduce a global SID table Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 11/44] selinux: wrap security server interfaces to use the " Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 12/44] selinux: update hook functions to use correct selinux namespace Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 13/44] selinux: introduce cred_task_has_perm() Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 14/44] selinux: introduce cred_has_extended_perms() Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 15/44] selinux: introduce cred_self_has_perm() Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 16/44] selinux: introduce cred_has_perm() Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 17/44] selinux: introduce cred_ssid_has_perm() and cred_other_has_perm() Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 18/44] selinux: introduce task_obj_perm() Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 19/44] selinux: fix selinux_lsm_getattr() check Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 20/44] selinux: update bprm hooks for selinux namespaces Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 21/44] selinux: add kerneldoc to new permission checking functions Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 22/44] selinux: convert selinux_file_send_sigiotask() to namespace-aware helper Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 23/44] selinux: rename cred_has_perm*() to cred_tsid_has_perm*() Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 24/44] selinux: convert additional checks to cred_ssid_has_perm() Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 25/44] selinux: introduce selinux_state_has_perm() Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 26/44] selinux: annotate selinuxfs permission checks Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 27/44] selinux: annotate process transition " Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 28/44] selinux: convert xfrm and netlabel " Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 29/44] selinux: switch selinux_lsm_setattr() checks to current namespace Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 30/44] selinux: add limits for SELinux namespaces Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 31/44] selinux: fix namespace creation Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 32/44] selinux: limit selinux netlink notifications to init namespace Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 33/44] selinux: refactor selinux_state_create() Stephen Smalley
2025-01-02 16:44 ` [RFC PATCH 34/44] selinux: make open_perms namespace-aware Stephen Smalley
2025-01-02 16:45 ` [RFC PATCH 35/44] selinux: split cred_ssid_has_perm() into two cases Stephen Smalley
2025-01-02 16:45 ` [RFC PATCH 36/44] selinux: set initial SID context for init to "kernel" in global SID table Stephen Smalley
2025-01-02 16:45 ` [RFC PATCH 37/44] selinux: disallow writes to /sys/fs/selinux/user in non-init namespaces Stephen Smalley
2025-01-02 16:45 ` [RFC PATCH 38/44] selinux: convert nlmsg_sock_has_extended_perms() to namespace-aware Stephen Smalley
2025-01-02 16:45 ` [RFC PATCH 39/44] selinux: defer inode init on current selinux state Stephen Smalley
2025-01-02 16:45 ` [RFC PATCH 40/44] selinux: init inode from nearest initialized namespace Stephen Smalley
2025-01-02 16:45 ` [RFC PATCH 41/44] selinux: allow userspace to detect non-init SELinux namespace Stephen Smalley
2025-01-02 16:45 ` [RFC PATCH 42/44] selinux: exempt creation of init SELinux namespace from limits Stephen Smalley
2025-01-02 16:45 ` [RFC PATCH 43/44] selinux: introduce a Kconfig option for SELinux namespaces Stephen Smalley
2025-01-02 16:45 ` [RFC PATCH 44/44] selinux: fix inode initialization when no namespace is initialized Stephen Smalley
2025-01-07 18:31   ` Stephen Smalley
2025-02-07 18:07 ` [RFC PATCH 00/44] SELinux namespace support Stephen Smalley
2025-02-07 19:56   ` Paul Moore

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=Z5cAT7xpQJFOrjGf@lei \
    --to=sergeh@kernel.org \
    --cc=omosnace@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=selinux@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.