From: Paul Moore <paul@paul-moore.com>
To: linux-security-module@vger.kernel.org
Subject: [PATCH 01/22] lsm: move the program execution hook comments to security/security.c
Date: Thu, 16 Feb 2023 22:26:04 -0500 [thread overview]
Message-ID: <20230217032625.678457-2-paul@paul-moore.com> (raw)
In-Reply-To: <20230217032625.678457-1-paul@paul-moore.com>
This patch relocates the LSM hook function comments to the function
definitions, in keeping with the current kernel conventions. This
should make the hook descriptions more easily discoverable and easier
to maintain.
While formatting changes have been done to better fit the kernel-doc
style, content changes have been kept to a minimum and limited to
text which was obviously incorrect and/or outdated. It is expected
the future patches will improve the quality of the function header
comments.
Signed-off-by: Paul Moore <paul@paul-moore.com>
---
include/linux/lsm_hooks.h | 52 -----------------------------
security/security.c | 69 +++++++++++++++++++++++++++++++++++++++
2 files changed, 69 insertions(+), 52 deletions(-)
diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h
index 0a5ba81f7367..24c242713a44 100644
--- a/include/linux/lsm_hooks.h
+++ b/include/linux/lsm_hooks.h
@@ -32,58 +32,6 @@
/**
* union security_list_options - Linux Security Module hook function list
*
- * Security hooks for program execution operations.
- *
- * @bprm_creds_for_exec:
- * If the setup in prepare_exec_creds did not setup @bprm->cred->security
- * properly for executing @bprm->file, update the LSM's portion of
- * @bprm->cred->security to be what commit_creds needs to install for the
- * new program. This hook may also optionally check permissions
- * (e.g. for transitions between security domains).
- * The hook must set @bprm->secureexec to 1 if AT_SECURE should be set to
- * request libc enable secure mode.
- * @bprm contains the linux_binprm structure.
- * Return 0 if the hook is successful and permission is granted.
- * @bprm_creds_from_file:
- * If @file is setpcap, suid, sgid or otherwise marked to change
- * privilege upon exec, update @bprm->cred to reflect that change.
- * This is called after finding the binary that will be executed.
- * without an interpreter. This ensures that the credentials will not
- * be derived from a script that the binary will need to reopen, which
- * when reopend may end up being a completely different file. This
- * hook may also optionally check permissions (e.g. for transitions
- * between security domains).
- * The hook must set @bprm->secureexec to 1 if AT_SECURE should be set to
- * request libc enable secure mode.
- * The hook must add to @bprm->per_clear any personality flags that
- * should be cleared from current->personality.
- * @bprm contains the linux_binprm structure.
- * Return 0 if the hook is successful and permission is granted.
- * @bprm_check_security:
- * This hook mediates the point when a search for a binary handler will
- * begin. It allows a check against the @bprm->cred->security value
- * which was set in the preceding creds_for_exec call. The argv list and
- * envp list are reliably available in @bprm. This hook may be called
- * multiple times during a single execve.
- * @bprm contains the linux_binprm structure.
- * Return 0 if the hook is successful and permission is granted.
- * @bprm_committing_creds:
- * Prepare to install the new security attributes of a process being
- * transformed by an execve operation, based on the old credentials
- * pointed to by @current->cred and the information set in @bprm->cred by
- * the bprm_creds_for_exec hook. @bprm points to the linux_binprm
- * structure. This hook is a good place to perform state changes on the
- * process such as closing open file descriptors to which access will no
- * longer be granted when the attributes are changed. This is called
- * immediately before commit_creds().
- * @bprm_committed_creds:
- * Tidy up after the installation of the new security attributes of a
- * process being transformed by an execve operation. The new credentials
- * have, by this point, been set to @current->cred. @bprm points to the
- * linux_binprm structure. This hook is a good place to perform state
- * changes on the process such as clearing out non-inheritable signal
- * state. This is called immediately after commit_creds().
- *
* Security hooks for mount using fs_context.
* [See also Documentation/filesystems/mount_api.rst]
*
diff --git a/security/security.c b/security/security.c
index d1571900a8c7..9e98f6703e18 100644
--- a/security/security.c
+++ b/security/security.c
@@ -6,6 +6,7 @@
* Copyright (C) 2001-2002 Greg Kroah-Hartman <greg@kroah.com>
* Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.com>
* Copyright (C) 2016 Mellanox Technologies
+ * Copyright (C) 2023 Microsoft Corporation <paul@paul-moore.com>
*/
#define pr_fmt(fmt) "LSM: " fmt
@@ -880,16 +881,61 @@ int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
return __vm_enough_memory(mm, pages, cap_sys_admin);
}
+/**
+ * security_bprm_creds_for_exec() - Prepare the credentials for exec()
+ * @bprm: binary program information
+ *
+ * If the setup in prepare_exec_creds did not setup @bprm->cred->security
+ * properly for executing @bprm->file, update the LSM's portion of
+ * @bprm->cred->security to be what commit_creds needs to install for the new
+ * program. This hook may also optionally check permissions (e.g. for
+ * transitions between security domains). The hook must set @bprm->secureexec
+ * to 1 if AT_SECURE should be set to request libc enable secure mode. @bprm
+ * contains the linux_binprm structure.
+ *
+ * Return: Returns 0 if the hook is successful and permission is granted.
+ */
int security_bprm_creds_for_exec(struct linux_binprm *bprm)
{
return call_int_hook(bprm_creds_for_exec, 0, bprm);
}
+/**
+ * security_bprm_creds_from_file() - Update linux_binprm creds based on file
+ * @bprm: binary program information
+ * @file: associated file
+ *
+ * If @file is setpcap, suid, sgid or otherwise marked to change privilege upon
+ * exec, update @bprm->cred to reflect that change. This is called after
+ * finding the binary that will be executed without an interpreter. This
+ * ensures that the credentials will not be derived from a script that the
+ * binary will need to reopen, which when reopend may end up being a completely
+ * different file. This hook may also optionally check permissions (e.g. for
+ * transitions between security domains). The hook must set @bprm->secureexec
+ * to 1 if AT_SECURE should be set to request libc enable secure mode. The
+ * hook must add to @bprm->per_clear any personality flags that should be
+ * cleared from current->personality. @bprm contains the linux_binprm
+ * structure.
+ *
+ * Return: Returns 0 if the hook is successful and permission is granted.
+ */
int security_bprm_creds_from_file(struct linux_binprm *bprm, struct file *file)
{
return call_int_hook(bprm_creds_from_file, 0, bprm, file);
}
+/**
+ * security_bprm_check() - Mediate binary handler search
+ * @bprm: binary program information
+ *
+ * This hook mediates the point when a search for a binary handler will begin.
+ * It allows a check against the @bprm->cred->security value which was set in
+ * the preceding creds_for_exec call. The argv list and envp list are reliably
+ * available in @bprm. This hook may be called multiple times during a single
+ * execve. @bprm contains the linux_binprm structure.
+ *
+ * Return: Returns 0 if the hook is successful and permission is granted.
+ */
int security_bprm_check(struct linux_binprm *bprm)
{
int ret;
@@ -900,11 +946,34 @@ int security_bprm_check(struct linux_binprm *bprm)
return ima_bprm_check(bprm);
}
+/**
+ * security_bprm_committing_creds() - Install creds for a process during exec()
+ * @bprm: binary program information
+ *
+ * Prepare to install the new security attributes of a process being
+ * transformed by an execve operation, based on the old credentials pointed to
+ * by @current->cred and the information set in @bprm->cred by the
+ * bprm_creds_for_exec hook. @bprm points to the linux_binprm structure. This
+ * hook is a good place to perform state changes on the process such as closing
+ * open file descriptors to which access will no longer be granted when the
+ * attributes are changed. This is called immediately before commit_creds().
+ */
void security_bprm_committing_creds(struct linux_binprm *bprm)
{
call_void_hook(bprm_committing_creds, bprm);
}
+/**
+ * security_bprm_committed_creds() - Tidy up after cred install during exec()
+ * @bprm: binary program information
+ *
+ * Tidy up after the installation of the new security attributes of a process
+ * being transformed by an execve operation. The new credentials have, by this
+ * point, been set to @current->cred. @bprm points to the linux_binprm
+ * structure. This hook is a good place to perform state changes on the
+ * process such as clearing out non-inheritable signal state. This is called
+ * immediately after commit_creds().
+ */
void security_bprm_committed_creds(struct linux_binprm *bprm)
{
call_void_hook(bprm_committed_creds, bprm);
--
2.39.2
next prev parent reply other threads:[~2023-02-17 3:26 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-17 3:26 [PATCH 00/22] Move LSM hook comments into security/security.c Paul Moore
2023-02-17 3:26 ` Paul Moore [this message]
2023-02-17 3:26 ` [PATCH 02/22] lsm: move the fs_context hook comments to security/security.c Paul Moore
2023-02-17 3:26 ` [PATCH 03/22] lsm: move the filesystem " Paul Moore
2023-02-17 3:26 ` [PATCH 04/22] lsm: move the inode " Paul Moore
2023-02-17 3:26 ` [PATCH 05/22] lsm: move the kernfs " Paul Moore
2023-02-17 3:26 ` [PATCH 06/22] lsm: move the file " Paul Moore
2023-02-17 3:26 ` [PATCH 07/22] lsm: move the task " Paul Moore
2023-02-17 3:26 ` [PATCH 08/22] lsm: move the netlink " Paul Moore
2023-02-17 3:26 ` [PATCH 09/22] lsm: move the AF_UNIX " Paul Moore
2023-02-17 3:26 ` [PATCH 10/22] lsm: move the socket " Paul Moore
2023-02-17 3:26 ` [PATCH 11/22] lsm: move the SCTP " Paul Moore
2023-02-17 3:26 ` [PATCH 12/22] lsm: move the Infiniband " Paul Moore
2023-02-17 3:26 ` [PATCH 13/22] lsm: move the xfrm " Paul Moore
2023-02-17 3:26 ` [PATCH 14/22] lsm: move the key " Paul Moore
2023-02-17 3:26 ` [PATCH 15/22] lsm: move the sysv " Paul Moore
2023-02-17 3:26 ` [PATCH 16/22] lsm: move the binder " Paul Moore
2023-02-17 3:26 ` [PATCH 17/22] lsm: move the audit " Paul Moore
2023-02-17 3:26 ` [PATCH 18/22] lsm: move the bpf " Paul Moore
2023-02-17 3:26 ` [PATCH 19/22] lsm: move the perf " Paul Moore
2023-02-17 3:26 ` [PATCH 20/22] lsm: move the io_uring " Paul Moore
2023-02-17 3:26 ` [PATCH 21/22] lsm: move the remaining LSM " Paul Moore
2023-02-17 3:26 ` [PATCH 22/22] lsm: styling fixes " Paul Moore
2023-02-17 14:07 ` [PATCH 00/22] Move LSM hook comments into security/security.c Paul Moore
2023-02-17 17:22 ` Casey Schaufler
2023-02-17 19:04 ` Paul Moore
2023-03-06 18:49 ` Paul Moore
2023-03-07 8:08 ` Roberto Sassu
2023-03-07 16:33 ` Paul Moore
2023-03-07 16:38 ` Roberto Sassu
2023-03-08 17:09 ` Paul Moore
2023-03-08 17:14 ` Roberto Sassu
2023-03-08 17:20 ` 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=20230217032625.678457-2-paul@paul-moore.com \
--to=paul@paul-moore.com \
--cc=linux-security-module@vger.kernel.org \
/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).