Skip to content

Commit 6672efb

Browse files
KhadijaKamranpcmoore
authored andcommitted
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 multiple lines to decrease the line length. Signed-off-by: Khadija Kamran <kamrankhadijadj@gmail.com> Acked-by: John Johansen <john.johansen@canonical.com> [PM: align the cap_capget() declaration, spelling fixes] Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent bd1f593 commit 6672efb

7 files changed

Lines changed: 10 additions & 9 deletions

File tree

include/linux/lsm_hook_defs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ LSM_HOOK(int, 0, binder_transfer_file, const struct cred *from,
3636
LSM_HOOK(int, 0, ptrace_access_check, struct task_struct *child,
3737
unsigned int mode)
3838
LSM_HOOK(int, 0, ptrace_traceme, struct task_struct *parent)
39-
LSM_HOOK(int, 0, capget, struct task_struct *target, kernel_cap_t *effective,
39+
LSM_HOOK(int, 0, capget, const struct task_struct *target, kernel_cap_t *effective,
4040
kernel_cap_t *inheritable, kernel_cap_t *permitted)
4141
LSM_HOOK(int, 0, capset, struct cred *new, const struct cred *old,
4242
const kernel_cap_t *effective, const kernel_cap_t *inheritable,

include/linux/security.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ extern int cap_capable(const struct cred *cred, struct user_namespace *ns,
145145
extern int cap_settime(const struct timespec64 *ts, const struct timezone *tz);
146146
extern int cap_ptrace_access_check(struct task_struct *child, unsigned int mode);
147147
extern int cap_ptrace_traceme(struct task_struct *parent);
148-
extern int cap_capget(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted);
148+
extern int cap_capget(const struct task_struct *target, kernel_cap_t *effective,
149+
kernel_cap_t *inheritable, kernel_cap_t *permitted);
149150
extern int cap_capset(struct cred *new, const struct cred *old,
150151
const kernel_cap_t *effective,
151152
const kernel_cap_t *inheritable,
@@ -271,7 +272,7 @@ int security_binder_transfer_file(const struct cred *from,
271272
const struct cred *to, struct file *file);
272273
int security_ptrace_access_check(struct task_struct *child, unsigned int mode);
273274
int security_ptrace_traceme(struct task_struct *parent);
274-
int security_capget(struct task_struct *target,
275+
int security_capget(const struct task_struct *target,
275276
kernel_cap_t *effective,
276277
kernel_cap_t *inheritable,
277278
kernel_cap_t *permitted);
@@ -553,7 +554,7 @@ static inline int security_ptrace_traceme(struct task_struct *parent)
553554
return cap_ptrace_traceme(parent);
554555
}
555556

556-
static inline int security_capget(struct task_struct *target,
557+
static inline int security_capget(const struct task_struct *target,
557558
kernel_cap_t *effective,
558559
kernel_cap_t *inheritable,
559560
kernel_cap_t *permitted)

kernel/capability.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static inline int cap_get_target_pid(pid_t pid, kernel_cap_t *pEp,
112112
int ret;
113113

114114
if (pid && (pid != task_pid_vnr(current))) {
115-
struct task_struct *target;
115+
const struct task_struct *target;
116116

117117
rcu_read_lock();
118118

security/apparmor/lsm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ static int apparmor_ptrace_traceme(struct task_struct *parent)
144144
}
145145

146146
/* Derived from security/commoncap.c:cap_capget */
147-
static int apparmor_capget(struct task_struct *target, kernel_cap_t *effective,
147+
static int apparmor_capget(const struct task_struct *target, kernel_cap_t *effective,
148148
kernel_cap_t *inheritable, kernel_cap_t *permitted)
149149
{
150150
struct aa_label *label;

security/commoncap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ int cap_ptrace_traceme(struct task_struct *parent)
197197
* This function retrieves the capabilities of the nominated task and returns
198198
* them to the caller.
199199
*/
200-
int cap_capget(struct task_struct *target, kernel_cap_t *effective,
200+
int cap_capget(const struct task_struct *target, kernel_cap_t *effective,
201201
kernel_cap_t *inheritable, kernel_cap_t *permitted)
202202
{
203203
const struct cred *cred;

security/security.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ int security_ptrace_traceme(struct task_struct *parent)
894894
*
895895
* Return: Returns 0 if the capability sets were successfully obtained.
896896
*/
897-
int security_capget(struct task_struct *target,
897+
int security_capget(const struct task_struct *target,
898898
kernel_cap_t *effective,
899899
kernel_cap_t *inheritable,
900900
kernel_cap_t *permitted)

security/selinux/hooks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2082,7 +2082,7 @@ static int selinux_ptrace_traceme(struct task_struct *parent)
20822082
SECCLASS_PROCESS, PROCESS__PTRACE, NULL);
20832083
}
20842084

2085-
static int selinux_capget(struct task_struct *target, kernel_cap_t *effective,
2085+
static int selinux_capget(const struct task_struct *target, kernel_cap_t *effective,
20862086
kernel_cap_t *inheritable, kernel_cap_t *permitted)
20872087
{
20882088
return avc_has_perm(current_sid(), task_sid_obj(target),

0 commit comments

Comments
 (0)