Skip to contentSkip to conversation

csiostor: off by one error

PATCH In review Dan Carpenter 2 participants 2 messages Mar 16, 2013 – Mar 25, 2013 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 csiostor: off by one error

We need to store PROTO_ERR_IMPL_LOGO (26) things here, but the first element isn't used so the array should have 27 elements. This matches fwevt_to_rnevt[] which has 27 elements.

The patch solves a Smatch static checker warning on my system:
drivers/scsi/csiostor/csio_rnode.c:880 csio_rnode_fwevt_handler()

	error: buffer overflow '(rn)->stats.n_evt_fw' 26 <= 26

---
This goes on top of d69630e8a4222 "csiostor: Header file modifications for chip support and bug fixes." That patch is in linux-next but I don't know which tree it came from. It's not the scsi for-next tree.

drivers/scsi/csiostor/csio_rnode.h +1 -1
index 6594009..4334342 100644
@@ -63,7 +63,7 @@ struct csio_rnode_stats {
 	uint32_t	n_err_nomem;	/* error nomem */
 	uint32_t	n_evt_unexp;	/* unexpected event */
 	uint32_t	n_evt_drop;	/* unexpected event */
-	uint32_t	n_evt_fw[PROTO_ERR_IMPL_LOGO];	/* fw events */
+	uint32_t	n_evt_fw[PROTO_ERR_IMPL_LOGO + 1];	/* fw events */
 	enum csio_rn_ev	n_evt_sm[CSIO_RNFE_MAX_EVENT];	/* State m/c events */
 	uint32_t	n_lun_rst;	/* Number of resets of
 					 * of LUNs under this
drivers/scsi/csiostor/csio_lnode.h +1 -1
index 0f9c041..372a67d 100644
@@ -114,7 +114,7 @@ struct csio_lnode_stats {
 	uint32_t	n_rnode_match;  /* matched rnode */
 	uint32_t	n_dev_loss_tmo; /* Device loss timeout */
 	uint32_t	n_fdmi_err;	/* fdmi err */
-	uint32_t	n_evt_fw[PROTO_ERR_IMPL_LOGO];	/* fw events */
+	uint32_t	n_evt_fw[PROTO_ERR_IMPL_LOGO + 1];	/* fw events */
 	enum csio_ln_ev	n_evt_sm[CSIO_LNE_MAX_EVENT];	/* State m/c events */
 	uint32_t	n_rnode_alloc;	/* rnode allocated */
 	uint32_t	n_rnode_free;	/* rnode freed */
Acked-by on v1 1/1
#1 lore raw
Quoted 34 lines · Dan Carpenter

We need to store PROTO_ERR_IMPL_LOGO (26) things here, but the first element isn't used so the array should have 27 elements. This matches fwevt_to_rnevt[] which has 27 elements.

The patch solves a Smatch static checker warning on my system:
drivers/scsi/csiostor/csio_rnode.c:880 csio_rnode_fwevt_handler()

	error: buffer overflow '(rn)->stats.n_evt_fw' 26 <= 26

---
This goes on top of d69630e8a4222 "csiostor: Header file modifications for chip support and bug fixes." That patch is in linux-next but I don't know which tree it came from. It's not the scsi for-next tree.

drivers/scsi/csiostor/csio_rnode.h +1 -1
index 6594009..4334342 100644
@@ -63,7 +63,7 @@ struct csio_rnode_stats {
 	uint32_t	n_err_nomem;	/* error nomem */
 	uint32_t	n_evt_unexp;	/* unexpected event */
 	uint32_t	n_evt_drop;	/* unexpected event */
-	uint32_t	n_evt_fw[PROTO_ERR_IMPL_LOGO];	/* fw events */
+	uint32_t	n_evt_fw[PROTO_ERR_IMPL_LOGO + 1];	/* fw events */
 	enum csio_rn_ev	n_evt_sm[CSIO_RNFE_MAX_EVENT];	/* State m/c events */
 	uint32_t	n_lun_rst;	/* Number of resets of
 					 * of LUNs under this
drivers/scsi/csiostor/csio_lnode.h +0 -0
index 0f9c041..372a67d 100644

drivers/scsi/csiostor/csio_lnode.h struct csio_lnode_stats { · line 120

Quoted 8 lines
drivers/scsi/csiostor/csio_lnode.h +1 -1
@@ -114,7 +114,7 @@ struct csio_lnode_stats {
 	uint32_t	n_rnode_match;  /* matched rnode */
 	uint32_t	n_dev_loss_tmo; /* Device loss timeout */
 	uint32_t	n_fdmi_err;	/* fdmi err */
-	uint32_t	n_evt_fw[PROTO_ERR_IMPL_LOGO];	/* fw events */
+	uint32_t	n_evt_fw[PROTO_ERR_IMPL_LOGO + 1];	/* fw events */
 	enum csio_ln_ev	n_evt_sm[CSIO_LNE_MAX_EVENT];	/* State m/c events */
 	uint32_t	n_rnode_alloc;	/* rnode allocated */
 	uint32_t	n_rnode_free;	/* rnode freed */

Thanks,
Naresh.