Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3888404imm; Mon, 8 Oct 2018 11:09:30 -0700 (PDT) X-Google-Smtp-Source: ACcGV62kSYyTcdLB4OqP8jM/KrMguPLPOL4W2fyPzNZMN5Tuqm4a57uDojrxKOQ/Gglskj4qc3/p X-Received: by 2002:a17:902:9b89:: with SMTP id y9-v6mr25119614plp.239.1539022169949; Mon, 08 Oct 2018 11:09:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539022169; cv=none; d=google.com; s=arc-20160816; b=ScqcyKBdZQhB1upCmfLee1EQnhQv9o85aD6JvmKT8DYuy/ZeIwpNFp1SE/zno0aI9h zug4yWBOprvRG8IKReazFHdcdFXgmtYLseKjwlslp91toDN9jer43YiNlSq1jlt8IO2m Xtrn0dDbqY0Zievh8uX3bchNRvMru/4xBoSL1381iIy8G57xR7DrtGcvFbVS6F+RYZGM hjibkfXw2Ov06+CmOE1ROB+DqS6i3B8TwPtaYvrvifsTmYdTrdwZSz8WRXm3LS+RnRDd tGH3Qz8YT8TputFsV3HNHfP+Fn64YWamumhr/3Dp9bUlvkCDjF+PabqkgekohQG+Rtbm 68NA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date; bh=Y0cAkYWFzcGB6/6zvuN8YBYtAUk5AOscc+3R6YF7zrE=; b=eBZUQD3f4ywHJxPQYadhKB7N5QT2S50EXPTKjTJbreNqEsVin44n2s9URKa8Wo4FPL ZlMdzQU4YMGdiMuFuiiyESIrUkS7X4Nh6z9Jqth2+VG8WwJTmuuHpGTQYsQ5vEqcjDD+ yvv59mqWICh85rYUyhTXdoJmF9zmkZOPegrYqk6uD52DnX20Lw2aemPJOxULMaJQraR/ aflv9PYHMKSQsD06QpO4aEujO8CbUuolbL4tK84EpRn6NnTQ6BgP+3x/aIPw4xVdhb1R Xwr41y8XiKkcnqvR7xeHN1uEUfYVQCPLPnJ58K+WxnxgQRxmTSYOA885l6Np6+ZkuA6a aAJw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v13-v6si18248478plo.182.2018.10.08.11.09.14; Mon, 08 Oct 2018 11:09:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726775AbeJIBUO (ORCPT + 99 others); Mon, 8 Oct 2018 21:20:14 -0400 Received: from gateway31.websitewelcome.com ([192.185.143.234]:18970 "EHLO gateway31.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726291AbeJIBUO (ORCPT ); Mon, 8 Oct 2018 21:20:14 -0400 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway31.websitewelcome.com (Postfix) with ESMTP id C90A2B79A for ; Mon, 8 Oct 2018 13:07:18 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id 9Zvfg5k57BcCX9ZvugOtty; Mon, 08 Oct 2018 13:07:18 -0500 X-Authority-Reason: nr=8 Received: from 174.206.93.92.rev.sfr.net ([92.93.206.174]:47794 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.91) (envelope-from ) id 1g9Zvf-003zBm-5P; Mon, 08 Oct 2018 13:06:51 -0500 Date: Mon, 8 Oct 2018 20:06:49 +0200 From: "Gustavo A. R. Silva" To: Kishon Vijay Abraham I , Quentin Schulz , "David S. Miller" Cc: linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH] phy: ocelot-serdes: fix out-of-bounds read Message-ID: <20181008180649.GA9152@embeddedor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 92.93.206.174 X-Source-L: No X-Exim-ID: 1g9Zvf-003zBm-5P X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 174.206.93.92.rev.sfr.net (embeddedor) [92.93.206.174]:47794 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 4 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Fix this by changing the condition in the for loop from i <= SERDES_MAX to i < SERDES_MAX. Addresses-Coverity-ID: 1473966 ("Out-of-bounds read") Addresses-Coverity-ID: 1473959 ("Out-of-bounds read") Fixes: 51f6b410fc22 ("phy: add driver for Microsemi Ocelot SerDes muxing") Signed-off-by: Gustavo A. R. Silva --- drivers/phy/mscc/phy-ocelot-serdes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/phy/mscc/phy-ocelot-serdes.c b/drivers/phy/mscc/phy-ocelot-serdes.c index 8936abd..c4eee3a 100644 --- a/drivers/phy/mscc/phy-ocelot-serdes.c +++ b/drivers/phy/mscc/phy-ocelot-serdes.c @@ -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) @@ -260,7 +260,7 @@ static int serdes_probe(struct platform_device *pdev) if (!ctrl->regs) return -ENODEV; - 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; -- 2.7.4