From 8220f9ac52c34dde4fda6e46a19547727b861af1 Mon Sep 17 00:00:00 2001 From: "Kenneth D. Merry" Date: Thu, 20 Oct 2016 19:42:26 +0000 Subject: [PATCH] For CCBs allocated on the stack, we need to clear the entire CCB, not just the header. Otherwise stack garbage can lead to random flags getting set. This showed up as 'camcontrol rescan all' failing with EINVAL because the address type wasn't CAM_DATA_VADDR. sbin/camcontrol/camcontrol.c: In rescan_or_reset_bus(), bzero the stack-allocated CCBs before use instead of clearing the body. MFC after: 3 days Sponsored by: Spectra Logic --- sbin/camcontrol/camcontrol.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sbin/camcontrol/camcontrol.c b/sbin/camcontrol/camcontrol.c index 2c3778dce65a..aebb90371436 100644 --- a/sbin/camcontrol/camcontrol.c +++ b/sbin/camcontrol/camcontrol.c @@ -3139,6 +3139,8 @@ rescan_or_reset_bus(path_id_t bus, int rescan) return(1); } + bzero(&ccb, sizeof(ccb)); + if (bus != CAM_BUS_WILDCARD) { ccb.ccb_h.func_code = rescan ? XPT_SCAN_BUS : XPT_RESET_BUS; ccb.ccb_h.path_id = bus; @@ -3181,7 +3183,7 @@ rescan_or_reset_bus(path_id_t bus, int rescan) * no-op, sending a rescan to the xpt bus would result in a status of * CAM_REQ_INVALID. */ - CCB_CLEAR_ALL_EXCEPT_HDR(&matchccb.cdm); + bzero(&matchccb, sizeof(matchccb)); matchccb.ccb_h.func_code = XPT_DEV_MATCH; matchccb.ccb_h.path_id = CAM_BUS_WILDCARD; bufsize = sizeof(struct dev_match_result) * 20;