Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3629273pxb; Mon, 24 Jan 2022 13:55:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJw0cy6uF2igFd8dH7aIzMQpJtXLUrTIx/ecQIjWagiQ5K3Z+/zfCxBGqJsWZtCSesHTyXZR X-Received: by 2002:a17:902:a9c3:b0:14b:63db:aef5 with SMTP id b3-20020a170902a9c300b0014b63dbaef5mr3069089plr.86.1643061334941; Mon, 24 Jan 2022 13:55:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643061334; cv=none; d=google.com; s=arc-20160816; b=Fcl4dcRLwPpIrlLsu0mhAD1+yz65517Fc3jFy781FYC9k+0U4nQICXIWUjY6CM5Dva N/OHpjapSGRMw1iDZtMp7024MXg4f79f+1qX9rs+eNoDMSGG04kA3Fcu3LJ/GTYG353M gubpjbCNqYNy7Fyrxvb6tOWbo56uVDw5NpDut1L7eI/mgXlpTdvbz3ExL7ljthJJ6MvB 5J1Ggpj6s/T4+1Z7uO/lW5F5c9f4Fs1tz+ZGFxOmzsqE0/S+eXCJp9B0sccr4I04DpWn AhF1LQ+OLojTeDctjV7k0TzUsjzn3ZytdlxV6AWJSgDNke/OavlyS+ZgR4ScydOEUC0X ZvDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Bxxsr69QwCb5urwNQ7jigkc41vO4FOfHh0aA914p9ZE=; b=mkDXHcACEWfGJmmBI4gYSjQ5YkpvkaqRspmG9s2o+CJ93p7Jd8R4FV4U1GjXnMwEmR dgrN86kOnIUilJXLidKf0gNe6gI6MuSDU7VLpUtSYfLqx6TZk2/WaqZFPYQ6J7Zyqlao IDpE3xJTuA1lVlH7H5zBqD8wNLwLIxg+BemAGdRSSZSOWY2zpmd8SRuq8kxUl4bkUmi+ 8ZvgE/paw//Yk48CLLh/JdtqwTeq1typmQvM4ZaG5wrJQlzetmqHkN8xohKWFBXPtci3 XV8+RkgF8MNYRszxQzvXpXw/MY0qKA6RMuXCl7nI8gtTuuNPKXE8EAOa7flLaLX2G7qY mbhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Wr8FMdTX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 193si4110775pgc.216.2022.01.24.13.55.23; Mon, 24 Jan 2022 13:55:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Wr8FMdTX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1445466AbiAXVng (ORCPT + 99 others); Mon, 24 Jan 2022 16:43:36 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:33946 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1447166AbiAXVKH (ORCPT ); Mon, 24 Jan 2022 16:10:07 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A13456148B; Mon, 24 Jan 2022 21:10:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82EACC340EC; Mon, 24 Jan 2022 21:10:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058606; bh=0uJHedN80f2xLTdruQW7Fj+OFcuWMBzE4MqBNcSaJxI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wr8FMdTXPyGbkmagPzh6rL/VaMxXGw8dFIkkaOc9AeMmkedRfmK5TAsYnVNY2mFW5 i4ncaISXwTJ2k4506V1s19cEXdJFvUXD2mRf2iWcUfRCrf9zLlGylCUS6luZL+GlHv 48eUzdbbR7OST0ze8zoxPvKiVI8Dm1cAk/l4hSEw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marijn Suijten , AngeloGioacchino Del Regno , Daniel Thompson , Lee Jones , Sasha Levin Subject: [PATCH 5.16 0344/1039] backlight: qcom-wled: Validate enabled string indices in DT Date: Mon, 24 Jan 2022 19:35:33 +0100 Message-Id: <20220124184136.861020501@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marijn Suijten [ Upstream commit c05b21ebc5bce3ecc78c2c71afd76d92c790a2ac ] The strings passed in DT may possibly cause out-of-bounds register accesses and should be validated before use. Fixes: 775d2ffb4af6 ("backlight: qcom-wled: Restructure the driver for WLED3") Signed-off-by: Marijn Suijten Reviewed-by: AngeloGioacchino Del Regno Reviewed-by: Daniel Thompson Signed-off-by: Lee Jones Link: https://lore.kernel.org/r/20211115203459.1634079-2-marijn.suijten@somainline.org Signed-off-by: Sasha Levin --- drivers/video/backlight/qcom-wled.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/video/backlight/qcom-wled.c b/drivers/video/backlight/qcom-wled.c index d094299c2a485..8a42ed89c59c9 100644 --- a/drivers/video/backlight/qcom-wled.c +++ b/drivers/video/backlight/qcom-wled.c @@ -1528,12 +1528,28 @@ static int wled_configure(struct wled *wled) string_len = of_property_count_elems_of_size(dev->of_node, "qcom,enabled-strings", sizeof(u32)); - if (string_len > 0) + if (string_len > 0) { + if (string_len > wled->max_string_count) { + dev_err(dev, "Cannot have more than %d strings\n", + wled->max_string_count); + return -EINVAL; + } + of_property_read_u32_array(dev->of_node, "qcom,enabled-strings", wled->cfg.enabled_strings, sizeof(u32)); + for (i = 0; i < string_len; ++i) { + if (wled->cfg.enabled_strings[i] >= wled->max_string_count) { + dev_err(dev, + "qcom,enabled-strings index %d at %d is out of bounds\n", + wled->cfg.enabled_strings[i], i); + return -EINVAL; + } + } + } + return 0; } -- 2.34.1