<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/fs/eventpoll.c, branch linux-4.4.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.4.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.4.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2020-10-14T07:46:21Z</updated>
<entry>
<title>ep_create_wakeup_source(): dentry name can change under you...</title>
<updated>2020-10-14T07:46:21Z</updated>
<author>
<name>Al Viro</name>
</author>
<published>2020-09-24T23:41:58Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=97f8be925b061241196e78c68455914e04dc2a4b'/>
<id>urn:sha1:97f8be925b061241196e78c68455914e04dc2a4b</id>
<content type='text'>
commit 3701cb59d892b88d569427586f01491552f377b1 upstream.

or get freed, for that matter, if it's a long (separately stored)
name.

Signed-off-by: Al Viro &lt;viro@zeniv.linux.org.uk&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>epoll: EPOLL_CTL_ADD: close the race in decision to take fast path</title>
<updated>2020-10-14T07:46:21Z</updated>
<author>
<name>Al Viro</name>
</author>
<published>2020-09-10T12:33:27Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=199140bc63cd00533f1d04ce9ae72a21123530ec'/>
<id>urn:sha1:199140bc63cd00533f1d04ce9ae72a21123530ec</id>
<content type='text'>
commit fe0a916c1eae8e17e86c3753d13919177d63ed7e upstream.

Checking for the lack of epitems refering to the epoll we want to insert into
is not enough; we might have an insertion of that epoll into another one that
has already collected the set of files to recheck for excessive reverse paths,
but hasn't gotten to creating/inserting the epitem for it.

However, any such insertion in progress can be detected - it will update the
generation count in our epoll when it's done looking through it for files
to check.  That gets done under -&gt;mtx of our epoll and that allows us to
detect that safely.

We are *not* holding epmutex here, so the generation count is not stable.
However, since both the update of ep-&gt;gen by loop check and (later)
insertion into -&gt;f_ep_link are done with ep-&gt;mtx held, we are fine -
the sequence is
	grab epmutex
	bump loop_check_gen
	...
	grab tep-&gt;mtx		// 1
	tep-&gt;gen = loop_check_gen
	...
	drop tep-&gt;mtx		// 2
	...
	grab tep-&gt;mtx		// 3
	...
	insert into -&gt;f_ep_link
	...
	drop tep-&gt;mtx		// 4
	bump loop_check_gen
	drop epmutex
and if the fastpath check in another thread happens for that
eventpoll, it can come
	* before (1) - in that case fastpath is just fine
	* after (4) - we'll see non-empty -&gt;f_ep_link, slow path
taken
	* between (2) and (3) - loop_check_gen is stable,
with -&gt;mtx providing barriers and we end up taking slow path.

Note that -&gt;f_ep_link emptiness check is slightly racy - we are protected
against insertions into that list, but removals can happen right under us.
Not a problem - in the worst case we'll end up taking a slow path for
no good reason.

Signed-off-by: Al Viro &lt;viro@zeniv.linux.org.uk&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>epoll: replace -&gt;visited/visited_list with generation count</title>
<updated>2020-10-14T07:46:21Z</updated>
<author>
<name>Al Viro</name>
</author>
<published>2020-09-10T12:30:05Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=648bffab761667d1d1ddb5dbb7585e250ddd49b9'/>
<id>urn:sha1:648bffab761667d1d1ddb5dbb7585e250ddd49b9</id>
<content type='text'>
commit 18306c404abe18a0972587a6266830583c60c928 upstream.

removes the need to clear it, along with the races.

Signed-off-by: Al Viro &lt;viro@zeniv.linux.org.uk&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>epoll: do not insert into poll queues until all sanity checks are done</title>
<updated>2020-10-14T07:46:20Z</updated>
<author>
<name>Al Viro</name>
</author>
<published>2020-09-10T02:25:06Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=ea984dfe0e7978cd294eb6a640ac27fa1834ac8d'/>
<id>urn:sha1:ea984dfe0e7978cd294eb6a640ac27fa1834ac8d</id>
<content type='text'>
commit f8d4f44df056c5b504b0d49683fb7279218fd207 upstream.

Signed-off-by: Al Viro &lt;viro@zeniv.linux.org.uk&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>fix regression in "epoll: Keep a reference on files added to the check list"</title>
<updated>2020-09-12T09:45:28Z</updated>
<author>
<name>Al Viro</name>
</author>
<published>2020-09-02T15:30:48Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=6504c100804870911f074fd67f280756b6805958'/>
<id>urn:sha1:6504c100804870911f074fd67f280756b6805958</id>
<content type='text'>
[ Upstream commit 77f4689de17c0887775bb77896f4cc11a39bf848 ]

epoll_loop_check_proc() can run into a file already committed to destruction;
we can't grab a reference on those and don't need to add them to the set for
reverse path check anyway.

Tested-by: Marc Zyngier &lt;maz@kernel.org&gt;
Fixes: a9ed4a6560b8 ("epoll: Keep a reference on files added to the check list")
Signed-off-by: Al Viro &lt;viro@zeniv.linux.org.uk&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>do_epoll_ctl(): clean the failure exits up a bit</title>
<updated>2020-08-26T08:27:10Z</updated>
<author>
<name>Al Viro</name>
</author>
<published>2020-08-22T22:25:52Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=d85e2b06662e7f46d0f174ecc603fc1c3554d5cf'/>
<id>urn:sha1:d85e2b06662e7f46d0f174ecc603fc1c3554d5cf</id>
<content type='text'>
commit 52c479697c9b73f628140dcdfcd39ea302d05482 upstream.

