From patchwork Thu Feb 19 08:40:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 5850681 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C513BBF440 for ; Thu, 19 Feb 2015 08:43:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0EF142027D for ; Thu, 19 Feb 2015 08:43:40 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 42C422017D for ; Thu, 19 Feb 2015 08:43:39 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YOMfn-0003iL-Kz; Thu, 19 Feb 2015 08:41:27 +0000 Received: from mail-we0-f175.google.com ([74.125.82.175]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YOMfi-0003a6-E6 for linux-arm-kernel@lists.infradead.org; Thu, 19 Feb 2015 08:41:23 +0000 Received: by wesq59 with SMTP id q59so5894310wes.1 for ; Thu, 19 Feb 2015 00:41:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=S7/sOS9lLCpsgSj7YjvgEqJSD/hTaXO3BS4xr+WrDyY=; b=etRQjpSS0Iz4W1VhQpbzbSrA91bTWyz9dHUE6WL1hENimxrL2I8ITWzaGv7jb70JSL GwQG7rHPq3xrLQCPfaYT5vUDGbHYko8aVyPqQHn2SKVev5maVqAfPJAPGyjjQpLz7J45 gkUOf+9K5ZuF/g8A4g41W9n1EkjLYJvCKfpl82x8jK2vmPp2AQ251Dia6B458Q6hNsDm a5NLJQIO4FdDu5aR4QpZuKqDQn6HrWKKThtH1sh1wUhFFvzvZZHQwKYBCYhW7FGDJcqJ ZqIxp6ah2SOlQRIgtBBl7gM5LvYw9NmkqQ6oG5YDNV2t/rsul2BodMrpTk2TWyZoEOrf O2Ow== X-Gm-Message-State: ALoCoQlzSe5bYLtnUFaKUUsmDcnaTWZD6+QqaSm8btUmedL3dWe/ZSN5rGnSMPplOI2g4IqckDuZ X-Received: by 10.180.188.41 with SMTP id fx9mr7857522wic.93.1424335260498; Thu, 19 Feb 2015 00:41:00 -0800 (PST) Received: from srini-ThinkPad-X1-Carbon-2nd.dlink.com (host-2-98-213-113.as13285.net. [2.98.213.113]) by mx.google.com with ESMTPSA id df8sm29151134wib.2.2015.02.19.00.40.59 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Feb 2015 00:40:59 -0800 (PST) From: Srinivas Kandagatla To: Mark Brown Subject: [PATCH 2/2] regmap: Add range check in _regmap_raw_write() Date: Thu, 19 Feb 2015 08:40:55 +0000 Message-Id: <1424335255-7517-1-git-send-email-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1424335193-7431-1-git-send-email-srinivas.kandagatla@linaro.org> References: <1424335193-7431-1-git-send-email-srinivas.kandagatla@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150219_004122_648770_D833E39A X-CRM114-Status: GOOD ( 14.92 ) X-Spam-Score: -0.7 (/) Cc: Greg Kroah-Hartman , Srinivas Kandagatla , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP regmap_bulk_write() ends up using the path that invokes _regmap_raw_write(), however _regmap_raw_write() never checks if the registers that are accessed are actually within the accessible range. This results in kernel crashes when trying to access registers beyond max_registers. This patch just adds check before accessing the register range. Signed-off-by: Srinivas Kandagatla --- drivers/base/regmap/regmap.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index d480e49..32ce7b3 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -1202,16 +1202,14 @@ int _regmap_raw_write(struct regmap *map, unsigned int reg, void *buf; int ret = -ENOTSUPP; size_t len; - int i; + int i, count = val_len/map->format.val_bytes; WARN_ON(!map->bus); /* Check for unwritable registers before we start */ - if (map->writeable_reg) - for (i = 0; i < val_len / map->format.val_bytes; i++) - if (!map->writeable_reg(map->dev, - reg + (i * map->reg_stride))) - return -EINVAL; + for (i = 0; i < count; i++) + if (!regmap_writeable(map, reg + (i * map->reg_stride))) + return -EINVAL; if (!map->cache_bypass && map->format.parse_val) { unsigned int ival;