From 368a8424bffa515a093732e04124d59941ec1992 Mon Sep 17 00:00:00 2001 From: Mark Bloch Date: Sun, 7 Feb 2021 07:23:13 +0000 Subject: [PATCH] ibacm: Fix possible port loop overflow [ Upstream commit 13d43426d81672970f3cbdaeb9e41bca40181ec1 ] When going over all the ports of an IB device and a uint_t8 variable is used a possible overflow can happen if the IB device has 255 ports. Once overflow occurs an invalid port (i.e. 0) is used. Fix by switching to uint32_t. Fixes: a0aaa5056057 ("ibacm: major rework to align with linux AF_IB changes") Signed-off-by: Mark Bloch Signed-off-by: Yishai Hadas Signed-off-by: Nicolas Morey-Chaisemartin --- ibacm/src/acme.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ibacm/src/acme.c b/ibacm/src/acme.c index 1289fa36c..569ad3fb5 100644 --- a/ibacm/src/acme.c +++ b/ibacm/src/acme.c @@ -453,7 +453,7 @@ static int gen_addr_names(FILE *f) struct ibv_port_attr port_attr; int i, index, ret, found_active; char host_name[256]; - uint8_t p; + uint32_t p; ret = gethostname(host_name, sizeof host_name); if (ret) { @@ -473,17 +473,17 @@ static int gen_addr_names(FILE *f) if (!found_active) { ret = ibv_query_port(verbs[i], p, &port_attr); if (!ret && port_attr.state == IBV_PORT_ACTIVE) { - VPRINT("%s %s %d default\n", + VPRINT("%s %s %u default\n", host_name, verbs[i]->device->name, p); - fprintf(f, "%s %s %d default\n", + fprintf(f, "%s %s %u default\n", host_name, verbs[i]->device->name, p); found_active = 1; } } - VPRINT("%s-%d %s %d default\n", + VPRINT("%s-%d %s %u default\n", host_name, index, verbs[i]->device->name, p); - fprintf(f, "%s-%d %s %d default\n", + fprintf(f, "%s-%d %s %u default\n", host_name, index++, verbs[i]->device->name, p); } }