lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20091103165947.35bd78d7@bike.lwn.net>
Date:	Tue, 3 Nov 2009 16:59:47 -0700
From:	Jonathan Corbet <corbet@....net>
To:	Eric Paris <eparis@...hat.com>
Cc:	linux-kernel@...r.kernel.org, linus-fsdevel@...r.kernel.org,
	viro@...iv.linux.org.uk, hch@...radead.org, agruen@...e.de,
	eparis@...hat.com
Subject: Re: [PATCH 10/10] send events using read

Hi, Eric,

This is not a full review, but I did notice a problem as I was trying to
figure out the new API...

> +static ssize_t fanotify_read(struct file *file, char __user *buf,
> +			     size_t count, loff_t *pos)
> +{
> +	struct fsnotify_group *group;
> +	struct fsnotify_event *kevent;
> +	char __user *start;
> +	int ret;
> +	DEFINE_WAIT(wait);
> +
> +	start = buf;
> +	group = file->private_data;
> +
> +	pr_debug("%s: group=%p\n", __func__, group);
> +
> +	while (1) {
> +		prepare_to_wait(&group->notification_waitq, &wait, TASK_INTERRUPTIBLE);
> +
> +		mutex_lock(&group->notification_mutex);
> +		kevent = get_one_event(group, count);
> +		mutex_unlock(&group->notification_mutex);

prepare_to_wait(), among other things, sets the task state.  But then you
go into various sleeping calls (mutex_lock(), for starters); that will undo
what prepare_to_wait has done.  You'll be back in TASK_RUNNING at this
point, so you'll never sleep.

I've not looked at the code well enough to know how to fix it.  My guess is
that the sleeping on event availability should be done in get_one_event(),
or in a small wrapper which goes immediately around it.

> +
> +		if (kevent) {
> +			ret = PTR_ERR(kevent);
> +			if (IS_ERR(kevent))
> +				break;
> +			ret = copy_event_to_user(group, kevent, buf);
> +			fsnotify_put_event(kevent);
> +			if (ret < 0)
> +				break;
> +			buf += ret;
> +			count -= ret;
> +			continue;
> +		}
> +
> +		ret = -EAGAIN;
> +		if (file->f_flags & O_NONBLOCK)
> +			break;
> +		ret = -EINTR;
> +		if (signal_pending(current))
> +			break;
> +
> +		if (start != buf)
> +			break;

Alternatively, maybe you could do this here?

	        prepare_to_wait(...);
		if (fsnotify_notify_queue_is_empty(group))
			schedule()
> +
> +		schedule();

You also need finish_wait() here, not outside the loop.

> +	}
> +
> +	finish_wait(&group->notification_waitq, &wait);
> +	if (start != buf && ret != -EFAULT)
> +		ret = buf - start;
> +	return ret;
> +}

jon
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