<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/net/rds/connection.c, branch linux-4.16.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.16.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.16.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2018-02-13T18:52:02Z</updated>
<entry>
<title>rds: do not call -&gt;conn_alloc with GFP_KERNEL</title>
<updated>2018-02-13T18:52:02Z</updated>
<author>
<name>Sowmini Varadhan</name>
</author>
<published>2018-02-13T17:46:16Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=d4014d8cc6dfa964e3e66df525de2384e3583018'/>
<id>urn:sha1:d4014d8cc6dfa964e3e66df525de2384e3583018</id>
<content type='text'>
Commit ebeeb1ad9b8a ("rds: tcp: use rds_destroy_pending() to synchronize
netns/module teardown and rds connection/workq management")
adds an rcu read critical section to __rd_conn_create. The
memory allocations in that critcal section need to use
GFP_ATOMIC to avoid sleeping.

This patch was verified with syzkaller reproducer.

Reported-by: syzbot+a0564419941aaae3fe3c@syzkaller.appspotmail.com
Fixes: ebeeb1ad9b8a ("rds: tcp: use rds_destroy_pending() to synchronize
       netns/module teardown and rds connection/workq management")
Signed-off-by: Sowmini Varadhan &lt;sowmini.varadhan@oracle.com&gt;
Acked-by: Santosh Shilimkar &lt;santosh.shilimkar@oracle.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>rds: tcp: use rds_destroy_pending() to synchronize netns/module teardown and rds connection/workq management</title>
<updated>2018-02-08T20:23:52Z</updated>
<author>
<name>Sowmini Varadhan</name>
</author>
<published>2018-02-03T12:26:51Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=ebeeb1ad9b8adcc37c2ec21a96f39e9d35199b46'/>
<id>urn:sha1:ebeeb1ad9b8adcc37c2ec21a96f39e9d35199b46</id>
<content type='text'>
An rds_connection can get added during netns deletion between lines 528
and 529 of

  506 static void rds_tcp_kill_sock(struct net *net)
  :
  /* code to pull out all the rds_connections that should be destroyed */
  :
  528         spin_unlock_irq(&amp;rds_tcp_conn_lock);
  529         list_for_each_entry_safe(tc, _tc, &amp;tmp_list, t_tcp_node)
  530                 rds_conn_destroy(tc-&gt;t_cpath-&gt;cp_conn);

Such an rds_connection would miss out the rds_conn_destroy()
loop (that cancels all pending work) and (if it was scheduled
after netns deletion) could trigger the use-after-free.

A similar race-window exists for the module unload path
in rds_tcp_exit -&gt; rds_tcp_destroy_conns

Concurrency with netns deletion (rds_tcp_kill_sock()) must be handled
by checking check_net() before enqueuing new work or adding new
connections.

Concurrency with module-unload is handled by maintaining a module
specific flag that is set at the start of the module exit function,
and must be checked before enqueuing new work or adding new connections.

This commit refactors existing RDS_DESTROY_PENDING checks added by
commit 3db6e0d172c9 ("rds: use RCU to synchronize work-enqueue with
connection teardown") and consolidates all the concurrency checks
listed above into the function rds_destroy_pending().

Signed-off-by: Sowmini Varadhan &lt;sowmini.varadhan@oracle.com&gt;
Acked-by: Santosh Shilimkar &lt;santosh.shilimkar@oracle.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>rds: use RCU to synchronize work-enqueue with connection teardown</title>
<updated>2018-01-05T18:39:18Z</updated>
<author>
<name>Sowmini Varadhan</name>
</author>
<published>2018-01-04T14:53:00Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=3db6e0d172c94bd9953a1347c55ffb64b1d2e74f'/>
<id>urn:sha1:3db6e0d172c94bd9953a1347c55ffb64b1d2e74f</id>
<content type='text'>
rds_sendmsg() can enqueue work on cp_send_w from process context, but
it should not enqueue this work if connection teardown  has commenced
(else we risk enquing work after rds_conn_path_destroy() has assumed that
all work has been cancelled/flushed).

Similarly some other functions like rds_cong_queue_updates
and rds_tcp_data_ready are called in softirq context, and may end
up enqueuing work on rds_wq after rds_conn_path_destroy() has assumed
that all workqs are quiesced.

Check the RDS_DESTROY_PENDING bit and use rcu synchronization to avoid
all these races.

Signed-off-by: Sowmini Varadhan &lt;sowmini.varadhan@oracle.com&gt;
Acked-by: Santosh Shilimkar &lt;santosh.shilimkar@oracle.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>rds: Use atomic flag to track connections being destroyed</title>
<updated>2018-01-05T18:39:18Z</updated>
<author>
<name>Sowmini Varadhan</name>
</author>
<published>2018-01-04T14:52:59Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=c90ecbfaf50d2d7db25c531d9169be7e47435f3f'/>
<id>urn:sha1:c90ecbfaf50d2d7db25c531d9169be7e47435f3f</id>
<content type='text'>
Replace c_destroy_in_prog by using a bit in cp_flags that
can set/tested atomically.

Signed-off-by: Sowmini Varadhan &lt;sowmini.varadhan@oracle.com&gt;
Acked-by: Santosh Shilimkar &lt;santosh.shilimkar@oracle.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>rds: debug: fix null check on static array</title>
<updated>2017-12-06T20:02:48Z</updated>
<author>
<name>Prashant Bhole</name>
</author>
<published>2017-12-06T01:47:04Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=d9b8693783e8a1ce8e4495d13d1dd6d8081f5070'/>
<id>urn:sha1:d9b8693783e8a1ce8e4495d13d1dd6d8081f5070</id>
<content type='text'>
t_name cannot be NULL since it is an array field of a struct.
Replacing null check on static array with string length check using
strnlen()

Signed-off-by: Prashant Bhole &lt;bhole_prashant_q7@lab.ntt.co.jp&gt;
Acked-by: Sowmini Varadhan &lt;sowmini.varadhan@oracle.com&gt;
Acked-by: Santosh Shilimkar &lt;santosh.shilimkar@oracle.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>rds: tcp: correctly sequence cleanup on netns deletion.</title>
<updated>2017-12-01T20:25:15Z</updated>
<author>
<name>Sowmini Varadhan</name>
</author>
<published>2017-11-30T19:11:28Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=681648e67d43cf269c5590ecf021ed481f4551fc'/>
<id>urn:sha1:681648e67d43cf269c5590ecf021ed481f4551fc</id>
<content type='text'>
Commit 8edc3affc077 ("rds: tcp: Take explicit refcounts on struct net")
introduces a regression in rds-tcp netns cleanup. The cleanup_net(),
(and thus rds_tcp_dev_event notification) is only called from put_net()
when all netns refcounts go to 0, but this cannot happen if the
rds_connection itself is holding a c_net ref that it expects to
release in rds_tcp_kill_sock.

Instead, the rds_tcp_kill_sock callback should make sure to
tear down state carefully, ensuring that the socket teardown
is only done after all data-structures and workqs that depend
on it are quiesced.

The original motivation for commit 8edc3affc077 ("rds: tcp: Take explicit
refcounts on struct net") was to resolve a race condition reported by
syzkaller where workqs for tx/rx/connect were triggered after the
namespace was deleted. Those worker threads should have been
cancelled/flushed before socket tear-down and indeed,
rds_conn_path_destroy() does try to sequence this by doing
     /* cancel cp_send_w */
     /* cancel cp_recv_w */
     /* flush cp_down_w */
     /* free data structures */
Here the "flush cp_down_w" will trigger rds_conn_shutdown and thus
invoke rds_tcp_conn_path_shutdown() to close the tcp socket, so that
we ought to have satisfied the requirement that "socket-close is
done after all other dependent state is quiesced". However,
rds_conn_shutdown has a bug in that it *always* triggers the reconnect
workq (and if connection is successful, we always restart tx/rx
workqs so with the right timing, we risk the race conditions reported
by syzkaller).

Netns deletion is like module teardown- no need to restart a
reconnect in this case. We can use the c_destroy_in_prog bit
to avoid restarting the reconnect.

Fixes: 8edc3affc077 ("rds: tcp: Take explicit refcounts on struct net")
Signed-off-by: Sowmini Varadhan &lt;sowmini.varadhan@oracle.com&gt;
Acked-by: Santosh Shilimkar &lt;santosh.shilimkar@oracle.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>rds: reduce memory footprint for RDS when transport is RDMA</title>
<updated>2017-08-03T16:27:59Z</updated>
<author>
<name>Sowmini Varadhan</name>
</author>
<published>2017-08-02T17:34:31Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=840df162b3eb3ec02e2613411fad1285a0017c13'/>
<id>urn:sha1:840df162b3eb3ec02e2613411fad1285a0017c13</id>
<content type='text'>
RDS over IB does not use multipath RDS, so the array
of additional rds_conn_path structures is always superfluous
in this case. Reduce the memory footprint of the rds module
by making this a dynamic allocation predicated on whether
the transport is mp_capable.

Signed-off-by: Sowmini Varadhan &lt;sowmini.varadhan@oracle.com&gt;
Acked-by: Santosh Shilimkar &lt;santosh.shilimkar@oracle.com&gt;
Tested-by: Efrain Galaviz &lt;efrain.galaviz@oracle.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>rds: cancel send/recv work before queuing connection shutdown</title>
<updated>2017-07-17T02:07:35Z</updated>
<author>
<name>Sowmini Varadhan</name>
</author>
<published>2017-07-16T23:43:46Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=aed20a53a7d91e45c6a8cb8920c77aaaa88f76ee'/>
<id>urn:sha1:aed20a53a7d91e45c6a8cb8920c77aaaa88f76ee</id>
<content type='text'>
We could end up executing rds_conn_shutdown before the rds_recv_worker
thread, then rds_conn_shutdown -&gt; rds_tcp_conn_shutdown can do a
sock_release and set sock-&gt;sk to null, which may interleave in bad
ways with rds_recv_worker, e.g., it could result in:

"BUG: unable to handle kernel NULL pointer dereference at 0000000000000078"
    [ffff881769f6fd70] release_sock at ffffffff815f337b
    [ffff881769f6fd90] rds_tcp_recv at ffffffffa043c888 [rds_tcp]
    [ffff881769f6fdb0] rds_recv_worker at ffffffffa04a4810 [rds]
    [ffff881769f6fde0] process_one_work at ffffffff810a14c1
    [ffff881769f6fe40] worker_thread at ffffffff810a1940
    [ffff881769f6fec0] kthread at ffffffff810a6b1e

Also, do not enqueue any new shutdown workq items when the connection is
shutting down (this may happen for rds-tcp in softirq mode, if a FIN
or CLOSE is received while the modules is in the middle of an unload)

Signed-off-by: Sowmini Varadhan &lt;sowmini.varadhan@oracle.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>rds: tcp: set linger to 1 when unloading a rds-tcp</title>
<updated>2017-06-22T15:34:04Z</updated>
<author>
<name>Sowmini Varadhan</name>
</author>
<published>2017-06-21T20:40:13Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=c14b0366813a8f6df7de181d8a333af7db6fb84e'/>
<id>urn:sha1:c14b0366813a8f6df7de181d8a333af7db6fb84e</id>
<content type='text'>
If we are unloading the rds_tcp module, we can set linger to 1
and drop pending packets to accelerate reconnect. The peer will
end up resetting the connection based on new generation numbers
of the new incarnation, so hanging on to unsent TCP packets via
linger is mostly pointless in this case.

Signed-off-by: Sowmini Varadhan &lt;sowmini.varadhan@oracle.com&gt;
Tested-by: Jenny Xu &lt;jenny.x.xu@oracle.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
<entry>
<title>rds: tcp: remove cp_outgoing</title>
<updated>2017-06-16T16:45:14Z</updated>
<author>
<name>Sowmini Varadhan</name>
</author>
<published>2017-06-15T18:28:53Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=41500c3e2a19ffcf40a7158fce1774de08e26ba2'/>
<id>urn:sha1:41500c3e2a19ffcf40a7158fce1774de08e26ba2</id>
<content type='text'>
After commit 1a0e100fb2c9 ("RDS: TCP: Force every connection to be
initiated by numerically smaller IP address") we no longer need
the logic associated with cp_outgoing, so clean up usage of this
field.

Signed-off-by: Sowmini Varadhan &lt;sowmini.varadhan@oracle.com&gt;
Tested-by: Imanti Mendez &lt;imanti.mendez@oracle.com&gt;
Signed-off-by: David S. Miller &lt;davem@davemloft.net&gt;
</content>
</entry>
</feed>
