Skip to content

Commit

Permalink
Merge branch 'phy-ocelot-serdes-fix-out-of-bounds-read'
Browse files Browse the repository at this point in the history
Gustavo A. R. Silva says:

====================
phy: ocelot-serdes: fix out-of-bounds read

This patchset aims to fix an out-of-bounds bug in
the phy-ocelot-serdes driver.

Currently, there is an out-of-bounds read on array ctrl->phys,
once variable i reaches the maximum array size of SERDES_MAX
in the for loop.

Quentin Schulz pointed out that SERDES_MAX is a valid value to
index ctrl->phys. So, I updated SERDES_MAX to be SERDES6G_MAX + 1
in include/dt-bindings/phy/phy-ocelot-serdes.h.

Then I changed the condition in the for loop from
i <= SERDES_MAX to i < SERDES_MAX in order to
complete the fix.

The reason I'm sending this fix as series is because
checkpatch reported an error when I first tried to
integrate the whole solution into a singe patch. So,
changes to dt-bindings should be sent as a separate
patch.

Changes in v3:
 - Post the series to netdev, so Dave can take it.

Changes in v2:
 - Send the whole series to Kishon Vijay Abraham I, so it
   can be taken into the PHY tree.
 - Add Quentin's Reviewed-by to commit log in both patches.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Oct 23, 2018
2 parents 29e270f + 6acb47d commit 627d39c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions drivers/phy/mscc/phy-ocelot-serdes.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ static struct phy *serdes_simple_xlate(struct device *dev,
port = args->args[0];
idx = args->args[1];

for (i = 0; i <= SERDES_MAX; i++) {
for (i = 0; i < SERDES_MAX; i++) {
struct serdes_macro *macro = phy_get_drvdata(ctrl->phys[i]);

if (idx != macro->idx)
Expand Down Expand Up @@ -260,7 +260,7 @@ static int serdes_probe(struct platform_device *pdev)
if (IS_ERR(ctrl->regs))
return PTR_ERR(ctrl->regs);

for (i = 0; i <= SERDES_MAX; i++) {
for (i = 0; i < SERDES_MAX; i++) {
ret = serdes_phy_create(ctrl, i, &ctrl->phys[i]);
if (ret)
return ret;
Expand Down
2 changes: 1 addition & 1 deletion include/dt-bindings/phy/phy-ocelot-serdes.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
#define SERDES1G_MAX SERDES1G(5)
#define SERDES6G(x) (SERDES1G_MAX + 1 + (x))
#define SERDES6G_MAX SERDES6G(2)
#define SERDES_MAX SERDES6G_MAX
#define SERDES_MAX (SERDES6G_MAX + 1)

#endif

0 comments on commit 627d39c

Please sign in to comment.