diff options
author | mav <mav@FreeBSD.org> | 2017-03-23 06:41:13 +0000 |
---|---|---|
committer | mav <mav@FreeBSD.org> | 2017-03-23 06:41:13 +0000 |
commit | 631dcdedb38019b17d61bcab65a49187ba252750 (patch) | |
tree | 15e02dbc1c5e7eb7fccbc68b409f233bf9fa9be0 /sys/cam | |
parent | 62106bfe0d84d50a5a95a989dfb48d2e7ad8a62b (diff) | |
download | FreeBSD-src-631dcdedb38019b17d61bcab65a49187ba252750.zip FreeBSD-src-631dcdedb38019b17d61bcab65a49187ba252750.tar.gz |
MFC r311305 (by asomers):
Always null-terminate ccb_pathinq.(sim_vid|hba_vid|dev_name)
The sim_vid, hba_vid, and dev_name fields of struct ccb_pathinq are
fixed-length strings. AFAICT the only place they're read is in
sbin/camcontrol/camcontrol.c, which assumes they'll be null-terminated.
However, the kernel doesn't null-terminate them. A bunch of copy-pasted code
uses strncpy to write them, and doesn't guarantee null-termination. For at
least 4 drivers (mpr, mps, ciss, and hyperv), the hba_vid field actually
overflows. You can see the result by doing "camcontrol negotiate da0 -v".
This change null-terminates those fields everywhere they're set in the
kernel. It also shortens a few strings to ensure they'll fit within the
16-character field.
PR: 215474
Reported by: Coverity
CID: 1009997 1010000 1010001 1010002 1010003 1010004 1010005
CID: 1331519 1010006 1215097 1010007 1288967 1010008 1306000
CID: 1211924 1010009 1010010 1010011 1010012 1010013 1010014
CID: 1147190 1010017 1010016 1010018 1216435 1010020 1010021
CID: 1010022 1009666 1018185 1010023 1010025 1010026 1010027
CID: 1010028 1010029 1010030 1010031 1010033 1018186 1018187
CID: 1010035 1010036 1010042 1010041 1010040 1010039
Diffstat (limited to 'sys/cam')
-rw-r--r-- | sys/cam/cam_xpt.c | 6 | ||||
-rw-r--r-- | sys/cam/ctl/ctl_frontend_cam_sim.c | 6 | ||||
-rw-r--r-- | sys/cam/scsi/scsi_low.c | 6 |
3 files changed, 9 insertions, 9 deletions
diff --git a/sys/cam/cam_xpt.c b/sys/cam/cam_xpt.c index 3cf307a..5f4f509 100644 --- a/sys/cam/cam_xpt.c +++ b/sys/cam/cam_xpt.c @@ -5144,9 +5144,9 @@ xptaction(struct cam_sim *sim, union ccb *work_ccb) cpi->max_target = 0; cpi->max_lun = 0; cpi->initiator_id = 0; - strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN); - strncpy(cpi->hba_vid, "", HBA_IDLEN); - strncpy(cpi->dev_name, sim->sim_name, DEV_IDLEN); + strlcpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN); + strlcpy(cpi->hba_vid, "", HBA_IDLEN); + strlcpy(cpi->dev_name, sim->sim_name, DEV_IDLEN); cpi->unit_number = sim->unit_number; cpi->bus_id = sim->bus_id; cpi->base_transfer_speed = 0; diff --git a/sys/cam/ctl/ctl_frontend_cam_sim.c b/sys/cam/ctl/ctl_frontend_cam_sim.c index 9a0ca9a..00a960e 100644 --- a/sys/cam/ctl/ctl_frontend_cam_sim.c +++ b/sys/cam/ctl/ctl_frontend_cam_sim.c @@ -786,9 +786,9 @@ cfcs_action(struct cam_sim *sim, union ccb *ccb) cpi->hpath_id = 0; cpi->initiator_id = 0; - strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN); - strncpy(cpi->hba_vid, "FreeBSD", HBA_IDLEN); - strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN); + strlcpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN); + strlcpy(cpi->hba_vid, "FreeBSD", HBA_IDLEN); + strlcpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN); cpi->unit_number = 0; cpi->bus_id = 0; cpi->base_transfer_speed = 800000; diff --git a/sys/cam/scsi/scsi_low.c b/sys/cam/scsi/scsi_low.c index 8ca669e..411c5a1 100644 --- a/sys/cam/scsi/scsi_low.c +++ b/sys/cam/scsi/scsi_low.c @@ -741,9 +741,9 @@ settings_out: cpi->transport_version = 2; cpi->protocol = PROTO_SCSI; cpi->protocol_version = SCSI_REV_2; - strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN); - strncpy(cpi->hba_vid, "SCSI_LOW", HBA_IDLEN); - strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN); + strlcpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN); + strlcpy(cpi->hba_vid, "SCSI_LOW", HBA_IDLEN); + strlcpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN); cpi->unit_number = cam_sim_unit(sim); cpi->ccb_h.status = CAM_REQ_CMP; xpt_done(ccb); |