lsm: constify the 'target' parameter in security_capget()
PATCH v2 1/1 lsm: constify the 'target' parameter in security_capget()
Three LSMs register the implementations for the "capget" hook: AppArmor, SELinux, and the normal capability code. Looking at the function implementations we may observe that the first parameter "target" is not changing.
Mark the first argument "target" of LSM hook security_capget() as "const" since it will not be changing in the LSM hook.
cap_capget() LSM hook declaration exceeds the 80 characters per line limit. Split the function declaration to multple lines to decrease the line length.
---
Changes in v2:
- Squash the patches 1/2 and 2/2 into a single patch
- Simplify the commit message
include/linux/lsm_hook_defs.h | 2 +- include/linux/security.h | 7 ++++--- kernel/capability.c | 2 +- security/apparmor/lsm.c | 2 +- security/commoncap.c | 2 +- security/security.c | 2 +- security/selinux/hooks.c | 2 +- 7 files changed, 10 insertions(+), 9 deletions(-)
include/linux/lsm_hook_defs.h +1 -1
@@ -36,7 +36,7 @@ LSM_HOOK(int, 0, binder_transfer_file, const struct cred *from, LSM_HOOK(int, 0, ptrace_access_check, struct task_struct *child, unsigned int mode) LSM_HOOK(int, 0, ptrace_traceme, struct task_struct *parent) -LSM_HOOK(int, 0, capget, struct task_struct *target, kernel_cap_t *effective, +LSM_HOOK(int, 0, capget, const struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted) LSM_HOOK(int, 0, capset, struct cred *new, const struct cred *old, const kernel_cap_t *effective, const kernel_cap_t *inheritable,
include/linux/security.h +4 -3
@@ -145,7 +145,8 @@ extern int cap_capable(const struct cred *cred, struct user_namespace *ns,extern int cap_settime (const struct timespec64 *ts,const struct timezone *tz);extern int cap_ptrace_access_check (struct task_struct *child,unsigned int mode);extern int cap_ptrace_traceme (struct task_struct *parent); -extern int cap_capget (struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted); +extern int cap_capget (const struct task_struct *target,kernel_cap_t *effective, +kernel_cap_t *inheritable,kernel_cap_t *permitted); extern int cap_capset(struct cred *new, const struct cred *old, const kernel_cap_t *effective, const kernel_cap_t *inheritable,
@@ -271,7 +272,7 @@ int security_binder_transfer_file(const struct cred *from, const struct cred *to, struct file *file);int security_ptrace_access_check (struct task_struct *child,unsigned int mode);int security_ptrace_traceme (struct task_struct *parent); -int security_capget (struct task_struct *target, +int security_capget (const struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted);
@@ -553,7 +554,7 @@ static inline int security_ptrace_traceme(struct task_struct *parent)return cap_ptrace_traceme (parent); } -static inline int security_capget (struct task_struct *target, +static inline int security_capget (const struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted)
kernel/capability.c +1 -1
@@ -112,7 +112,7 @@ static inline int cap_get_target_pid(pid_t pid, kernel_cap_t *pEp,int ret;if (pid && (pid !=task_pid_vnr (current))) { -struct task_struct *target; +const struct task_struct *target;rcu_read_lock ();
security/apparmor/lsm.c +1 -1
@@ -144,7 +144,7 @@ static int apparmor_ptrace_traceme(struct task_struct *parent) }/* Derived from security/commoncap.c:cap_capget */ -static int apparmor_capget (struct task_struct *target,kernel_cap_t *effective, +static int apparmor_capget (const struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted) {struct aa_label *label;
security/commoncap.c +1 -1
@@ -197,7 +197,7 @@ int cap_ptrace_traceme(struct task_struct *parent)* This function retrieves the capabilities of the nominated task and returns * them to the caller. */ -int cap_capget (struct task_struct *target,kernel_cap_t *effective, +int cap_capget (const struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted) {const struct cred *cred;
security/security.c +1 -1
@@ -893,7 +893,7 @@ int security_ptrace_traceme(struct task_struct *parent)* * Return: Returns 0 if the capability sets were successfully obtained. */ -int security_capget (struct task_struct *target, +int security_capget (const struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted)
security/selinux/hooks.c +1 -1
@@ -2056,7 +2056,7 @@ static int selinux_ptrace_traceme(struct task_struct *parent) SECCLASS_PROCESS, PROCESS__PTRACE, NULL); } -static int selinux_capget (struct task_struct *target,kernel_cap_t *effective, +static int selinux_capget (const struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted) { return avc_has_perm(current_sid(), task_sid_obj(target),
Signature · 1 line
2.34.1
Paul Moore
maintainerQuoted 11 lines · Khadija Kamran
Three LSMs register the implementations for the "capget" hook: AppArmor, SELinux, and the normal capability code. Looking at the function implementations we may observe that the first parameter "target" is not changing.
Mark the first argument "target" of LSM hook
security_capget()as "const" since it will not be changing in the LSM hook.
cap_capget()LSM hook declaration exceeds the 80 characters per line limit. Split the function declaration to multple lines to decrease the
"multiple" :)
Don't worry, I'll fix that in the merge.
There is one more nitpick below, but I think this looks good. I'll give this a few days to see if John can ACK the AppArmor bits, but if we don't hear from him by mid-week I'll plan to merge this.
Thanks!
Quoted 35 lines
line length.
Signed-off-by Khadija Kamran <[email protected]>---
Changes in v2:
- Squash the patches 1/2 and 2/2 into a single patch
- Simplify the commit messageinclude/linux/lsm_hook_defs.h | 2 +- include/linux/security.h | 7 ++++--- kernel/capability.c | 2 +- security/apparmor/lsm.c | 2 +- security/commoncap.c | 2 +- security/security.c | 2 +- security/selinux/hooks.c | 2 +- 7 files changed, 10 insertions(+), 9 deletions(-)include/linux/lsm_hook_defs.h +1
-1@@ -36,7 +36,7 @@ LSM_HOOK(int, 0, binder_transfer_file, const struct cred *from, LSM_HOOK(int, 0, ptrace_access_check, struct task_struct *child, unsigned int mode) LSM_HOOK(int, 0, ptrace_traceme, struct task_struct *parent) -LSM_HOOK(int, 0, capget, struct task_struct *target, kernel_cap_t *effective, +LSM_HOOK(int, 0, capget, const struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted) LSM_HOOK(int, 0, capset, struct cred *new, const struct cred *old, const kernel_cap_t *effective, const kernel_cap_t *inheritable,include/linux/security.h +0
-0
include/linux/security.h extern int cap_capable(const struct cred *cred, struct user_namespace *ns, · line 149
Quoted 6 lines
include/linux/security.h +2
-1@@ -145,7 +145,8 @@ extern int cap_capable(const struct cred *cred, struct user_namespace *ns,extern int cap_settime (const struct timespec64 *ts,const struct timezone *tz);extern int cap_ptrace_access_check (struct task_struct *child,unsigned int mode);extern int cap_ptrace_traceme (struct task_struct *parent); -extern int cap_capget (struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted); +extern int cap_capget (const struct task_struct *target,kernel_cap_t *effective, +kernel_cap_t *inheritable,kernel_cap_t *permitted);
Don't resubmit the patch just for this, I'll fix it during the merge, but generally nice to make sure the wrapped lines are aligned with the previous line; look at the security_cap_get() declaration (below) in this patch to see an example.
Quoted 88 lines
include/linux/security.h +2
-2extern int cap_capset(struct cred *new, const struct cred *old, const kernel_cap_t *effective, const kernel_cap_t *inheritable,@@ -271,7 +272,7 @@ int security_binder_transfer_file(const struct cred *from, const struct cred *to, struct file *file);int security_ptrace_access_check (struct task_struct *child,unsigned int mode);int security_ptrace_traceme (struct task_struct *parent); -int security_capget (struct task_struct *target, +int security_capget (const struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted);@@ -553,7 +554,7 @@ static inline int security_ptrace_traceme(struct task_struct *parent)return cap_ptrace_traceme (parent); } -static inline int security_capget (struct task_struct *target, +static inline int security_capget (const struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted)kernel/capability.c +1
-1@@ -112,7 +112,7 @@ static inline int cap_get_target_pid(pid_t pid, kernel_cap_t *pEp,int ret;if (pid && (pid !=task_pid_vnr (current))) { -struct task_struct *target; +const struct task_struct *target;rcu_read_lock ();security/apparmor/lsm.c +1
-1@@ -144,7 +144,7 @@ static int apparmor_ptrace_traceme(struct task_struct *parent) }/* Derived from security/commoncap.c:cap_capget */ -static int apparmor_capget (struct task_struct *target,kernel_cap_t *effective, +static int apparmor_capget (const struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted) {struct aa_label *label;security/commoncap.c +1
-1@@ -197,7 +197,7 @@ int cap_ptrace_traceme(struct task_struct *parent)* This function retrieves the capabilities of the nominated task and returns * them to the caller. */ -int cap_capget (struct task_struct *target,kernel_cap_t *effective, +int cap_capget (const struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted) {const struct cred *cred;security/security.c +1
-1@@ -893,7 +893,7 @@ int security_ptrace_traceme(struct task_struct *parent)* * Return: Returns 0 if the capability sets were successfully obtained. */ -int security_capget (struct task_struct *target, +int security_capget (const struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted)security/selinux/hooks.c +1
-2@@ -2056,7 +2056,7 @@ static int selinux_ptrace_traceme(struct task_struct *parent) SECCLASS_PROCESS, PROCESS__PTRACE, NULL); } -static int selinux_capget (struct task_struct *target,kernel_cap_t *effective, +static int selinux_capget (const struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted) { return avc_has_perm(current_sid(), task_sid_obj(target), --2.34.1
Signature · 1 line
paul-moore.com
Quoted 11 lines · Paul Moore
Quoted 5 lines · Khadija Kamran
cap_capget()LSM hook declaration exceeds the 80 characters per line limit. Split the function declaration to multple lines to decrease the"multiple" :)
Don't worry, I'll fix that in the merge.
Hey Paul,
Thank you. :)
Quoted 44 lines
There is one more nitpick below, but I think this looks good. I'll give this a few days to see if John can ACK the AppArmor bits, but if we don't hear from him by mid-week I'll plan to merge this.
Thanks!
Quoted 38 lines
line length.
Signed-off-by Khadija Kamran <[email protected]>---
Changes in v2:
- Squash the patches 1/2 and 2/2 into a single patch
- Simplify the commit messageinclude/linux/lsm_hook_defs.h | 2 +- include/linux/security.h | 7 ++++--- kernel/capability.c | 2 +- security/apparmor/lsm.c | 2 +- security/commoncap.c | 2 +- security/security.c | 2 +- security/selinux/hooks.c | 2 +- 7 files changed, 10 insertions(+), 9 deletions(-)include/linux/lsm_hook_defs.h +1
-1@@ -36,7 +36,7 @@ LSM_HOOK(int, 0, binder_transfer_file, const struct cred *from, LSM_HOOK(int, 0, ptrace_access_check, struct task_struct *child, unsigned int mode) LSM_HOOK(int, 0, ptrace_traceme, struct task_struct *parent) -LSM_HOOK(int, 0, capget, struct task_struct *target, kernel_cap_t *effective, +LSM_HOOK(int, 0, capget, const struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted) LSM_HOOK(int, 0, capset, struct cred *new, const struct cred *old, const kernel_cap_t *effective, const kernel_cap_t *inheritable,include/linux/security.h +0
-0@@ -145,7 +145,8 @@ extern int cap_capable(const struct cred *cred, struct user_namespace *ns,extern int cap_settime (const struct timespec64 *ts,const struct timezone *tz);extern int cap_ptrace_access_check (struct task_struct *child,unsigned int mode);extern int cap_ptrace_traceme (struct task_struct *parent);
Quoted 8 lines
include/linux/security.h extern int cap_capable(const struct cred *cred, struct user_namespace *ns, · line 149
Quoted 3 lines
include/linux/security.h +2
-1-extern int cap_capget (struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted); +extern int cap_capget (const struct task_struct *target,kernel_cap_t *effective, +kernel_cap_t *inheritable,kernel_cap_t *permitted);Don't resubmit the patch just for this, I'll fix it during the merge, but generally nice to make sure the wrapped lines are aligned with the previous line; look at the
security_cap_get()declaration (below) in this patch to see an example.
Okay noted.
Regards,
Khadija
Quoted 92 lines
Quoted 89 lines
include/linux/security.h +2
-2extern int cap_capset(struct cred *new, const struct cred *old, const kernel_cap_t *effective, const kernel_cap_t *inheritable,@@ -271,7 +272,7 @@ int security_binder_transfer_file(const struct cred *from, const struct cred *to, struct file *file);int security_ptrace_access_check (struct task_struct *child,unsigned int mode);int security_ptrace_traceme (struct task_struct *parent); -int security_capget (struct task_struct *target, +int security_capget (const struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted);@@ -553,7 +554,7 @@ static inline int security_ptrace_traceme(struct task_struct *parent)return cap_ptrace_traceme (parent); } -static inline int security_capget (struct task_struct *target, +static inline int security_capget (const struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted)kernel/capability.c +1
-1@@ -112,7 +112,7 @@ static inline int cap_get_target_pid(pid_t pid, kernel_cap_t *pEp,int ret;if (pid && (pid !=task_pid_vnr (current))) { -struct task_struct *target; +const struct task_struct *target;rcu_read_lock ();security/apparmor/lsm.c +1
-1@@ -144,7 +144,7 @@ static int apparmor_ptrace_traceme(struct task_struct *parent) }/* Derived from security/commoncap.c:cap_capget */ -static int apparmor_capget (struct task_struct *target,kernel_cap_t *effective, +static int apparmor_capget (const struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted) {struct aa_label *label;security/commoncap.c +1
-1@@ -197,7 +197,7 @@ int cap_ptrace_traceme(struct task_struct *parent)* This function retrieves the capabilities of the nominated task and returns * them to the caller. */ -int cap_capget (struct task_struct *target,kernel_cap_t *effective, +int cap_capget (const struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted) {const struct cred *cred;security/security.c +1
-1@@ -893,7 +893,7 @@ int security_ptrace_traceme(struct task_struct *parent)* * Return: Returns 0 if the capability sets were successfully obtained. */ -int security_capget (struct task_struct *target, +int security_capget (const struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted)security/selinux/hooks.c +1
-2@@ -2056,7 +2056,7 @@ static int selinux_ptrace_traceme(struct task_struct *parent) SECCLASS_PROCESS, PROCESS__PTRACE, NULL); } -static int selinux_capget (struct task_struct *target,kernel_cap_t *effective, +static int selinux_capget (const struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted) { return avc_has_perm(current_sid(), task_sid_obj(target), --2.34.1
Signature · 1 line
paul-moore.com
Paul Moore
maintainerQuoted 9 lines · Khadija Kamran
Quoted 7 lines · Paul Moore
Quoted 5 lines · Khadija Kamran
cap_capget()LSM hook declaration exceeds the 80 characters per line limit. Split the function declaration to multple lines to decrease the
Quoted 7 lines
Quoted 4 lines
"multiple" :)
Don't worry, I'll fix that in the merge.
Hey Paul,
Thank you. :)
... and now it's merged :)
Signature · 1 line
paul-moore.com
Quoted 5 lines · Khadija Kamran
Three LSMs register the implementations for the "capget" hook: AppArmor, SELinux, and the normal capability code. Looking at the function implementations we may observe that the first parameter "target" is not changing.
Quoted 8 lines
Mark the first argument "target" of LSM hook
security_capget()as "const" since it will not be changing in the LSM hook.
cap_capget()LSM hook declaration exceeds the 80 characters per line limit. Split the function declaration to multple lines to decrease the line length.Signed-off-by Khadija Kamran <[email protected]>
Quoted 124 lines
---
Changes in v2:
- Squash the patches 1/2 and 2/2 into a single patch
- Simplify the commit messageinclude/linux/lsm_hook_defs.h | 2 +- include/linux/security.h | 7 ++++--- kernel/capability.c | 2 +- security/apparmor/lsm.c | 2 +- security/commoncap.c | 2 +- security/security.c | 2 +- security/selinux/hooks.c | 2 +- 7 files changed, 10 insertions(+), 9 deletions(-)include/linux/lsm_hook_defs.h +1
-1@@ -36,7 +36,7 @@ LSM_HOOK(int, 0, binder_transfer_file, const struct cred *from, LSM_HOOK(int, 0, ptrace_access_check, struct task_struct *child, unsigned int mode) LSM_HOOK(int, 0, ptrace_traceme, struct task_struct *parent) -LSM_HOOK(int, 0, capget, struct task_struct *target, kernel_cap_t *effective, +LSM_HOOK(int, 0, capget, const struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted) LSM_HOOK(int, 0, capset, struct cred *new, const struct cred *old, const kernel_cap_t *effective, const kernel_cap_t *inheritable,include/linux/security.h +4
-3@@ -145,7 +145,8 @@ extern int cap_capable(const struct cred *cred, struct user_namespace *ns,extern int cap_settime (const struct timespec64 *ts,const struct timezone *tz);extern int cap_ptrace_access_check (struct task_struct *child,unsigned int mode);extern int cap_ptrace_traceme (struct task_struct *parent); -extern int cap_capget (struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted); +extern int cap_capget (const struct task_struct *target,kernel_cap_t *effective, +kernel_cap_t *inheritable,kernel_cap_t *permitted); extern int cap_capset(struct cred *new, const struct cred *old, const kernel_cap_t *effective, const kernel_cap_t *inheritable,@@ -271,7 +272,7 @@ int security_binder_transfer_file(const struct cred *from, const struct cred *to, struct file *file);int security_ptrace_access_check (struct task_struct *child,unsigned int mode);int security_ptrace_traceme (struct task_struct *parent); -int security_capget (struct task_struct *target, +int security_capget (const struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted);@@ -553,7 +554,7 @@ static inline int security_ptrace_traceme(struct task_struct *parent)return cap_ptrace_traceme (parent); } -static inline int security_capget (struct task_struct *target, +static inline int security_capget (const struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted)kernel/capability.c +1
-1@@ -112,7 +112,7 @@ static inline int cap_get_target_pid(pid_t pid, kernel_cap_t *pEp,int ret;if (pid && (pid !=task_pid_vnr (current))) { -struct task_struct *target; +const struct task_struct *target;rcu_read_lock ();security/apparmor/lsm.c +1
-1@@ -144,7 +144,7 @@ static int apparmor_ptrace_traceme(struct task_struct *parent) }/* Derived from security/commoncap.c:cap_capget */ -static int apparmor_capget (struct task_struct *target,kernel_cap_t *effective, +static int apparmor_capget (const struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted) {struct aa_label *label;security/commoncap.c +1
-1@@ -197,7 +197,7 @@ int cap_ptrace_traceme(struct task_struct *parent)* This function retrieves the capabilities of the nominated task and returns * them to the caller. */ -int cap_capget (struct task_struct *target,kernel_cap_t *effective, +int cap_capget (const struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted) {const struct cred *cred;security/security.c +1
-1@@ -893,7 +893,7 @@ int security_ptrace_traceme(struct task_struct *parent)* * Return: Returns 0 if the capability sets were successfully obtained. */ -int security_capget (struct task_struct *target, +int security_capget (const struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted)security/selinux/hooks.c +1
-1@@ -2056,7 +2056,7 @@ static int selinux_ptrace_traceme(struct task_struct *parent) SECCLASS_PROCESS, PROCESS__PTRACE, NULL); } -static int selinux_capget (struct task_struct *target,kernel_cap_t *effective, +static int selinux_capget (const struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted) { return avc_has_perm(current_sid(), task_sid_obj(target),