Skip to content

Commit e0b93ed

Browse files
author
Jeff Layton
committed
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>
1 parent 1c994a0 commit e0b93ed

12 files changed

Lines changed: 26 additions & 42 deletions

File tree

‎drivers/net/tun.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,9 +2152,7 @@ static int tun_chr_fasync(int fd, struct file *file, int on)
21522152
goto out;
21532153

21542154
if (on) {
2155-
ret = __f_setown(file, task_pid(current), PIDTYPE_PID, 0);
2156-
if (ret)
2157-
goto out;
2155+
__f_setown(file, task_pid(current), PIDTYPE_PID, 0);
21582156
tfile->flags |= TUN_FASYNC;
21592157
} else
21602158
tfile->flags &= ~TUN_FASYNC;

‎drivers/tty/tty_io.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2163,8 +2163,9 @@ static int __tty_fasync(int fd, struct file *filp, int on)
21632163
}
21642164
get_pid(pid);
21652165
spin_unlock_irqrestore(&tty->ctrl_lock, flags);
2166-
retval = __f_setown(filp, pid, type, 0);
2166+
__f_setown(filp, pid, type, 0);
21672167
put_pid(pid);
2168+
retval = 0;
21682169
}
21692170
out:
21702171
return retval;

‎fs/fcntl.c‎

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,36 +98,28 @@ static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
9898
write_unlock_irq(&filp->f_owner.lock);
9999
}
100100

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,
102102
int force)
103103
{
104-
int err;
105-
106-
err = security_file_set_fowner(filp);
107-
if (err)
108-
return err;
109-
104+
security_file_set_fowner(filp);
110105
f_modown(filp, pid, type, force);
111-
return 0;
112106
}
113107
EXPORT_SYMBOL(__f_setown);
114108

115-
int f_setown(struct file *filp, unsigned long arg, int force)
109+
void f_setown(struct file *filp, unsigned long arg, int force)
116110
{
117111
enum pid_type type;
118112
struct pid *pid;
119113
int who = arg;
120-
int result;
121114
type = PIDTYPE_PID;
122115
if (who < 0) {
123116
type = PIDTYPE_PGID;
124117
who = -who;
125118
}
126119
rcu_read_lock();
127120
pid = find_vpid(who);
128-
result = __f_setown(filp, pid, type, force);
121+
__f_setown(filp, pid, type, force);
129122
rcu_read_unlock();
130-
return result;
131123
}
132124
EXPORT_SYMBOL(f_setown);
133125

@@ -181,7 +173,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
181173
if (owner.pid && !pid)
182174
ret = -ESRCH;
183175
else
184-
ret = __f_setown(filp, pid, type, 1);
176+
__f_setown(filp, pid, type, 1);
185177
rcu_read_unlock();
186178

187179
return ret;
@@ -302,7 +294,8 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
302294
force_successful_syscall_return();
303295
break;
304296
case F_SETOWN:
305-
err = f_setown(filp, arg, 1);
297+
f_setown(filp, arg, 1);
298+
err = 0;
306299
break;
307300
case F_GETOWN_EX:
308301
err = f_getown_ex(filp, arg);

‎fs/locks.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1776,7 +1776,7 @@ static int do_fcntl_add_lease(unsigned int fd, struct file *filp, long arg)
17761776
if (!fasync_insert_entry(fd, filp, &ret->fl_fasync, new))
17771777
new = NULL;
17781778

1779-
error = __f_setown(filp, task_pid(current), PIDTYPE_PID, 0);
1779+
__f_setown(filp, task_pid(current), PIDTYPE_PID, 0);
17801780
out_unlock:
17811781
spin_unlock(&inode->i_lock);
17821782
if (fl)

‎fs/notify/dnotify/dnotify.c‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,7 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg)
346346
goto out;
347347
}
348348

349-
error = __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-
}
349+
__f_setown(filp, task_pid(current), PIDTYPE_PID, 0);
356350

357351
error = attach_dn(dn, dn_mark, id, fd, filp, mask);
358352
/* !error means that we attached the dn to the dn_mark, so don't free it */

‎include/linux/fs.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,8 +1139,8 @@ extern void fasync_free(struct fasync_struct *);
11391139
/* can be called from interrupts */
11401140
extern void kill_fasync(struct fasync_struct **, int, int);
11411141

1142-
extern int __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);
1142+
extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
1143+
extern void f_setown(struct file *filp, unsigned long arg, int force);
11441144
extern void f_delown(struct file *filp);
11451145
extern pid_t f_getown(struct file *filp);
11461146
extern int send_sigurg(struct fown_struct *fown);

‎include/linux/security.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,7 @@ struct security_operations {
15591559
int (*file_lock) (struct file *file, unsigned int cmd);
15601560
int (*file_fcntl) (struct file *file, unsigned int cmd,
15611561
unsigned long arg);
1562-
int (*file_set_fowner) (struct file *file);
1562+
void (*file_set_fowner) (struct file *file);
15631563
int (*file_send_sigiotask) (struct task_struct *tsk,
15641564
struct fown_struct *fown, int sig);
15651565
int (*file_receive) (struct file *file);
@@ -1834,7 +1834,7 @@ int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
18341834
unsigned long prot);
18351835
int security_file_lock(struct file *file, unsigned int cmd);
18361836
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);
18381838
int security_file_send_sigiotask(struct task_struct *tsk,
18391839
struct fown_struct *fown, int sig);
18401840
int security_file_receive(struct file *file);
@@ -2312,9 +2312,9 @@ static inline int security_file_fcntl(struct file *file, unsigned int cmd,
23122312
return 0;
23132313
}
23142314

2315-
static inline int security_file_set_fowner(struct file *file)
2315+
static inline void security_file_set_fowner(struct file *file)
23162316
{
2317-
return 0;
2317+
return;
23182318
}
23192319

23202320
static inline int security_file_send_sigiotask(struct task_struct *tsk,

‎net/socket.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,8 @@ static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg)
10691069
err = -EFAULT;
10701070
if (get_user(pid, (int __user *)argp))
10711071
break;
1072-
err = f_setown(sock->file, pid, 1);
1072+
f_setown(sock->file, pid, 1);
1073+
err = 0;
10731074
break;
10741075
case FIOGETOWN:
10751076
case SIOCGPGRP:

‎security/capability.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,9 @@ static int cap_file_fcntl(struct file *file, unsigned int cmd,
343343
return 0;
344344
}
345345

346-
static int cap_file_set_fowner(struct file *file)
346+
static void cap_file_set_fowner(struct file *file)
347347
{
348-
return 0;
348+
return;
349349
}
350350

351351
static int cap_file_send_sigiotask(struct task_struct *tsk,

‎security/security.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,9 +775,9 @@ int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
775775
return security_ops->file_fcntl(file, cmd, arg);
776776
}
777777

778-
int security_file_set_fowner(struct file *file)
778+
void security_file_set_fowner(struct file *file)
779779
{
780-
return security_ops->file_set_fowner(file);
780+
security_ops->file_set_fowner(file);
781781
}
782782

783783
int security_file_send_sigiotask(struct task_struct *tsk,

0 commit comments

Comments
 (0)