Skip to content

Commit

Permalink
lsm: constify the 'file' parameter in security_binder_transfer_file()
Browse files Browse the repository at this point in the history
SELinux registers the implementation for the "binder_transfer_file"
hook. Looking at the function implementation we observe that the
parameter "file" is not changing.

Mark the "file" parameter of LSM hook security_binder_transfer_file() as
"const" since it will not be changing in the LSM hook.

Signed-off-by: Khadija Kamran <kamrankhadijadj@gmail.com>
[PM: subject line whitespace fix]
Signed-off-by: Paul Moore <paul@paul-moore.com>
  • Loading branch information
Khadija Kamran authored and Paul Moore committed Aug 15, 2023
1 parent 6672efb commit 8e4672d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion include/linux/lsm_hook_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ LSM_HOOK(int, 0, binder_transaction, const struct cred *from,
LSM_HOOK(int, 0, binder_transfer_binder, const struct cred *from,
const struct cred *to)
LSM_HOOK(int, 0, binder_transfer_file, const struct cred *from,
const struct cred *to, struct file *file)
const struct cred *to, const struct file *file)
LSM_HOOK(int, 0, ptrace_access_check, struct task_struct *child,
unsigned int mode)
LSM_HOOK(int, 0, ptrace_traceme, struct task_struct *parent)
Expand Down
4 changes: 2 additions & 2 deletions include/linux/security.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ int security_binder_transaction(const struct cred *from,
int security_binder_transfer_binder(const struct cred *from,
const struct cred *to);
int security_binder_transfer_file(const struct cred *from,
const struct cred *to, struct file *file);
const struct cred *to, const 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(const struct task_struct *target,
Expand Down Expand Up @@ -538,7 +538,7 @@ static inline int security_binder_transfer_binder(const struct cred *from,

static inline int security_binder_transfer_file(const struct cred *from,
const struct cred *to,
struct file *file)
const struct file *file)
{
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion security/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ int security_binder_transfer_binder(const struct cred *from,
* Return: Returns 0 if permission is granted.
*/
int security_binder_transfer_file(const struct cred *from,
const struct cred *to, struct file *file)
const struct cred *to, const struct file *file)
{
return call_int_hook(binder_transfer_file, 0, from, to, file);
}
Expand Down
8 changes: 4 additions & 4 deletions security/selinux/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1691,7 +1691,7 @@ static inline int file_path_has_perm(const struct cred *cred,
}

#ifdef CONFIG_BPF_SYSCALL
static int bpf_fd_pass(struct file *file, u32 sid);
static int bpf_fd_pass(const struct file *file, u32 sid);
#endif

/* Check whether a task can use an open file descriptor to
Expand Down Expand Up @@ -1952,7 +1952,7 @@ static inline u32 file_mask_to_av(int mode, int mask)
}

/* Convert a Linux file to an access vector. */
static inline u32 file_to_av(struct file *file)
static inline u32 file_to_av(const struct file *file)
{
u32 av = 0;

Expand Down Expand Up @@ -2027,7 +2027,7 @@ static int selinux_binder_transfer_binder(const struct cred *from,

static int selinux_binder_transfer_file(const struct cred *from,
const struct cred *to,
struct file *file)
const struct file *file)
{
u32 sid = cred_sid(to);
struct file_security_struct *fsec = selinux_file(file);
Expand Down Expand Up @@ -6718,7 +6718,7 @@ static u32 bpf_map_fmode_to_av(fmode_t fmode)
* access the bpf object and that's why we have to add this additional check in
* selinux_file_receive and selinux_binder_transfer_files.
*/
static int bpf_fd_pass(struct file *file, u32 sid)
static int bpf_fd_pass(const struct file *file, u32 sid)
{
struct bpf_security_struct *bpfsec;
struct bpf_prog *prog;
Expand Down

0 comments on commit 8e4672d

Please sign in to comment.