diff options
author | Jeff Layton <jlayton@primarydata.com> | 2014-08-22 11:27:32 -0400 |
---|---|---|
committer | Jeff Layton <jlayton@primarydata.com> | 2014-09-09 16:01:36 -0400 |
commit | e0b93eddfe17dcb7d644eb5d6ad02a86fc41a977 (patch) | |
tree | 97ceab83fdbfd3bf54fd8235a66da665fbcc83a7 | |
parent | 1c994a0909a556508c2cc26ab5d9e13c5ce33aa0 (diff) |
security: make security_file_set_fowner, f_setown and __f_setown void 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: linux-security-module@vger.kernel.org
Signed-off-by: Jeff Layton <jlayton@primarydata.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
-rw-r--r-- | drivers/net/tun.c | 4 | ||||
-rw-r--r-- | drivers/tty/tty_io.c | 3 | ||||
-rw-r--r-- | fs/fcntl.c | 21 | ||||
-rw-r--r-- | fs/locks.c | 2 | ||||
-rw-r--r-- | fs/notify/dnotify/dnotify.c | 8 | ||||
-rw-r--r-- | include/linux/fs.h | 4 | ||||
-rw-r--r-- | include/linux/security.h | 8 | ||||
-rw-r--r-- | net/socket.c | 3 | ||||
-rw-r--r-- | security/capability.c | 4 | ||||
-rw-r--r-- | security/security.c | 4 | ||||
-rw-r--r-- | security/selinux/hooks.c | 4 | ||||
-rw-r--r-- | security/smack/smack_lsm.c | 3 |
12 files changed, 26 insertions, 42 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c index acaaf6784179..186ce541c657 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c | |||
@@ -2152,9 +2152,7 @@ static int tun_chr_fasync(int fd, struct file *file, int on) | |||
2152 | goto out; | 2152 | goto out; |
2153 | 2153 | ||
2154 | if (on) { | 2154 | if (on) { |
2155 | ret = __f_setown(file, task_pid(current), PIDTYPE_PID, 0); | 2155 | __f_setown(file, task_pid(current), PIDTYPE_PID, 0); |
2156 | if (ret) | ||
2157 | goto out; | ||
2158 | tfile->flags |= TUN_FASYNC; | 2156 | tfile->flags |= TUN_FASYNC; |
2159 | } else | 2157 | } else |
2160 | tfile->flags &= ~TUN_FASYNC; | 2158 | tfile->flags &= ~TUN_FASYNC; |
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 8fbad3410c75..aea3b66f7bf2 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c | |||
@@ -2163,8 +2163,9 @@ static int __tty_fasync(int fd, struct file *filp, int on) | |||
2163 | } | 2163 | } |
2164 | get_pid(pid); | 2164 | get_pid(pid); |
2165 | spin_unlock_irqrestore(&tty->ctrl_lock, flags); | 2165 | spin_unlock_irqrestore(&tty->ctrl_lock, flags); |
2166 | retval = __f_setown(filp, pid, type, 0); | 2166 | __f_setown(filp, pid, type, 0); |
2167 | put_pid(pid); | 2167 | put_pid(pid); |
2168 | retval = 0; | ||
2168 | } | 2169 | } |
2169 | out: | 2170 | out: |
2170 | return retval; | 2171 | return retval; |
diff --git a/fs/fcntl.c b/fs/fcntl.c index 22d1c3df61ac..99d440a4a6ba 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c | |||
@@ -98,26 +98,19 @@ static void f_modown(struct file *filp, struct pid *pid, enum pid_type type, | |||
98 | write_unlock_irq(&filp->f_owner.lock); | 98 | write_unlock_irq(&filp->f_owner.lock); |
99 | } | 99 | } |
100 | 100 | ||
101 | int __f_setown(struct file *filp, struct pid *pid, enum pid_type type, | 101 | void __f_setown(struct file *filp, struct pid *pid, enum pid_type type, |
102 | int force) | 102 | int force) |
103 | { | 103 | { |
104 | int err; | 104 | security_file_set_fowner(filp); |
105 | |||
106 | err = security_file_set_fowner(filp); | ||
107 | if (err) | ||
108 | return err; | ||
109 | |||
110 | f_modown(filp, pid, type, force); | 105 | f_modown(filp, pid, type, force); |
111 | return 0; | ||
112 | } | 106 | } |
113 | EXPORT_SYMBOL(__f_setown); | 107 | EXPORT_SYMBOL(__f_setown); |
114 | 108 | ||
115 | int f_setown(struct file *filp, unsigned long arg, int force) | 109 | void f_setown(struct file *filp, unsigned long arg, int force) |
116 | { | 110 | { |
117 | enum pid_type type; | 111 | enum pid_type type; |
118 | struct pid *pid; | 112 | struct pid *pid; |
119 | int who = arg; | 113 | int who = arg; |
120 | int result; | ||
121 | type = PIDTYPE_PID; | 114 | type = PIDTYPE_PID; |
122 | if (who < 0) { | 115 | if (who < 0) { |
123 | type = PIDTYPE_PGID; | 116 | type = PIDTYPE_PGID; |
@@ -125,9 +118,8 @@ int f_setown(struct file *filp, unsigned long arg, int force) | |||
125 | } | 118 | } |
126 | rcu_read_lock(); | 119 | rcu_read_lock(); |
127 | pid = find_vpid(who); | 120 | pid = find_vpid(who); |
128 | result = __f_setown(filp, pid, type, force); | 121 | __f_setown(filp, pid, type, force); |
129 | rcu_read_unlock(); | 122 | rcu_read_unlock(); |
130 | return result; | ||
131 | } | 123 | } |
132 | EXPORT_SYMBOL(f_setown); | 124 | EXPORT_SYMBOL(f_setown); |
133 | 125 | ||
@@ -181,7 +173,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg) | |||
181 | if (owner.pid && !pid) | 173 | if (owner.pid && !pid) |
182 | ret = -ESRCH; | 174 | ret = -ESRCH; |
183 | else | 175 | else |
184 | ret = __f_setown(filp, pid, type, 1); | 176 | __f_setown(filp, pid, type, 1); |
185 | rcu_read_unlock(); | 177 | rcu_read_unlock(); |
186 | 178 | ||
187 | return ret; | 179 | return ret; |
@@ -302,7 +294,8 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg, | |||
302 | force_successful_syscall_return(); | 294 | force_successful_syscall_return(); |
303 | break; | 295 | break; |
304 | case F_SETOWN: | 296 | case F_SETOWN: |
305 | err = f_setown(filp, arg, 1); | 297 | f_setown(filp, arg, 1); |
298 | err = 0; | ||
306 | break; | 299 | break; |
307 | case F_GETOWN_EX: | 300 | case F_GETOWN_EX: |
308 | err = f_getown_ex(filp, arg); | 301 | err = f_getown_ex(filp, arg); |
diff --git a/fs/locks.c b/fs/locks.c index 5200ffd2ba9b..f5f648e003dd 100644 --- a/fs/locks.c +++ b/fs/locks.c | |||
@@ -1776,7 +1776,7 @@ static int do_fcntl_add_lease(unsigned int fd, struct file *filp, long arg) | |||
1776 | if (!fasync_insert_entry(fd, filp, &ret->fl_fasync, new)) | 1776 | if (!fasync_insert_entry(fd, filp, &ret->fl_fasync, new)) |
1777 | new = NULL; | 1777 | new = NULL; |
1778 | 1778 | ||
1779 | error = __f_setown(filp, task_pid(current), PIDTYPE_PID, 0); | 1779 | __f_setown(filp, task_pid(current), PIDTYPE_PID, 0); |
1780 | out_unlock: | 1780 | out_unlock: |
1781 | spin_unlock(&inode->i_lock); | 1781 | spin_unlock(&inode->i_lock); |
1782 | if (fl) | 1782 | if (fl) |
diff --git a/fs/notify/dnotify/dnotify.c b/fs/notify/dnotify/dnotify.c index abc8cbcfe90e..caaaf9dfe353 100644 --- a/fs/notify/dnotify/dnotify.c +++ b/fs/notify/dnotify/dnotify.c | |||
@@ -346,13 +346,7 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg) | |||
346 | goto out; | 346 | goto out; |
347 | } | 347 | } |
348 | 348 | ||
349 | error = __f_setown(filp, task_pid(current), PIDTYPE_PID, 0); | 349 | __f_setown(filp, task_pid(current), PIDTYPE_PID, 0); |
350 | if (error) { | ||
351 | /* if we added, we must shoot */ | ||
352 | if (dn_mark == new_dn_mark) | ||
353 | destroy = 1; | ||
354 | goto out; | ||
355 | } | ||
356 | 350 | ||
357 | error = attach_dn(dn, dn_mark, id, fd, filp, mask); | 351 | error = attach_dn(dn, dn_mark, id, fd, filp, mask); |
358 | /* !error means that we attached the dn to the dn_mark, so don't free it */ | 352 | /* !error means that we attached the dn to the dn_mark, so don't free it */ |
diff --git a/include/linux/fs.h b/include/linux/fs.h index 435e3d9ec5cf..96528f73dda4 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h | |||
@@ -1139,8 +1139,8 @@ extern void fasync_free(struct fasync_struct *); | |||
1139 | /* can be called from interrupts */ | 1139 | /* can be called from interrupts */ |
1140 | extern void kill_fasync(struct fasync_struct **, int, int); | 1140 | extern void kill_fasync(struct fasync_struct **, int, int); |
1141 | 1141 | ||
1142 | extern int __f_setown(struct file *filp, struct pid *, enum pid_type, int force); | 1142 | extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force); |
1143 | extern int f_setown(struct file *filp, unsigned long arg, int force); | 1143 | extern void f_setown(struct file *filp, unsigned long arg, int force); |
1144 | extern void f_delown(struct file *filp); | 1144 | extern void f_delown(struct file *filp); |
1145 | extern pid_t f_getown(struct file *filp); | 1145 | extern pid_t f_getown(struct file *filp); |
1146 | extern int send_sigurg(struct fown_struct *fown); | 1146 | extern int send_sigurg(struct fown_struct *fown); |
diff --git a/include/linux/security.h b/include/linux/security.h index 623f90e5f38d..b10e7af95d3b 100644 --- a/include/linux/security.h +++ b/include/linux/security.h | |||
@@ -1559,7 +1559,7 @@ struct security_operations { | |||
1559 | int (*file_lock) (struct file *file, unsigned int cmd); | 1559 | int (*file_lock) (struct file *file, unsigned int cmd); |
1560 | int (*file_fcntl) (struct file *file, unsigned int cmd, | 1560 | int (*file_fcntl) (struct file *file, unsigned int cmd, |
1561 | unsigned long arg); | 1561 | unsigned long arg); |
1562 | int (*file_set_fowner) (struct file *file); | 1562 | void (*file_set_fowner) (struct file *file); |
1563 | int (*file_send_sigiotask) (struct task_struct *tsk, | 1563 | int (*file_send_sigiotask) (struct task_struct *tsk, |
1564 | struct fown_struct *fown, int sig); | 1564 | struct fown_struct *fown, int sig); |
1565 | int (*file_receive) (struct file *file); | 1565 | int (*file_receive) (struct file *file); |
@@ -1834,7 +1834,7 @@ int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot, | |||
1834 | unsigned long prot); | 1834 | unsigned long prot); |
1835 | int security_file_lock(struct file *file, unsigned int cmd); | 1835 | int security_file_lock(struct file *file, unsigned int cmd); |
1836 | int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg); | 1836 | int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg); |
1837 | int security_file_set_fowner(struct file *file); | 1837 | void security_file_set_fowner(struct file *file); |
1838 | int security_file_send_sigiotask(struct task_struct *tsk, | 1838 | int security_file_send_sigiotask(struct task_struct *tsk, |
1839 | struct fown_struct *fown, int sig); | 1839 | struct fown_struct *fown, int sig); |
1840 | int security_file_receive(struct file *file); | 1840 | int security_file_receive(struct file *file); |
@@ -2312,9 +2312,9 @@ static inline int security_file_fcntl(struct file *file, unsigned int cmd, | |||
2312 | return 0; | 2312 | return 0; |
2313 | } | 2313 | } |
2314 | 2314 | ||
2315 | static inline int security_file_set_fowner(struct file *file) | 2315 | static inline void security_file_set_fowner(struct file *file) |
2316 | { | 2316 | { |
2317 | return 0; | 2317 | return; |
2318 | } | 2318 | } |
2319 | 2319 | ||
2320 | static inline int security_file_send_sigiotask(struct task_struct *tsk, | 2320 | static inline int security_file_send_sigiotask(struct task_struct *tsk, |
diff --git a/net/socket.c b/net/socket.c index 95ee7d8682e7..769c9671847e 100644 --- a/net/socket.c +++ b/net/socket.c | |||
@@ -1069,7 +1069,8 @@ static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg) | |||
1069 | err = -EFAULT; | 1069 | err = -EFAULT; |
1070 | if (get_user(pid, (int __user *)argp)) | 1070 | if (get_user(pid, (int __user *)argp)) |
1071 | break; | 1071 | break; |
1072 | err = f_setown(sock->file, pid, 1); | 1072 | f_setown(sock->file, pid, 1); |
1073 | err = 0; | ||
1073 | break; | 1074 | break; |
1074 | case FIOGETOWN: | 1075 | case FIOGETOWN: |
1075 | case SIOCGPGRP: | 1076 | case SIOCGPGRP: |
diff --git a/security/capability.c b/security/capability.c index a74fde6a7468..d68c57a62bcf 100644 --- a/security/capability.c +++ b/security/capability.c | |||
@@ -343,9 +343,9 @@ static int cap_file_fcntl(struct file *file, unsigned int cmd, | |||
343 | return 0; | 343 | return 0; |
344 | } | 344 | } |
345 | 345 | ||
346 | static int cap_file_set_fowner(struct file *file) | 346 | static void cap_file_set_fowner(struct file *file) |
347 | { | 347 | { |
348 | return 0; | 348 | return; |
349 | } | 349 | } |
350 | 350 | ||
351 | static int cap_file_send_sigiotask(struct task_struct *tsk, | 351 | static int cap_file_send_sigiotask(struct task_struct *tsk, |
diff --git a/security/security.c b/security/security.c index e41b1a8d7644..18b35c63fc0c 100644 --- a/security/security.c +++ b/security/security.c | |||
@@ -775,9 +775,9 @@ int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg) | |||
775 | return security_ops->file_fcntl(file, cmd, arg); | 775 | return security_ops->file_fcntl(file, cmd, arg); |
776 | } | 776 | } |
777 | 777 | ||
778 | int security_file_set_fowner(struct file *file) | 778 | void security_file_set_fowner(struct file *file) |
779 | { | 779 | { |
780 | return security_ops->file_set_fowner(file); | 780 | security_ops->file_set_fowner(file); |
781 | } | 781 | } |
782 | 782 | ||
783 | int security_file_send_sigiotask(struct task_struct *tsk, | 783 | int security_file_send_sigiotask(struct task_struct *tsk, |
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index b0e940497e23..ada0d0bf3463 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c | |||
@@ -3346,14 +3346,12 @@ static int selinux_file_fcntl(struct file *file, unsigned int cmd, | |||
3346 | return err; | 3346 | return err; |
3347 | } | 3347 | } |
3348 | 3348 | ||
3349 | static int selinux_file_set_fowner(struct file *file) | 3349 | static void selinux_file_set_fowner(struct file *file) |
3350 | { | 3350 | { |
3351 | struct file_security_struct *fsec; | 3351 | struct file_security_struct *fsec; |
3352 | 3352 | ||
3353 | fsec = file->f_security; | 3353 | fsec = file->f_security; |
3354 | fsec->fown_sid = current_sid(); | 3354 | fsec->fown_sid = current_sid(); |
3355 | |||
3356 | return 0; | ||
3357 | } | 3355 | } |
3358 | 3356 | ||
3359 | static int selinux_file_send_sigiotask(struct task_struct *tsk, | 3357 | static int selinux_file_send_sigiotask(struct task_struct *tsk, |
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index e6ab307ce86e..69e5635d89e5 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c | |||
@@ -1390,12 +1390,11 @@ static int smack_mmap_file(struct file *file, | |||
1390 | * Returns 0 | 1390 | * Returns 0 |
1391 | * Further research may be required on this one. | 1391 | * Further research may be required on this one. |
1392 | */ | 1392 | */ |
1393 | static int smack_file_set_fowner(struct file *file) | 1393 | static void smack_file_set_fowner(struct file *file) |
1394 | { | 1394 | { |
1395 | struct smack_known *skp = smk_of_current(); | 1395 | struct smack_known *skp = smk_of_current(); |
1396 | 1396 | ||
1397 | file->f_security = skp->smk_known; | 1397 | file->f_security = skp->smk_known; |
1398 | return 0; | ||
1399 | } | 1398 | } |
1400 | 1399 | ||
1401 | /** | 1400 | /** |