linux/drivers/scsi/libfc
Alok Tiwari 072fdd4b0b scsi: libfc: Fix potential buffer overflow in fc_ct_ms_fill()
The fc_ct_ms_fill() helper currently formats the OS name and version
into entry->value using "%s v%s". Since init_utsname()->sysname and
->release are unbounded strings, snprintf() may attempt to write more
than FC_FDMI_HBA_ATTR_OSNAMEVERSION_LEN bytes, triggering a
-Wformat-truncation warning with W=1.

In file included from drivers/scsi/libfc/fc_elsct.c:18:
drivers/scsi/libfc/fc_encode.h: In function ‘fc_ct_ms_fill.constprop’:
drivers/scsi/libfc/fc_encode.h:359:30: error: ‘%s’ directive output may
be truncated writing up to 64 bytes into a region of size between 62
and 126 [-Werror=format-truncation=]
  359 |                         "%s v%s",
      |                              ^~
  360 |                         init_utsname()->sysname,
  361 |                         init_utsname()->release);
      |                         ~~~~~~~~~~~~~~~~~~~~~~~
drivers/scsi/libfc/fc_encode.h:357:17: note: ‘snprintf’ output between
3 and 131 bytes into a destination of size 128
  357 |                 snprintf((char *)&entry->value,
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  358 |                         FC_FDMI_HBA_ATTR_OSNAMEVERSION_LEN,
      |                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  359 |                         "%s v%s",
      |                         ~~~~~~~~~
  360 |                         init_utsname()->sysname,
      |                         ~~~~~~~~~~~~~~~~~~~~~~~~
  361 |                         init_utsname()->release);
      |                         ~~~~~~~~~~~~~~~~~~~~~~~~

Fix this by using "%.62s v%.62s", which ensures sysname and release are
truncated to fit within the 128-byte field defined by
FC_FDMI_HBA_ATTR_OSNAMEVERSION_LEN.

[mkp: clarified commit description]

Signed-off-by: Alok Tiwari <alok.a.tiwari@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2025-09-24 21:57:03 -04:00
..
Makefile
fc_disc.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
fc_elsct.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
fc_encode.h scsi: libfc: Fix potential buffer overflow in fc_ct_ms_fill() 2025-09-24 21:57:03 -04:00
fc_exch.c
fc_fcp.c treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
fc_frame.c
fc_libfc.c
fc_libfc.h
fc_lport.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
fc_npiv.c
fc_rport.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00