Commit 532adda9 authored by Kees Cook's avatar Kees Cook Committed by Martin K. Petersen
Browse files

scsi: lpfc: Use struct_group() to initialize struct lpfc_cgn_info

In preparation for FORTIFY_SOURCE performing compile-time and run-time
field bounds checking for memset(), avoid intentionally writing across
neighboring fields.

Add struct_group() to mark "stat" region of struct lpfc_cgn_info that
should be initialized to zero, and refactor the "data" region memset()
to wipe everything up to the cgn_stats region.

Link: https://lore.kernel.org/r/20211208195957.1603092-1-keescook@chromium.org


Reviewed-by: default avatarJames Smart <jsmart2021@gmail.com>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 4437503b
Loading
Loading
Loading
Loading
+44 −46
Original line number Diff line number Diff line
@@ -496,7 +496,7 @@ struct lpfc_cgn_info {
	__le32   cgn_alarm_hr[24];
	__le32   cgn_alarm_day[LPFC_MAX_CGN_DAYS];

	/* Start of congestion statistics */
	struct_group(cgn_stat,
		uint8_t  cgn_stat_npm;		/* Notifications per minute */

		/* Start Time */
@@ -539,9 +539,7 @@ struct lpfc_cgn_info {
		uint8_t  cgn_stat_del_hour;
		uint8_t  cgn_stat_del_min;
		uint8_t  cgn_stat_del_sec;
#define LPFC_CGN_STAT_SIZE	48
#define LPFC_CGN_DATA_SIZE	(sizeof(struct lpfc_cgn_info) -  \
				LPFC_CGN_STAT_SIZE - sizeof(uint32_t))
	);

	__le32   cgn_info_crc;
#define LPFC_CGN_CRC32_MAGIC_NUMBER	0x1EDC6F41
+2 −2
Original line number Diff line number Diff line
@@ -13483,7 +13483,7 @@ lpfc_init_congestion_buf(struct lpfc_hba *phba)
	phba->cgn_evt_minute = 0;
	phba->hba_flag &= ~HBA_CGN_DAY_WRAP;

	memset(cp, 0xff, LPFC_CGN_DATA_SIZE);
	memset(cp, 0xff, offsetof(struct lpfc_cgn_info, cgn_stat));
	cp->cgn_info_size = cpu_to_le16(LPFC_CGN_INFO_SZ);
	cp->cgn_info_version = LPFC_CGN_INFO_V3;

@@ -13542,7 +13542,7 @@ lpfc_init_congestion_stat(struct lpfc_hba *phba)
		return;

	cp = (struct lpfc_cgn_info *)phba->cgn_i->virt;
	memset(&cp->cgn_stat_npm, 0, LPFC_CGN_STAT_SIZE);
	memset(&cp->cgn_stat, 0, sizeof(cp->cgn_stat));

	ktime_get_real_ts64(&cmpl_time);
	time64_to_tm(cmpl_time.tv_sec, 0, &broken);