pppoe: disc: document who holds references to the net object #141
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
REVISED PATCH
While working on another patch, I had a bug that seemed to be related
to a use-after-free on the net structure, leading to a faulty patch
removing the disc_stop refcount decrement, as I missed that the init_net
function initialized the refcount to 1 and not 0. The bug was in my
code.
This patch adds simple comments the reference handling to make it a bit
more obvious what is going on.
INITIAL VERSION
pppoe: disc: do not free the net struct in disc_stop
Assuming there is only one server associated with the current net
object, freeing the net object at the end of disc_stop could potentially
create a use-after-free error since before that, we queued an
asynchronous call to _serv_stop, which in turn calls pppoe_disc_stop.
Since pppoe_disc_stop acquires a pointer to the net object at the
beginning of its run, and uses it all throughout as part of its locking,
having free_net running alongside could result in the memory backing the
lock being freed while the code is running.