Skip to content

Commit

Permalink
security: make security_file_set_fowner, f_setown and __f_setown void…
Browse files Browse the repository at this point in the history
… return

security_file_set_fowner always returns 0, so make it f_setown and
__f_setown void return functions and fix up the error handling in the
callers.

Cc: [email protected]
Signed-off-by: Jeff Layton <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
  • Loading branch information
Jeff Layton committed Sep 9, 2014
1 parent 1c994a0 commit e0b93ed
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 42 deletions.
4 changes: 1 addition & 3 deletions drivers/net/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -2152,9 +2152,7 @@ static int tun_chr_fasync(int fd, struct file *file, int on)
goto out;

if (on) {
ret = __f_setown(file, task_pid(current), PIDTYPE_PID, 0);
if (ret)
goto out;
__f_setown(file, task_pid(current), PIDTYPE_PID, 0);
tfile->flags |= TUN_FASYNC;
} else
tfile->flags &= ~TUN_FASYNC;
Expand Down
3 changes: 2 additions & 1 deletion drivers/tty/tty_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2163,8 +2163,9 @@ static int __tty_fasync(int fd, struct file *filp, int on)
}
get_pid(pid);
spin_unlock_irqrestore(&tty->ctrl_lock, flags);
retval = __f_setown(filp, pid, type, 0);
__f_setown(filp, pid, type, 0);
put_pid(pid);
retval = 0;
}
out:
return retval;
Expand Down
21 changes: 7 additions & 14 deletions fs/fcntl.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,36 +98,28 @@ static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
write_unlock_irq(&filp->f_owner.lock);
}

int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
void __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
int force)
{
int err;

err = security_file_set_fowner(filp);
if (err)
return err;

security_file_set_fowner(filp);
f_modown(filp, pid, type, force);
return 0;
}
EXPORT_SYMBOL(__f_setown);

int f_setown(struct file *filp, unsigned long arg, int force)
void f_setown(struct file *filp, unsigned long arg, int force)
{
enum pid_type type;
struct pid *pid;
int who = arg;
int result;
type = PIDTYPE_PID;
if (who < 0) {
type = PIDTYPE_PGID;
who = -who;
}
rcu_read_lock();
pid = find_vpid(who);
result = __f_setown(filp, pid, type, force);
__f_setown(filp, pid, type, force);
rcu_read_unlock();
return result;
}
EXPORT_SYMBOL(f_setown);

Expand Down Expand Up @@ -181,7 +173,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
if (owner.pid && !pid)
ret = -ESRCH;
else
ret = __f_setown(filp, pid, type, 1);
__f_setown(filp, pid, type, 1);
rcu_read_unlock();

return ret;
Expand Down Expand Up @@ -302,7 +294,8 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
force_successful_syscall_return();
break;
case F_SETOWN:
err = f_setown(filp, arg, 1);
f_setown(filp, arg, 1);
err = 0;
break;
case F_GETOWN_EX:
err = f_getown_ex(filp, arg);
Expand Down
2 changes: 1 addition & 1 deletion fs/locks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1776,7 +1776,7 @@ static int do_fcntl_add_lease(unsigned int fd, struct file *filp, long arg)
if (!fasync_insert_entry(fd, filp, &ret->fl_fasync, new))
new = NULL;

error = __f_setown(filp, task_pid(current), PIDTYPE_PID, 0);
__f_setown(filp, task_pid(current), PIDTYPE_PID, 0);
out_unlock:
spin_unlock(&inode->i_lock);
if (fl)
Expand Down
8 changes: 1 addition & 7 deletions fs/notify/dnotify/dnotify.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,7 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg)
goto out;
}

error = __f_setown(filp, task_pid(current), PIDTYPE_PID, 0);
if (error) {
/* if we added, we must shoot */
if (dn_mark == new_dn_mark)
destroy = 1;
goto out;
}
__f_setown(filp, task_pid(current), PIDTYPE_PID, 0);

