Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3913556pxb; Mon, 4 Oct 2021 12:29:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPgk3Nuv46qBancXL3Z2w938Q2XOSkUVXmlOqyxKpkRXpJ3sozQqHLJPlN16OGtv4QGKli X-Received: by 2002:a17:90b:4d87:: with SMTP id oj7mr7937686pjb.107.1633375779801; Mon, 04 Oct 2021 12:29:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633375779; cv=none; d=google.com; s=arc-20160816; b=rl3HWWiM06NKmZGpIfkliCFYXCBn6532OB9+jEr9NrWa2xvIQaByyMUdf78oJi2Gpk EK1/kCUczabzSH90qBYYEvNHV4uUjSCdRevQNHIw8zQ4XedpfWkGz5ujqMcI0CmGX/aZ FTeAWHUw3puH0sdWww552hwrQIPSGxXsqufu3JLH38L6xXCX4kbobzTKBxxm9LEn+LBH LoeC/MGrZM6tFAg42Kks6ql3fiQrnZlGFxQb37rU6jRpg0ASkRUtNqNfdytf+d6S1Uq5 80bOy3pw7e6N57ZLdADUGH1sCmvPyEe5yG4zXy5so1BG1ry2JkPj3G36Y6Ako6Ebhqv6 1u1w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=uqVDfSkOLrTyg95E6RWZqJHNSayQiAXQ8DT0OXz+y6A=; b=RvnLXVWDyT1VjbNbXPAsOcMD5bmWtFgvlKO5Cxj+w+NgtIO/7p6cVfyDPMnCstKE3V O9PtltB6c8nGRJ5G3VVfkaajX2sbGu9D1/RN9vbvcExnueiQd0pn8aYupMkA3pRSh4nm CANwLp3mFFUX8toyb95jmdNyXLp+/EUQ+npQnt3duJb96yqZSY7wS/B5zKXUeEf32ojM FjFyZaMW9kv97llTNQ7sZqTYDpl+dzz7Ldn0dkaZxovqeE4DiwEboFFbDViYVD4lPn3N OOaEiKuI65rrIfzW+hHbNJN/w0NNyUZGs5MsuoJYQ3rNzFf3cHW2JXngfEaEWHOb2roE X85A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 10si20693415pfl.358.2021.10.04.12.29.26; Mon, 04 Oct 2021 12:29:39 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238943AbhJDT3j (ORCPT + 99 others); Mon, 4 Oct 2021 15:29:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238942AbhJDT3i (ORCPT ); Mon, 4 Oct 2021 15:29:38 -0400 Received: from relay01.th.seeweb.it (relay01.th.seeweb.it [IPv6:2001:4b7a:2000:18::162]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7331C061749; Mon, 4 Oct 2021 12:27:48 -0700 (PDT) Received: from Marijn-Arch-PC.localdomain (94-209-165-62.cable.dynamic.v4.ziggo.nl [94.209.165.62]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by m-r1.th.seeweb.it (Postfix) with ESMTPSA id 9D6AD1F691; Mon, 4 Oct 2021 21:27:46 +0200 (CEST) From: Marijn Suijten To: phone-devel@vger.kernel.org, Andy Gross , Bjorn Andersson , Lee Jones , Daniel Thompson , Jingoo Han Cc: ~postmarketos/upstreaming@lists.sr.ht, AngeloGioacchino Del Regno , Konrad Dybcio , Martin Botka , Jami Kettunen , Pavel Dubrova , Marijn Suijten , Kiran Gunda , Courtney Cavin , Bryan Wu , linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 04/10] backlight: qcom-wled: Validate enabled string indices in DT Date: Mon, 4 Oct 2021 21:27:35 +0200 Message-Id: <20211004192741.621870-5-marijn.suijten@somainline.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004192741.621870-1-marijn.suijten@somainline.org> References: <20211004192741.621870-1-marijn.suijten@somainline.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/video/backlight/qcom-wled.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/video/backlight/qcom-wled.c b/drivers/video/backlight/qcom-wled.c index 29910e603c42..27e8949c7922 100644 --- a/drivers/video/backlight/qcom-wled.c +++ b/drivers/video/backlight/qcom-wled.c @@ -1526,6 +1526,12 @@ static int wled_configure(struct wled *wled) "qcom,enabled-strings", sizeof(u32)); 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; + } + rc = of_property_read_u32_array(dev->of_node, "qcom,enabled-strings", wled->cfg.enabled_strings, @@ -1537,6 +1543,14 @@ static int wled_configure(struct wled *wled) return -EINVAL; } + 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; + } + } + cfg->num_strings = string_len; } -- 2.33.0