Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f7312735 authored by Jeff Layton's avatar Jeff Layton
Browse files

fs/fcntl: return -ESRCH in f_setown when pid/pgid can't be found

The current implementation of F_SETOWN doesn't properly vet the argument
passed in and only returns an error if INT_MIN is passed in. If the
argument doesn't specify a valid pid/pgid, then we just end up cleaning
out the file->f_owner structure.

What we really want is to only clean that out only in the case where
userland passed in an argument of 0. For anything else, we want to
return ESRCH if it doesn't refer to a valid pid.

The relevant POSIX spec page is here:

    http://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html



Cc: Jiri Slaby <jslaby@suse.cz>
Cc: zhong jiang <zhongjiang@huawei.com>
Signed-off-by: default avatarJeff Layton <jlayton@redhat.com>
parent fc3dc674
Loading
Loading
Loading
Loading
+13 −5
Original line number Original line Diff line number Diff line
@@ -112,8 +112,9 @@ EXPORT_SYMBOL(__f_setown);
int f_setown(struct file *filp, unsigned long arg, int force)
int f_setown(struct file *filp, unsigned long arg, int force)
{
{
	enum pid_type type;
	enum pid_type type;
	struct pid *pid;
	struct pid *pid = NULL;
	int who = arg;
	int who = arg, ret = 0;

	type = PIDTYPE_PID;
	type = PIDTYPE_PID;
	if (who < 0) {
	if (who < 0) {
		/* avoid overflow below */
		/* avoid overflow below */
@@ -123,12 +124,19 @@ int f_setown(struct file *filp, unsigned long arg, int force)
		type = PIDTYPE_PGID;
		type = PIDTYPE_PGID;
		who = -who;
		who = -who;
	}
	}

	rcu_read_lock();
	rcu_read_lock();
	if (who) {
		pid = find_vpid(who);
		pid = find_vpid(who);
		if (!pid)
			ret = -ESRCH;
	}

	if (!ret)
		__f_setown(filp, pid, type, force);
		__f_setown(filp, pid, type, force);
	rcu_read_unlock();
	rcu_read_unlock();


	return 0;
	return ret;
}
}
EXPORT_SYMBOL(f_setown);
EXPORT_SYMBOL(f_setown);