netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* rtnetlink: fix dump+module unload races, take 2
@ 2017-11-06 10:51 Florian Westphal
  2017-11-06 10:51 ` [PATCH net-next 1/8] rtnetlink: Revert "rtnetlink: add reference counting to prevent module unload while dump is in progress" Florian Westphal
                   ` (7 more replies)
  0 siblings, 8 replies; 20+ messages in thread
From: Florian Westphal @ 2017-11-06 10:51 UTC (permalink / raw)
  To: netdev; +Cc: peterz

Peter Zijlstra reported:
----------
  I just ran across commit:
  019a316992ee ("rtnetlink: add reference counting to prevent module unload while dump is in progress")
  And that commit is _completely_ broken.

  1) it not in fact a refcount, so using refcount_t is silly
  2) there is a distinct lack of memory barriers, so we can easily
     observe the decrement while the msg_handler is still in progress.
  3) waiting with a schedule()/yield() loop is complete crap and subject
     life-locks, imagine doing that rtnl_unregister_all() from a RT task.
----------

Moreover, the commit doesn't work.

Problem is that netlink keeps the dump function address in the control
block to resume dumps, i.e. when netlink_dump_start() returns then
we may not be done with the dump, it can be restarted on next recv.

netlink already has a mechanism to prevent module unload while
dumps are in progress: netlink_dump_control struct contains a pointer
to struct module, and netlink will take care of module_get/put as needed
if that is set.

To make use of this however we need to store pointer to module that
registered the particular dump function.  This series does that.

First, revert the broken commit to start from scratch.
Second patch adds new rtnl_register_module() that takes pointer to
the owning module.

Rest of patches convert affected modules.
IPv6 is not converted as ipv6 module cannot be unloaded.

One alternative to this series would be to decrement
rtnl_msg_handlers_ref count via netlink_dump_control->done(), but that
doesn't address any of Peters points.

I am submitting this for -next for 2 reasons:
1. This problem has existed for so long its evidently not a big deal
2. I think its a bad idea to cram this in at last second in current
development cycle.

ps: I will be travelling, replies will be delayed.

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2017-11-13  8:00 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-06 10:51 rtnetlink: fix dump+module unload races, take 2 Florian Westphal
2017-11-06 10:51 ` [PATCH net-next 1/8] rtnetlink: Revert "rtnetlink: add reference counting to prevent module unload while dump is in progress" Florian Westphal
2017-11-06 10:51 ` [PATCH net-next 2/8] rtnetlink: add rtnl_register_module Florian Westphal
2017-11-06 12:44   ` Peter Zijlstra
2017-11-07  6:11     ` Florian Westphal
2017-11-07  9:10       ` Peter Zijlstra
2017-11-07  9:24         ` Peter Zijlstra
2017-11-07  9:47           ` Florian Westphal
2017-11-07 14:57             ` Peter Zijlstra
2017-11-08  1:27               ` Stephen Hemminger
2017-11-13  7:21               ` Florian Westphal
2017-11-13  7:55                 ` Peter Zijlstra
2017-11-13  7:59                   ` Florian Westphal
2017-11-07  9:43         ` Florian Westphal
2017-11-06 10:51 ` [PATCH net-next 3/8] qtr: use rtnl_register_module Florian Westphal
2017-11-06 10:51 ` [PATCH net-next 4/8] bridge: " Florian Westphal
2017-11-06 10:51 ` [PATCH net-next 5/8] can: " Florian Westphal
2017-11-06 10:51 ` [PATCH net-next 6/8] decnet: " Florian Westphal
2017-11-06 10:51 ` [PATCH net-next 7/8] phonet: " Florian Westphal
2017-11-06 10:51 ` [PATCH net-next 8/8] mpls: " Florian Westphal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).