Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: James Smart <jsmart2021@gmail.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Kees Cook and committed by
Martin K. Petersen
532adda9 4437503b

+40 -42
+38 -40
drivers/scsi/lpfc/lpfc.h
··· 496 496 __le32 cgn_alarm_hr[24]; 497 497 __le32 cgn_alarm_day[LPFC_MAX_CGN_DAYS]; 498 498 499 - /* Start of congestion statistics */ 500 - uint8_t cgn_stat_npm; /* Notifications per minute */ 499 + struct_group(cgn_stat, 500 + uint8_t cgn_stat_npm; /* Notifications per minute */ 501 501 502 - /* Start Time */ 503 - uint8_t cgn_stat_month; 504 - uint8_t cgn_stat_day; 505 - uint8_t cgn_stat_year; 506 - uint8_t cgn_stat_hour; 507 - uint8_t cgn_stat_minute; 508 - uint8_t cgn_pad2[2]; 502 + /* Start Time */ 503 + uint8_t cgn_stat_month; 504 + uint8_t cgn_stat_day; 505 + uint8_t cgn_stat_year; 506 + uint8_t cgn_stat_hour; 507 + uint8_t cgn_stat_minute; 508 + uint8_t cgn_pad2[2]; 509 509 510 - __le32 cgn_notification; 511 - __le32 cgn_peer_notification; 512 - __le32 link_integ_notification; 513 - __le32 delivery_notification; 510 + __le32 cgn_notification; 511 + __le32 cgn_peer_notification; 512 + __le32 link_integ_notification; 513 + __le32 delivery_notification; 514 514 515 - uint8_t cgn_stat_cgn_month; /* Last congestion notification FPIN */ 516 - uint8_t cgn_stat_cgn_day; 517 - uint8_t cgn_stat_cgn_year; 518 - uint8_t cgn_stat_cgn_hour; 519 - uint8_t cgn_stat_cgn_min; 520 - uint8_t cgn_stat_cgn_sec; 515 + uint8_t cgn_stat_cgn_month; /* Last congestion notification FPIN */ 516 + uint8_t cgn_stat_cgn_day; 517 + uint8_t cgn_stat_cgn_year; 518 + uint8_t cgn_stat_cgn_hour; 519 + uint8_t cgn_stat_cgn_min; 520 + uint8_t cgn_stat_cgn_sec; 521 521 522 - uint8_t cgn_stat_peer_month; /* Last peer congestion FPIN */ 523 - uint8_t cgn_stat_peer_day; 524 - uint8_t cgn_stat_peer_year; 525 - uint8_t cgn_stat_peer_hour; 526 - uint8_t cgn_stat_peer_min; 527 - uint8_t cgn_stat_peer_sec; 522 + uint8_t cgn_stat_peer_month; /* Last peer congestion FPIN */ 523 + uint8_t cgn_stat_peer_day; 524 + uint8_t cgn_stat_peer_year; 525 + uint8_t cgn_stat_peer_hour; 526 + uint8_t cgn_stat_peer_min; 527 + uint8_t cgn_stat_peer_sec; 528 528 529 - uint8_t cgn_stat_lnk_month; /* Last link integrity FPIN */ 530 - uint8_t cgn_stat_lnk_day; 531 - uint8_t cgn_stat_lnk_year; 532 - uint8_t cgn_stat_lnk_hour; 533 - uint8_t cgn_stat_lnk_min; 534 - uint8_t cgn_stat_lnk_sec; 529 + uint8_t cgn_stat_lnk_month; /* Last link integrity FPIN */ 530 + uint8_t cgn_stat_lnk_day; 531 + uint8_t cgn_stat_lnk_year; 532 + uint8_t cgn_stat_lnk_hour; 533 + uint8_t cgn_stat_lnk_min; 534 + uint8_t cgn_stat_lnk_sec; 535 535 536 - uint8_t cgn_stat_del_month; /* Last delivery notification FPIN */ 537 - uint8_t cgn_stat_del_day; 538 - uint8_t cgn_stat_del_year; 539 - uint8_t cgn_stat_del_hour; 540 - uint8_t cgn_stat_del_min; 541 - uint8_t cgn_stat_del_sec; 542 - #define LPFC_CGN_STAT_SIZE 48 543 - #define LPFC_CGN_DATA_SIZE (sizeof(struct lpfc_cgn_info) - \ 544 - LPFC_CGN_STAT_SIZE - sizeof(uint32_t)) 536 + uint8_t cgn_stat_del_month; /* Last delivery notification FPIN */ 537 + uint8_t cgn_stat_del_day; 538 + uint8_t cgn_stat_del_year; 539 + uint8_t cgn_stat_del_hour; 540 + uint8_t cgn_stat_del_min; 541 + uint8_t cgn_stat_del_sec; 542 + ); 545 543 546 544 __le32 cgn_info_crc; 547 545 #define LPFC_CGN_CRC32_MAGIC_NUMBER 0x1EDC6F41
+2 -2
drivers/scsi/lpfc/lpfc_init.c
··· 13483 13483 phba->cgn_evt_minute = 0; 13484 13484 phba->hba_flag &= ~HBA_CGN_DAY_WRAP; 13485 13485 13486 - memset(cp, 0xff, LPFC_CGN_DATA_SIZE); 13486 + memset(cp, 0xff, offsetof(struct lpfc_cgn_info, cgn_stat)); 13487 13487 cp->cgn_info_size = cpu_to_le16(LPFC_CGN_INFO_SZ); 13488 13488 cp->cgn_info_version = LPFC_CGN_INFO_V3; 13489 13489 ··· 13542 13542 return; 13543 13543 13544 13544 cp = (struct lpfc_cgn_info *)phba->cgn_i->virt; 13545 - memset(&cp->cgn_stat_npm, 0, LPFC_CGN_STAT_SIZE); 13545 + memset(&cp->cgn_stat, 0, sizeof(cp->cgn_stat)); 13546 13546 13547 13547 ktime_get_real_ts64(&cmpl_time); 13548 13548 time64_to_tm(cmpl_time.tv_sec, 0, &broken);