linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Mickaël Salaün" <mic@digikod.net>
To: Casey Schaufler <casey@schaufler-ca.com>,
	casey.schaufler@intel.com, paul@paul-moore.com,
	linux-security-module@vger.kernel.org
Cc: linux-audit@redhat.com, jmorris@namei.org,
	selinux@vger.kernel.org, keescook@chromium.org,
	john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp,
	stephen.smalley.work@gmail.com, linux-kernel@vger.kernel.org,
	linux-api@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>
Subject: Re: [PATCH v38 39/39] LSM: Create lsm_module_list system call
Date: Wed, 12 Oct 2022 23:19:49 +0200	[thread overview]
Message-ID: <13ab134b-e7a9-fe3f-a05a-7cece1d52403@digikod.net> (raw)
In-Reply-To: <20220927203155.15060-1-casey@schaufler-ca.com>


On 27/09/2022 22:31, Casey Schaufler wrote:
> Create a system call to report the list of Linux Security Modules
> that are active on the system. The list is provided as an array
> of LSM ID numbers.

With lsm_self_attr(), this would look like a dir/file structure.

Would it be useful for user space to list all the currently used LSMs 
instead of only retrieving information about a known (list of) LSM?
What is the use case for this syscall?


> 
> Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
> ---
>   arch/x86/entry/syscalls/syscall_64.tbl |  1 +
>   include/linux/syscalls.h               |  1 +
>   include/uapi/asm-generic/unistd.h      |  5 ++-
>   kernel/sys_ni.c                        |  1 +
>   security/lsm_syscalls.c                | 50 ++++++++++++++++++++++++++
>   5 files changed, 57 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/entry/syscalls/syscall_64.tbl b/arch/x86/entry/syscalls/syscall_64.tbl
> index 56d5c5202fd0..40b35e7069a7 100644
> --- a/arch/x86/entry/syscalls/syscall_64.tbl
> +++ b/arch/x86/entry/syscalls/syscall_64.tbl
> @@ -373,6 +373,7 @@
>   449	common	futex_waitv		sys_futex_waitv
>   450	common	set_mempolicy_home_node	sys_set_mempolicy_home_node
>   451	common	lsm_self_attr		sys_lsm_self_attr
> +452	common	lsm_module_list		sys_lsm_module_list

As for the other syscall, this should also be in the same dedicated 
"wire syscalls" patch.


