From: "Serge E. Hallyn" As suggested by Steve Beattie, rather than jump into a conditional block in certain cases, define and use a static inline bprm_clear_caps(). Signed-off-by: Serge E. Hallyn Acked-by: Andrew Morgan Cc: Chris Wright Cc: Stephen Smalley Cc: KaiGai Kohei Acked-by: James Morris Cc: Casey Schaufler Signed-off-by: Andrew Morton --- security/commoncap.c | 26 +++++++++++++++----------- 1 files changed, 15 insertions(+), 11 deletions(-) diff -puN security/commoncap.c~file-capabilities-clear-caps-cleanup security/commoncap.c --- a/security/commoncap.c~file-capabilities-clear-caps-cleanup +++ a/security/commoncap.c @@ -109,6 +109,13 @@ void cap_capset_set (struct task_struct target->cap_permitted = *permitted; } +static inline void bprm_clear_caps(struct linux_binprm *bprm) +{ + cap_clear (bprm->cap_inheritable); + cap_clear (bprm->cap_permitted); + cap_clear (bprm->cap_effective); +} + #ifdef CONFIG_SECURITY_FILE_CAPABILITIES static inline int cap_from_disk(struct vfs_cap_data_disk *dcap, @@ -144,8 +151,10 @@ static int get_file_caps(struct linux_bi struct inode *inode; dcaps = (struct vfs_cap_data_disk *)&v1caps; - if (bprm->file->f_vfsmnt->mnt_flags & MNT_NOSUID) - goto clear_caps; + if (bprm->file->f_vfsmnt->mnt_flags & MNT_NOSUID) { + bprm_clear_caps(bprm); + return 0; + } dentry = dget(bprm->file->f_dentry); inode = dentry->d_inode; @@ -186,21 +195,16 @@ out: dput(dentry); if ((void *)dcaps != (void *)&v1caps) kfree(dcaps); - if (rc) { -clear_caps: - cap_clear (bprm->cap_inheritable); - cap_clear (bprm->cap_permitted); - cap_clear (bprm->cap_effective); - } + if (rc) + bprm_clear_caps(bprm); + return rc; } #else static inline int get_file_caps(struct linux_binprm *bprm) { - cap_clear (bprm->cap_inheritable); - cap_clear (bprm->cap_permitted); - cap_clear (bprm->cap_effective); + bprm_clear_caps(bprm); return 0; } #endif _