Signed-off-by: Al Viro &lt;viro@zeniv.linux.org.uk&gt;
Signed-off-by: Marc Zyngier &lt;maz@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>epoll: Keep a reference on files added to the check list</title>
<updated>2020-08-26T08:27:10Z</updated>
<author>
<name>Marc Zyngier</name>
</author>
<published>2020-08-19T16:12:17Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=89077f38db728c980dd0cc776400dff5c645f627'/>
<id>urn:sha1:89077f38db728c980dd0cc776400dff5c645f627</id>
<content type='text'>
commit a9ed4a6560b8562b7e2e2bed9527e88001f7b682 upstream.

When adding a new fd to an epoll, and that this new fd is an
epoll fd itself, we recursively scan the fds attached to it
to detect cycles, and add non-epool files to a "check list"
that gets subsequently parsed.

However, this check list isn't completely safe when deletions
can happen concurrently. To sidestep the issue, make sure that
a struct file placed on the check list sees its f_count increased,
ensuring that a concurrent deletion won't result in the file
disapearing from under our feet.

Cc: stable@vger.kernel.org
Signed-off-by: Marc Zyngier &lt;maz@kernel.org&gt;
Signed-off-by: Al Viro &lt;viro@zeniv.linux.org.uk&gt;
Signed-off-by: Marc Zyngier &lt;maz@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>fs/epoll: drop ovflist branch prediction</title>
<updated>2019-02-20T09:13:14Z</updated>
<author>
<name>Davidlohr Bueso</name>
</author>
<published>2019-01-03T23:27:09Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=e1d575b52c32b40184c1d1ca6039e8c7d3ce2db7'/>
<id>urn:sha1:e1d575b52c32b40184c1d1ca6039e8c7d3ce2db7</id>
<content type='text'>
[ Upstream commit 76699a67f3041ff4c7af6d6ee9be2bfbf1ffb671 ]

The ep-&gt;ovflist is a secondary ready-list to temporarily store events
that might occur when doing sproc without holding the ep-&gt;wq.lock.  This
accounts for every time we check for ready events and also send events
back to userspace; both callbacks, particularly the latter because of
copy_to_user, can account for a non-trivial time.

As such, the unlikely() check to see if the pointer is being used, seems
both misleading and sub-optimal.  In fact, we go to an awful lot of
trouble to sync both lists, and populating the ovflist is far from an
uncommon scenario.

For example, profiling a concurrent epoll_wait(2) benchmark, with
CONFIG_PROFILE_ANNOTATED_BRANCHES shows that for a two threads a 33%
incorrect rate was seen; and when incrementally increasing the number of
epoll instances (which is used, for example for multiple queuing load
balancing models), up to a 90% incorrect rate was seen.

Similarly, by deleting the prediction, 3% throughput boost was seen
across incremental threads.

Link: http://lkml.kernel.org/r/20181108051006.18751-4-dave@stgolabs.net
Signed-off-by: Davidlohr Bueso &lt;dbueso@suse.de&gt;
Reviewed-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Cc: Al Viro &lt;viro@zeniv.linux.org.uk&gt;
Cc: Jason Baron &lt;jbaron@akamai.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>epoll: fix race between ep_poll_callback(POLLFREE) and ep_free()/ep_remove()</title>
<updated>2017-09-07T06:34:10Z</updated>
<author>
<name>Oleg Nesterov</name>
</author>
<published>2017-09-01T16:55:33Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=ab3ee6b53d678b37b90934fb67b01d5fc7aa3a85'/>
<id>urn:sha1:ab3ee6b53d678b37b90934fb67b01d5fc7aa3a85</id>
<content type='text'>
commit 138e4ad67afd5c6c318b056b4d17c17f2c0ca5c0 upstream.

The race was introduced by me in commit 971316f0503a ("epoll:
ep_unregister_pollwait() can use the freed pwq-&gt;whead").  I did not
realize that nothing can protect eventpoll after ep_poll_callback() sets
-&gt;whead = NULL, only whead-&gt;lock can save us from the race with
ep_free() or ep_remove().

Move -&gt;whead = NULL to the end of ep_poll_callback() and add the
necessary barriers.

TODO: cleanup the ewake/EPOLLEXCLUSIVE logic, it was confusing even
before this patch.

Hopefully this explains use-after-free reported by syzcaller:

	BUG: KASAN: use-after-free in debug_spin_lock_before
	...
	 _raw_spin_lock_irqsave+0x4a/0x60 kernel/locking/spinlock.c:159
	 ep_poll_callback+0x29f/0xff0 fs/eventpoll.c:1148

this is spin_lock(eventpoll-&gt;lock),

	...
	Freed by task 17774:
	...
	 kfree+0xe8/0x2c0 mm/slub.c:3883
	 ep_free+0x22c/0x2a0 fs/eventpoll.c:865

Fixes: 971316f0503a ("epoll: ep_unregister_pollwait() can use the freed pwq-&gt;whead")
Reported-by: 范龙飞 &lt;long7573@126.com&gt;
Signed-off-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;


</content>
</entry>
<entry>
<title>epoll: optimize setting task running after blocking</title>
<updated>2015-02-14T05:21:40Z</updated>
<author>
<name>Davidlohr Bueso</name>
</author>
<published>2015-02-13T22:39:08Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=4d5755b147665912c938504033d958f1115b68ff'/>
<id>urn:sha1:4d5755b147665912c938504033d958f1115b68ff</id>
<content type='text'>
After waking up a task waiting for an event, we explicitly mark it as
TASK_RUNNING (which is necessary as we do the checks for wakeups as
TASK_INTERRUPTIBLE).  Once running and dealing with actually delivering
the events, we're obviously not planning on calling schedule, thus we can
relax the implied barrier and simply update the state with
__set_current_state().

Signed-off-by: Davidlohr Bueso &lt;dbueso@suse.de&gt;
Cc: Alexander Viro &lt;viro@zeniv.linux.org.uk&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
</feed>
