Commit 5f1141b1 authored by Bart Van Assche's avatar Bart Van Assche Committed by Doug Ledford

IB/srpt: Verify port numbers in srpt_event_handler()

Verify whether port numbers are in the expected range before using
these as an array index. Complain if a port number is out of range.
Signed-off-by: default avatarBart Van Assche <bart.vanassche@wdc.com>
Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
parent d9f45ae6
...@@ -134,6 +134,7 @@ static void srpt_event_handler(struct ib_event_handler *handler, ...@@ -134,6 +134,7 @@ static void srpt_event_handler(struct ib_event_handler *handler,
{ {
struct srpt_device *sdev; struct srpt_device *sdev;
struct srpt_port *sport; struct srpt_port *sport;
u8 port_num;
sdev = ib_get_client_data(event->device, &srpt_client); sdev = ib_get_client_data(event->device, &srpt_client);
if (!sdev || sdev->device != event->device) if (!sdev || sdev->device != event->device)
...@@ -144,10 +145,15 @@ static void srpt_event_handler(struct ib_event_handler *handler, ...@@ -144,10 +145,15 @@ static void srpt_event_handler(struct ib_event_handler *handler,
switch (event->event) { switch (event->event) {
case IB_EVENT_PORT_ERR: case IB_EVENT_PORT_ERR:
if (event->element.port_num <= sdev->device->phys_port_cnt) { port_num = event->element.port_num - 1;
sport = &sdev->port[event->element.port_num - 1]; if (port_num < sdev->device->phys_port_cnt) {
sport = &sdev->port[port_num];
sport->lid = 0; sport->lid = 0;
sport->sm_lid = 0; sport->sm_lid = 0;
} else {
WARN(true, "event %d: port_num %d out of range 1..%d\n",
event->event, port_num + 1,
sdev->device->phys_port_cnt);
} }
break; break;
case IB_EVENT_PORT_ACTIVE: case IB_EVENT_PORT_ACTIVE:
...@@ -157,15 +163,19 @@ static void srpt_event_handler(struct ib_event_handler *handler, ...@@ -157,15 +163,19 @@ static void srpt_event_handler(struct ib_event_handler *handler,
case IB_EVENT_CLIENT_REREGISTER: case IB_EVENT_CLIENT_REREGISTER:
case IB_EVENT_GID_CHANGE: case IB_EVENT_GID_CHANGE:
/* Refresh port data asynchronously. */ /* Refresh port data asynchronously. */
if (event->element.port_num <= sdev->device->phys_port_cnt) { port_num = event->element.port_num - 1;
sport = &sdev->port[event->element.port_num - 1]; if (port_num < sdev->device->phys_port_cnt) {
sport = &sdev->port[port_num];
if (!sport->lid && !sport->sm_lid) if (!sport->lid && !sport->sm_lid)
schedule_work(&sport->work); schedule_work(&sport->work);
} else {
WARN(true, "event %d: port_num %d out of range 1..%d\n",
event->event, port_num + 1,
sdev->device->phys_port_cnt);
} }
break; break;
default: default:
pr_err("received unrecognized IB event %d\n", pr_err("received unrecognized IB event %d\n", event->event);
event->event);
break; break;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment