Skip to content

Commit

Permalink
ibacm: Fix possible port loop overflow
Browse files Browse the repository at this point in the history
[ Upstream commit 13d4342 ]

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: a0aaa50 ("ibacm: major rework to align with linux AF_IB changes")
Signed-off-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
Signed-off-by: Nicolas Morey-Chaisemartin <nmoreychaisemartin@suse.com>
  • Loading branch information
mark-bloch authored and nmorey committed Feb 18, 2021
1 parent bd77596 commit 368a842
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions ibacm/src/acme.c
Expand Up @@ -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) {
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 368a842

Please sign in to comment.