Skip to content

Commit 4a00c67

Browse files
KhadijaKamranpcmoore
authored andcommitted
lsm: constify 'file' parameter in security_bprm_creds_from_file()
The 'bprm_creds_from_file' hook has implementation registered in commoncap. Looking at the function implementation we observe that the 'file' parameter is not changing. Mark the 'file' parameter of LSM hook security_bprm_creds_from_file() as 'const' since it will not be changing in the LSM hook. Signed-off-by: Khadija Kamran <kamrankhadijadj@gmail.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 25cc71d commit 4a00c67

5 files changed

Lines changed: 8 additions & 8 deletions

File tree

include/linux/fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2450,7 +2450,7 @@ struct filename {
24502450
};
24512451
static_assert(offsetof(struct filename, iname) % sizeof(long) == 0);
24522452

2453-
static inline struct mnt_idmap *file_mnt_idmap(struct file *file)
2453+
static inline struct mnt_idmap *file_mnt_idmap(const struct file *file)
24542454
{
24552455
return mnt_idmap(file->f_path.mnt);
24562456
}

include/linux/lsm_hook_defs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ LSM_HOOK(int, 0, settime, const struct timespec64 *ts,
5050
const struct timezone *tz)
5151
LSM_HOOK(int, 0, vm_enough_memory, struct mm_struct *mm, long pages)
5252
LSM_HOOK(int, 0, bprm_creds_for_exec, struct linux_binprm *bprm)
53-
LSM_HOOK(int, 0, bprm_creds_from_file, struct linux_binprm *bprm, struct file *file)
53+
LSM_HOOK(int, 0, bprm_creds_from_file, struct linux_binprm *bprm, const struct file *file)
5454
LSM_HOOK(int, 0, bprm_check_security, struct linux_binprm *bprm)
5555
LSM_HOOK(void, LSM_RET_VOID, bprm_committing_creds, struct linux_binprm *bprm)
5656
LSM_HOOK(void, LSM_RET_VOID, bprm_committed_creds, struct linux_binprm *bprm)

include/linux/security.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ extern int cap_capset(struct cred *new, const struct cred *old,
151151
const kernel_cap_t *effective,
152152
const kernel_cap_t *inheritable,
153153
const kernel_cap_t *permitted);
154-
extern int cap_bprm_creds_from_file(struct linux_binprm *bprm, struct file *file);
154+
extern int cap_bprm_creds_from_file(struct linux_binprm *bprm, const struct file *file);
155155
int cap_inode_setxattr(struct dentry *dentry, const char *name,
156156
const void *value, size_t size, int flags);
157157
int cap_inode_removexattr(struct mnt_idmap *idmap,
@@ -290,7 +290,7 @@ int security_syslog(int type);
290290
int security_settime64(const struct timespec64 *ts, const struct timezone *tz);
291291
int security_vm_enough_memory_mm(struct mm_struct *mm, long pages);
292292
int security_bprm_creds_for_exec(struct linux_binprm *bprm);
293-
int security_bprm_creds_from_file(struct linux_binprm *bprm, struct file *file);
293+
int security_bprm_creds_from_file(struct linux_binprm *bprm, const struct file *file);
294294
int security_bprm_check(struct linux_binprm *bprm);
295295
void security_bprm_committing_creds(struct linux_binprm *bprm);
296296
void security_bprm_committed_creds(struct linux_binprm *bprm);
@@ -613,7 +613,7 @@ static inline int security_bprm_creds_for_exec(struct linux_binprm *bprm)
613613
}
614614

615615
static inline int security_bprm_creds_from_file(struct linux_binprm *bprm,
616-
struct file *file)
616+
const struct file *file)
617617
{
618618
return cap_bprm_creds_from_file(bprm, file);
619619
}

security/commoncap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ int get_vfs_caps_from_disk(struct mnt_idmap *idmap,
720720
* its xattrs and, if present, apply them to the proposed credentials being
721721
* constructed by execve().
722722
*/
723-
static int get_file_caps(struct linux_binprm *bprm, struct file *file,
723+
static int get_file_caps(struct linux_binprm *bprm, const struct file *file,
724724
bool *effective, bool *has_fcap)
725725
{
726726
int rc = 0;
@@ -882,7 +882,7 @@ static inline bool nonroot_raised_pE(struct cred *new, const struct cred *old,
882882
*
883883
* Return: 0 if successful, -ve on error.
884884
*/
885-
int cap_bprm_creds_from_file(struct linux_binprm *bprm, struct file *file)
885+
int cap_bprm_creds_from_file(struct linux_binprm *bprm, const struct file *file)
886886
{
887887
/* Process setpcap binaries and capabilities for uid 0 */
888888
const struct cred *old = current_cred();

security/security.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ int security_bprm_creds_for_exec(struct linux_binprm *bprm)
10791079
*
10801080
* Return: Returns 0 if the hook is successful and permission is granted.
10811081
*/
1082-
int security_bprm_creds_from_file(struct linux_binprm *bprm, struct file *file)
1082+
int security_bprm_creds_from_file(struct linux_binprm *bprm, const struct file *file)
10831083
{
10841084
return call_int_hook(bprm_creds_from_file, 0, bprm, file);
10851085
}

0 commit comments

Comments
 (0)