Skip to content

Commit 0926f91

Browse files
Eli Cohendavem330
authored andcommitted
mlx4_en: Fix out of bounds array access
When searching for a free entry in either mlx4_register_vlan() or mlx4_register_mac(), and there is no free entry, the loop terminates without updating the local variable free thus causing out of array bounds access. Fix this by adding a proper check outside the loop. Signed-off-by: Eli Cohen <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b336369 commit 0926f91

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

drivers/net/mlx4/port.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ int mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac, int *index)
111111
goto out;
112112
}
113113
}
114+
115+
if (free < 0) {
116+
err = -ENOMEM;
117+
goto out;
118+
}
119+
114120
mlx4_dbg(dev, "Free MAC index is %d\n", free);
115121

116122
if (table->total == table->max) {
@@ -205,6 +211,11 @@ int mlx4_register_vlan(struct mlx4_dev *dev, u8 port, u16 vlan, int *index)
205211
}
206212
}
207213

214+
if (free < 0) {
215+
err = -ENOMEM;
216+
goto out;
217+
}
218+
208219
if (table->total == table->max) {
209220
/* No free vlan entries */
210221
err = -ENOSPC;

0 commit comments

Comments
 (0)