Skip to content

Commit

Permalink
ocp: fix to check hwcomp log size if valid
Browse files Browse the repository at this point in the history
Since the log size value needed to reduce the descriptor length.

Signed-off-by: Tokunori Ikegami <[email protected]>
  • Loading branch information
ikegami-t committed Dec 29, 2024
1 parent 4608b1c commit 8e0ee84
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions plugins/ocp/ocp-hardware-component-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ static int get_hwcomp_log_data(struct nvme_dev *dev, struct hwcomp_log *log)
{
int ret = 0;
size_t desc_offset = offsetof(struct hwcomp_log, desc);
long double log_bytes;
nvme_uint128_t log_size;

struct nvme_get_log_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
Expand All @@ -193,16 +196,27 @@ static int get_hwcomp_log_data(struct nvme_dev *dev, struct hwcomp_log *log)
}
#endif /* HWCOMP_DUMMY */

log_size = le128_to_cpu(log->size);

print_info("id: %02Xh\n", OCP_LID_HWCOMP);
print_info("version: %04Xh\n", log->ver);
print_info_array("guid", log->guid, ARRAY_SIZE(log->guid));
print_info("size: %s\n", uint128_t_to_string(le128_to_cpu(log->size)));
print_info("size: %s\n", uint128_t_to_string(log_size));

log_bytes = uint128_t_to_double(log_size);
if (log->ver == 1)
log_bytes *= sizeof(__le32);

args.len = 0;
if (log_bytes > desc_offset)
args.len = log_bytes - desc_offset;

if (!args.len) {
print_info_error("error: ocp: invalid hwcomp log size bytes: %.0Lf\n", log_bytes);
return -EINVAL;
}

if (log->ver > 1)
args.len = uint128_t_to_double(le128_to_cpu(log->size)) - desc_offset;
else
args.len = uint128_t_to_double(le128_to_cpu(log->size)) * sizeof(__le32)
- desc_offset;
print_info("args.len: %u\n", args.len);

log->desc = calloc(1, args.len);
if (!log->desc) {
Expand Down

0 comments on commit 8e0ee84

Please sign in to comment.