error = attach_dn(dn, dn_mark, id, fd, filp, mask);
/* !error means that we attached the dn to the dn_mark, so don't free it */
Expand Down
4 changes: 2 additions & 2 deletions include/linux/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1139,8 +1139,8 @@ extern void fasync_free(struct fasync_struct *);
/* can be called from interrupts */
extern void kill_fasync(struct fasync_struct **, int, int);

extern int __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
extern int f_setown(struct file *filp, unsigned long arg, int force);
extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
extern void f_setown(struct file *filp, unsigned long arg, int force);
extern void f_delown(struct file *filp);
extern pid_t f_getown(struct file *filp);
extern int send_sigurg(struct fown_struct *fown);
Expand Down
8 changes: 4 additions & 4 deletions include/linux/security.h
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,7 @@ struct security_operations {
int (*file_lock) (struct file *file, unsigned int cmd);
int (*file_fcntl) (struct file *file, unsigned int cmd,
unsigned long arg);
int (*file_set_fowner) (struct file *file);
void (*file_set_fowner) (struct file *file);
int (*file_send_sigiotask) (struct task_struct *tsk,
struct fown_struct *fown, int sig);
int (*file_receive) (struct file *file);
Expand Down Expand Up @@ -1834,7 +1834,7 @@ int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
unsigned long prot);
int security_file_lock(struct file *file, unsigned int cmd);
int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg);
int security_file_set_fowner(struct file *file);
void security_file_set_fowner(struct file *file);
int security_file_send_sigiotask(struct task_struct *tsk,
struct fown_struct *fown, int sig);
int security_file_receive(struct file *file);
Expand Down Expand Up @@ -2312,9 +2312,9 @@ static inline int security_file_fcntl(struct file *file, unsigned int cmd,
return 0;
}

static inline int security_file_set_fowner(struct file *file)
static inline void security_file_set_fowner(struct file *file)
{
return 0;
return;
}

static inline int security_file_send_sigiotask(struct task_struct *tsk,
Expand Down
3 changes: 2 additions & 1 deletion net/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,8 @@ static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg)
err = -EFAULT;
if (get_user(pid, (int __user *)argp))
break;
err = f_setown(sock->file, pid, 1);
f_setown(sock->file, pid, 1);
err = 0;
break;
case FIOGETOWN:
case SIOCGPGRP:
Expand Down
4 changes: 2 additions & 2 deletions security/capability.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ static int cap_file_fcntl(struct file *file, unsigned int cmd,
return 0;
}

static int cap_file_set_fowner(struct file *file)
static void cap_file_set_fowner(struct file *file)
{
return 0;
return;
}

static int cap_file_send_sigiotask(struct task_struct *tsk,
Expand Down
4 changes: 2 additions & 2 deletions security/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -775,9 +775,9 @@ int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
return security_ops->file_fcntl(file, cmd, arg);
}

int security_file_set_fowner(struct file *file)
void security_file_set_fowner(struct file *file)
{
return security_ops->file_set_fowner(file);
security_ops->file_set_fowner(file);
}

int security_file_send_sigiotask(struct task_struct *tsk,
Expand Down
4 changes: 1 addition & 3 deletions security/selinux/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -3346,14 +3346,12 @@ static int selinux_file_fcntl(struct file *file, unsigned int cmd,
return err;
}

static int selinux_file_set_fowner(struct file *file)
static void selinux_file_set_fowner(struct file *file)
{
struct file_security_struct *fsec;

fsec = file->f_security;
fsec->fown_sid = current_sid();

return 0;
}

static int selinux_file_send_sigiotask(struct task_struct *tsk,
Expand Down
3 changes: 1 addition & 2 deletions security/smack/smack_lsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1390,12 +1390,11 @@ static int smack_mmap_file(struct file *file,
* Returns 0
* Further research may be required on this one.
*/
static int smack_file_set_fowner(struct file *file)
static void smack_file_set_fowner(struct file *file)
{
struct smack_known *skp = smk_of_current();

file->f_security = skp->smk_known;
return 0;
}

/**
Expand Down

0 comments on commit e0b93ed

Please sign in to comment.