]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
MFC r320421:
authorken <ken@FreeBSD.org>
Mon, 3 Jul 2017 15:34:21 +0000 (15:34 +0000)
committerken <ken@FreeBSD.org>
Mon, 3 Jul 2017 15:34:21 +0000 (15:34 +0000)
commit9d75fcb36dbbd65c5efb20b6dde53dd45a6c6056
tree991318f05c5929b6da225d82b1932597987b5c93
parent007fbeb9c679f727af4afa22d3a3916ddef42386
MFC r320421:

  ------------------------------------------------------------------------
  r320421 | ken | 2017-06-27 13:26:02 -0600 (Tue, 27 Jun 2017) | 37 lines

  Fix a panic in camperiphfree().

  If a peripheral driver (e.g. da, sa, cd) is added or removed from the
  peripheral driver list while an unrelated peripheral driver instance (e.g.
  da0, sa5, cd2) is going away and is inside camperiphfree(), we could
  dereference an invalid pointer.

  When peripheral drivers are added or removed (see periphdriver_register()
  and periphdriver_unregister()), the peripheral driver array is resized
  and existing entries are moved.

  Although we hold the topology lock while we traverse the peripheral driver
  list, we retain a pointer to the location of the peripheral driver pointer
  and then drop the topology lock.  So we are still vulnerable to the list
  getting moved around while the lock is dropped.

  To solve the problem, cache a copy of the peripheral driver pointer.  If
  its storage location in the list changes while we have the lock dropped, it
  won't have any effect.

  This doesn't solve the issue that peripheral drivers ("da", "cd", as opposed
  to individual instances like "da0", "cd0") are not generally part of a
  reference counting scheme to guard against deregistering them while there
  are instances active.  The caller (generally the person unloading a module)
  has to be aware of active drivers and not unload something that is in use.

  sys/cam/cam_periph.c:
   In camperiphfree(), cache a pointer to the peripheral driver
   instance to avoid holding a pointer to an invalid memory location
   in the event that the peripheral driver list changes while we have
   the topology lock dropped.

  PR: kern/219701
  Submitted by: avg
  Sponsored by: Spectra Logic

  ------------------------------------------------------------------------
PR: kern/219701
Sponsored by: Spectra Logic
sys/cam/cam_periph.c