Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3654748pxb; Mon, 24 Jan 2022 14:33:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJxY+g48/ckL66WiK13xzIcL8ymLfl8LE9iqxv9ytG+YHM6jWLkMcnO12z13HZy10y82ulri X-Received: by 2002:a17:903:11d1:b0:149:57d1:acc6 with SMTP id q17-20020a17090311d100b0014957d1acc6mr15935972plh.134.1643063580450; Mon, 24 Jan 2022 14:33:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643063580; cv=none; d=google.com; s=arc-20160816; b=RY0wN5zimV0tHLW3xffbhmT3bsiwdKsEzF627wWJKjIjziAMggWuncNZ4EhLBThn+T Ti7BDm5+V9iGsYswBg2Plt4O4H4MwiU8Ffom0pgRhyjdTvBz43Ga1y1n+spUtzn3imRd jYqLS0sR6WzeiEZHrcI+R71Z4ZB3ih09qYKnAAUYMTrhwIk6oL8bWMKsR0Zc/Z0FkLc6 J5QOBr5YhFZ9X+1vGIyB6Nz2uXm5Wr07oOe7xs0SvRPq93E0pxYNnRewXzjThgRW1GO8 LpQlR2zbjIg/VSvMP3SrIyeLT9DXAkoIySjI2QasVtCVYwZCASUFPv+K+UlNGq3GeBgi HwyQ== 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=KW+Ekyh8YBXAufXSjN/HrJ6/ymYDbe40LMT8LhLMqSOEM+7xePLA8FYkzLhjttjkJf 4Olu6MBncm+Ml3Eacu7AqY6roxsnBAzNf825+TMutOZmtVvZNpa1CCGQ2mo+o6mFKpo4 qjFZkJiWccMLFXLg4s4qvE1eK8rNr5P9cGe6B53hGwKN1jhkzRj4mE3tM+1jbuBX3WEu ls567H3BDsJBz9qfg4LE9FEynVFE4Mof7+UQ4O+E0DdkR2pFaSbwgud5k03V0VUTVZK3 xKnrDlM6BosdO5xtzjLwt8r7o5PaTaoPhBl6W+aEvcuN7kXzAPH//cIniVsRiiRlijri hkCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ATReQQf3; 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 h27si13959285pgl.732.2022.01.24.14.32.47; Mon, 24 Jan 2022 14:33:00 -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=ATReQQf3; 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 S1352005AbiAXWau (ORCPT + 99 others); Mon, 24 Jan 2022 17:30:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1456423AbiAXVjT (ORCPT ); Mon, 24 Jan 2022 16:39:19 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03DC9C034003; Mon, 24 Jan 2022 12:24:16 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id B572DB8122D; Mon, 24 Jan 2022 20:24:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E11E2C340E5; Mon, 24 Jan 2022 20:24:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643055853; bh=0uJHedN80f2xLTdruQW7Fj+OFcuWMBzE4MqBNcSaJxI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ATReQQf3vEqUlPZVmppNZqvWqwovWgfKOQU7MFqEI0EWmtHysvTLw/q6VjwD05cvw qckEqB/w3Ivq62kB4jymRqeQBNXJH7pHwtuSR8ApssNBmaHRJ+mLpnCpEMTwfzrwd+ Q/1cHLpepdIpn6tWZ8gBhKSzR3KXjWRN17U0hldA= 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.15 286/846] backlight: qcom-wled: Validate enabled string indices in DT Date: Mon, 24 Jan 2022 19:36:43 +0100 Message-Id: <20220124184110.787654678@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@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