>   
>   #
>   # Due to a historical design error, certain syscalls are numbered differently
> diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
> index 7f87ef8be546..e2e2a9e93e8c 100644
> --- a/include/linux/syscalls.h
> +++ b/include/linux/syscalls.h
> @@ -1057,6 +1057,7 @@ asmlinkage long sys_set_mempolicy_home_node(unsigned long start, unsigned long l
>   					    unsigned long home_node,
>   					    unsigned long flags);
>   asmlinkage long sys_lsm_self_attr(struct lsm_ctx *ctx, size_t *size, int flags);
> +asmlinkage long sys_lsm_module_list(unsigned int *ids, size_t *size, int flags);
>   
>   /*
>    * Architecture-specific system calls
> diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h
> index aa66718e1b48..090617a9a53a 100644
> --- a/include/uapi/asm-generic/unistd.h
> +++ b/include/uapi/asm-generic/unistd.h
> @@ -889,8 +889,11 @@ __SYSCALL(__NR_set_mempolicy_home_node, sys_set_mempolicy_home_node)
>   #define __NR_lsm_self_attr 451
>   __SYSCALL(__NR_lsm_self_attr, sys_lsm_self_attr)
>   
> +#define __NR_lsm_module_list 452
> +__SYSCALL(__NR_lsm_module_list, sys_lsm_module_list)
> +
>   #undef __NR_syscalls
> -#define __NR_syscalls 452
> +#define __NR_syscalls 453

Same here.


>   
>   /*
>    * 32 bit systems traditionally used different
> diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c
> index 0fdb0341251d..bde9e74a3473 100644
> --- a/kernel/sys_ni.c
> +++ b/kernel/sys_ni.c
> @@ -264,6 +264,7 @@ COND_SYSCALL(mremap);
>   
>   /* security/lsm_syscalls.c */
>   COND_SYSCALL(lsm_self_attr);
> +COND_SYSCALL(lsm_module_list);
>   
>   /* security/keys/keyctl.c */
>   COND_SYSCALL(add_key);
> diff --git a/security/lsm_syscalls.c b/security/lsm_syscalls.c
> index da0fab7065e2..41d9ef945ede 100644
> --- a/security/lsm_syscalls.c
> +++ b/security/lsm_syscalls.c
> @@ -154,3 +154,53 @@ SYSCALL_DEFINE3(lsm_self_attr,
>   	kfree(final);
>   	return rc;
>   }
> +
> +/**
> + * lsm_module_list - Return a list of the active security modules
> + * @ids: the LSM module ids
> + * @size: size of @ids, updated on return
> + * @flags: reserved for future use, must be zero
> + *
> + * Returns a list of the active LSM ids. On success this function
> + * returns the number of @ids array elements. This value may be zero
> + * if there are no LSMs active. If @size is insufficient to contain
> + * the return data -E2BIG is returned and @size is set to the minimum
> + * required size. In all other cases a negative value indicating the
> + * error is returned.
> + */
> +SYSCALL_DEFINE3(lsm_module_list,
> +	       unsigned int __user *, ids,
> +	       size_t __user *, size,
> +	       int, flags)
> +{
> +	unsigned int *interum;
> +	size_t total_size = lsm_id * sizeof(*interum);
> +	size_t usize;
> +	int rc;
> +	int i;
> +
> +	if (get_user(usize, size))
> +		return -EFAULT;
> +
> +	if (usize < total_size) {
> +		if (put_user(total_size, size) != 0)
> +			return -EFAULT;
> +		return -E2BIG;
> +	}
> +
> +	interum = kzalloc(total_size, GFP_KERNEL);
> +	if (interum == NULL)
> +		return -ENOMEM;
> +
> +	for (i = 0; i < lsm_id; i++)
> +		interum[i] = lsm_idlist[i]->id;
> +
> +	if (copy_to_user(ids, interum, total_size) != 0 ||
> +	    put_user(total_size, size) != 0)
> +		rc = -EFAULT;
> +	else
> +		rc = lsm_id;
> +
> +	kfree(interum);
> +	return rc;
> +}

  parent reply	other threads:[~2022-10-12 21:20 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20220927195421.14713-1-casey.ref@schaufler-ca.com>
2022-09-27 19:53 ` [PATCH v38 00/39] LSM: Module stacking for AppArmor Casey Schaufler
2022-09-27 19:53   ` [PATCH v38 01/39] LSM: Identify modules by more than name Casey Schaufler
2022-10-12 21:14     ` Mickaël Salaün
2023-03-03 15:17     ` Georgia Garcia
2023-03-03 16:52       ` Casey Schaufler
2022-09-27 19:53   ` [PATCH v38 02/39] LSM: Add an LSM identifier for external use Casey Schaufler
2022-10-12 21:14     ` Mickaël Salaün
2022-10-20 22:47       ` Casey Schaufler
2023-03-03 17:14     ` Georgia Garcia
2022-09-27 19:53   ` [PATCH v38 03/39] LSM: Identify the process attributes for each module Casey Schaufler
2022-09-27 19:53   ` [PATCH v38 04/39] LSM: Maintain a table of LSM attribute data Casey Schaufler
2022-10-13 10:04     ` Tetsuo Handa
2022-10-20 23:42       ` Casey Schaufler
2022-10-23  7:27         ` Tetsuo Handa
2022-10-23 10:10           ` Tetsuo Handa
2022-10-23 17:20             ` Casey Schaufler
2022-10-23 17:13           ` Casey Schaufler
2022-10-24 15:13             ` Tetsuo Handa
2022-10-24 16:37               ` Casey Schaufler
2022-10-25  9:59                 ` Tetsuo Handa
2022-09-27 19:53   ` [PATCH v38 05/39] proc: Use lsmids instead of lsm names for attrs Casey Schaufler
2022-09-27 19:53   ` [PATCH v38 06/39] LSM: lsm_self_attr syscall for LSM self attributes Casey Schaufler
2022-09-27 22:45     ` kernel test robot
2022-09-28 11:04     ` kernel test robot
2022-10-12 21:16     ` Mickaël Salaün
2022-10-20 15:44     ` Paul Moore
2022-10-20 16:13       ` Casey Schaufler
2022-09-27 19:53   ` [PATCH v38 07/39] integrity: disassociate ima_filter_rule from security_audit_rule Casey Schaufler
2022-09-27 19:53   ` [PATCH v38 08/39] LSM: Infrastructure management of the sock security Casey Schaufler
2022-10-12 21:17     ` Mickaël Salaün
2022-09-27 19:53   ` [PATCH v38 09/39] LSM: Add the lsmblob data structure Casey Schaufler
2022-10-12 21:18     ` Mickaël Salaün
2022-09-27 19:53   ` [PATCH v38 10/39] LSM: provide lsm name and id slot mappings Casey Schaufler
2022-09-27 19:53   ` [PATCH v38 11/39] IMA: avoid label collisions with stacked LSMs Casey Schaufler
2022-09-27 19:53   ` [PATCH v38 12/39] LSM: Use lsmblob in security_audit_rule_match Casey Schaufler
2022-09-27 19:53   ` [PATCH v38 13/39] LSM: Use lsmblob in security_kernel_act_as Casey Schaufler
2022-09-27 19:53   ` [PATCH v38 14/39] LSM: Use lsmblob in security_secctx_to_secid Casey Schaufler
2022-09-27 19:53   ` [PATCH v38 15/39] LSM: Use lsmblob in security_secid_to_secctx Casey Schaufler
2022-09-27 19:53   ` [PATCH v38 16/39] LSM: Use lsmblob in security_ipc_getsecid Casey Schaufler
2022-09-27 19:53   ` [PATCH v38 17/39] LSM: Use lsmblob in security_current_getsecid Casey Schaufler
2022-09-27 19:54   ` [PATCH v38 18/39] LSM: Use lsmblob in security_inode_getsecid Casey Schaufler
2022-09-27 19:54   ` [PATCH v38 19/39] LSM: Use lsmblob in security_cred_getsecid Casey Schaufler
2022-09-27 19:54   ` [PATCH v38 20/39] LSM: Specify which LSM to display Casey Schaufler
2022-10-12 21:19     ` Mickaël Salaün
2022-09-27 19:54   ` [PATCH v38 21/39] LSM: Ensure the correct LSM context releaser Casey Schaufler
2022-09-27 19:54   ` [PATCH v38 22/39] LSM: Use lsmcontext in security_secid_to_secctx Casey Schaufler
2022-09-27 19:54   ` [PATCH v38 23/39] LSM: Use lsmcontext in security_inode_getsecctx Casey Schaufler
2022-09-27 19:54   ` [PATCH v38 24/39] Use lsmcontext in security_dentry_init_security Casey Schaufler
2022-09-27 19:54   ` [PATCH v38 25/39] LSM: security_secid_to_secctx in netlink netfilter Casey Schaufler
2022-09-27 19:54   ` [PATCH v38 26/39] NET: Store LSM netlabel data in a lsmblob Casey Schaufler
2022-09-27 19:54   ` [PATCH v38 27/39] binder: Pass LSM identifier for confirmation Casey Schaufler
2022-09-27 19:54   ` [PATCH v38 28/39] LSM: security_secid_to_secctx module selection Casey Schaufler
2022-09-27 19:54   ` [PATCH v38 29/39] Audit: Keep multiple LSM data in audit_names Casey Schaufler
2022-09-27 19:54   ` [PATCH v38 30/39] Audit: Create audit_stamp structure Casey Schaufler
2022-09-27 19:54   ` [PATCH v38 31/39] LSM: Add a function to report multiple LSMs Casey Schaufler
2022-09-27 19:54   ` [PATCH v38 32/39] Audit: Allow multiple records in an audit_buffer Casey Schaufler
2022-09-27 19:54   ` [PATCH v38 33/39] Audit: Add record for multiple task security contexts Casey Schaufler
2022-09-27 19:54   ` [PATCH v38 34/39] audit: multiple subject lsm values for netlabel Casey Schaufler
2022-09-27 19:54   ` [PATCH v38 35/39] Audit: Add record for multiple object contexts Casey Schaufler
2022-09-27 19:54   ` [PATCH v38 36/39] netlabel: Use a struct lsmblob in audit data Casey Schaufler
2022-09-27 19:54   ` [PATCH v38 37/39] LSM: Removed scaffolding function lsmcontext_init Casey Schaufler
2022-09-27 19:54   ` [PATCH v38 38/39] AppArmor: Remove the exclusive flag Casey Schaufler
2022-09-27 20:31   ` [PATCH v38 39/39] LSM: Create lsm_module_list system call Casey Schaufler
2022-09-28 14:27     ` kernel test robot
2022-10-12 21:19     ` Mickaël Salaün [this message]
2022-10-20 20:28       ` Casey Schaufler
2022-10-12 22:04     ` Kees Cook
2022-10-25  0:39       ` 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=13ab134b-e7a9-fe3f-a05a-7cece1d52403@digikod.net \
    --to=mic@digikod.net \
    --cc=arnd@arndb.de \
    --cc=casey.schaufler@intel.com \
    --cc=casey@schaufler-ca.com \
    --cc=jmorris@namei.org \
    --cc=john.johansen@canonical.com \
    --cc=keescook@chromium.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-audit@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).