Add asserts for some state transitions

For the PROBEWP and PROBERC* states, add assertiosn that both the da device
state is in the right state, as well as the ccb state is the right one when we
enter dadone_probe{wp,rc}. This will ensure that we don't sneak through when
we're re-probing the size and write protection status of the device and thereby
leak a reference which can later lead to an invalidated peripheral going away
before all references are released (and resulting panic).

Reviewed by: scottl, ken
Differential Revision: https://reviews.freebsd.org/D22295
This commit is contained in:
Warner Losh 2019-11-11 17:36:57 +00:00
parent dc1c17691e
commit 45fceedf87
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=354623

View File

@ -4613,6 +4613,14 @@ dadone_probewp(struct cam_periph *periph, union ccb *done_ccb)
cam_periph_assert(periph, MA_OWNED);
KASSERT(softc->state == DA_STATE_PROBE_WP,
("State (%d) not PROBE_WP in dadone_probewp, periph %p ccb %p",
softc->state, periph, done_ccb));
KASSERT((csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK) == DA_CCB_PROBE_WP,
("CCB State (%lu) not PROBE_WP in dadone_probewp, periph %p ccb %p",
(unsigned long)csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK, periph,
done_ccb));
if (softc->minimum_cmd_size > 6) {
mode_hdr10 = (struct scsi_mode_header_10 *)csio->data_ptr;
dev_spec = mode_hdr10->dev_spec;
@ -4673,6 +4681,13 @@ dadone_proberc(struct cam_periph *periph, union ccb *done_ccb)
csio = &done_ccb->csio;
state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
KASSERT(softc->state == DA_STATE_PROBE_RC || softc->state == DA_STATE_PROBE_RC16,
("State (%d) not PROBE_RC* in dadone_proberc, periph %p ccb %p",
softc->state, periph, done_ccb));
KASSERT(state == DA_CCB_PROBE_RC || state == DA_CCB_PROBE_RC16,
("CCB State (%lu) not PROBE_RC* in dadone_probewp, periph %p ccb %p",
(unsigned long)state, periph, done_ccb));
lbp = 0;
rdcap = NULL;
rcaplong = NULL;