Skip to content

Commit

Permalink
scsi: smartpqi: Use scnprintf() for avoiding potential buffer overflow
Browse files Browse the repository at this point in the history
Since snprintf() returns the would-be-output size instead of the actual
output size, the succeeding calls may go beyond the given buffer limit.
Fix it by replacing with scnprintf().

Link: https://lore.kernel.org/r/[email protected]
Cc: "James E . J . Bottomley" <[email protected]>
Cc: "Martin K . Petersen" <[email protected]>
Cc: Don Brace <[email protected]>
Cc: [email protected]
Signed-off-by: Takashi Iwai <[email protected]>
Signed-off-by: Martin K. Petersen <[email protected]>
  • Loading branch information
tiwai authored and martinkpetersen committed Mar 17, 2020
1 parent 81546b3 commit 181aea8
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions drivers/scsi/smartpqi/smartpqi_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -1614,48 +1614,48 @@ static void pqi_dev_info(struct pqi_ctrl_info *ctrl_info,
"%d:%d:", ctrl_info->scsi_host->host_no, device->bus);

if (device->target_lun_valid)
count += snprintf(buffer + count,
count += scnprintf(buffer + count,
PQI_DEV_INFO_BUFFER_LENGTH - count,
"%d:%d",
device->target,
device->lun);
else
count += snprintf(buffer + count,
count += scnprintf(buffer + count,
PQI_DEV_INFO_BUFFER_LENGTH - count,
"-:-");

if (pqi_is_logical_device(device))
count += snprintf(buffer + count,
count += scnprintf(buffer + count,
PQI_DEV_INFO_BUFFER_LENGTH - count,
" %08x%08x",
*((u32 *)&device->scsi3addr),
*((u32 *)&device->scsi3addr[4]));
else
count += snprintf(buffer + count,
count += scnprintf(buffer + count,
PQI_DEV_INFO_BUFFER_LENGTH - count,
" %016llx", device->sas_address);

count += snprintf(buffer + count, PQI_DEV_INFO_BUFFER_LENGTH - count,
count += scnprintf(buffer + count, PQI_DEV_INFO_BUFFER_LENGTH - count,
" %s %.8s %.16s ",
pqi_device_type(device),
device->vendor,
device->model);

if (pqi_is_logical_device(device)) {
if (device->devtype == TYPE_DISK)
count += snprintf(buffer + count,
count += scnprintf(buffer + count,
PQI_DEV_INFO_BUFFER_LENGTH - count,
"SSDSmartPathCap%c En%c %-12s",
device->raid_bypass_configured ? '+' : '-',
device->raid_bypass_enabled ? '+' : '-',
pqi_raid_level_to_string(device->raid_level));
} else {
count += snprintf(buffer + count,
count += scnprintf(buffer + count,
PQI_DEV_INFO_BUFFER_LENGTH - count,
"AIO%c", device->aio_enabled ? '+' : '-');
if (device->devtype == TYPE_DISK ||
device->devtype == TYPE_ZBC)
count += snprintf(buffer + count,
count += scnprintf(buffer + count,
PQI_DEV_INFO_BUFFER_LENGTH - count,
" qd=%-6d", device->queue_depth);
}
Expand Down Expand Up @@ -6191,14 +6191,14 @@ static ssize_t pqi_lockup_action_show(struct device *dev,

for (i = 0; i < ARRAY_SIZE(pqi_lockup_actions); i++) {
if (pqi_lockup_actions[i].action == pqi_lockup_action)
count += snprintf(buffer + count, PAGE_SIZE - count,
count += scnprintf(buffer + count, PAGE_SIZE - count,
"[%s] ", pqi_lockup_actions[i].name);
else
count += snprintf(buffer + count, PAGE_SIZE - count,
count += scnprintf(buffer + count, PAGE_SIZE - count,
"%s ", pqi_lockup_actions[i].name);
}

count += snprintf(buffer + count, PAGE_SIZE - count, "\n");
count += scnprintf(buffer + count, PAGE_SIZE - count, "\n");

return count;
}
Expand Down

0 comments on commit 181aea8

Please sign in to comment.