Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp4065806pxb; Mon, 4 Oct 2021 16:37:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/mGbL4V7/bf73DlzjJ2FPkwaQK35WQnNXuybIykHx9JoJoHhYRlMSXZIdfsB6HF+wdL+a X-Received: by 2002:a17:907:7fa8:: with SMTP id qk40mr20444334ejc.445.1633390649292; Mon, 04 Oct 2021 16:37:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633390649; cv=none; d=google.com; s=arc-20160816; b=EPNcxg/ixTXKhhRfyBjW7lj8Ebp6ZIH7d8jAha9oIZDNdp6j+HKpLFsin+SCh6fwUM MTz17d3buPXWMH8vCRnCV4Nyv4tTyjwiZHF2czY1Qd3qC2NIgXEWQsF5drqO+FiYHxMP iSJ3O8BFruk2tMRt0IlirJWTy300620RT7rKrJndQDvHDJ0lKVMG3DLp2a0HzJybSL5p 3V642uTrW3ffKBbn/25H41XP1b8V/FOxjqUJnv77QDEy1vtw2/0sC4P99IompdCrJrDx o6P83JhjPPuHteXdBZ/Bl/IIgi1zoA+BGpmmqx97bgn2Ek3XdkZcxxhBeiiDxIi4nnTl Psfg== 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=PaA9Rhc6H9AkJf70hEfMmZwqELUUZIqr60dCxW4plpQ=; b=pmWTGwmuYNWS8t9R53VlG7mQw2lrIQHbS9yvToSSPeBP2okgmbeOIiTpV2BFR/dIIf +xKCS/6jOqmksZ5nZ3/ZkKRrjqfKaOYp4LoCBVQdqZpW1yxn2uXsltC8ewLliZ11jA4N VxW40Ecytv/cStybRReqDE5MUv11SKoVL6A0SpkJNN0SzFp64IR6trglmB0DIVKH8WOh vrS5l98ivoyzKXzC0jwmaqYwuJPtMfSXgamFdQntyIS3nM/UWMS+U8C7wQiPIZ4cX6HZ lMR20r3jDkxIg56IpaqdYl2HLjOlXGyzyRxMuA0zxy63pw6XvQZMJ2NyPqQ84nVRFFek Necw== 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 lv23si14468759ejb.649.2021.10.04.16.37.06; Mon, 04 Oct 2021 16:37:29 -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 S239002AbhJDT3k (ORCPT + 99 others); Mon, 4 Oct 2021 15:29:40 -0400 Received: from relay02.th.seeweb.it ([5.144.164.163]:40701 "EHLO relay02.th.seeweb.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238930AbhJDT3i (ORCPT ); Mon, 4 Oct 2021 15:29:38 -0400 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 85F901F6A2; Mon, 4 Oct 2021 21:27:47 +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 05/10] backlight: qcom-wled: Fix off-by-one maximum with default num_strings Date: Mon, 4 Oct 2021 21:27:36 +0200 Message-Id: <20211004192741.621870-6-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 When not specifying num-strings in the DT the default is used, but +1 is added to it which turns wled3 into 4 and wled4/5 into 5 strings instead of 3 and 4 respectively, causing out of bounds reads and register read/writes. This +1 exists for a deficiency in the DT parsing code, and is simply omitted entirely - solving this oob issue - by allowing one extra iteration of the wled_var_cfg function parsing this particular property. Fixes: 93c64f1ea1e8 ("leds: add Qualcomm PM8941 WLED driver") Signed-off-by: Marijn Suijten Reviewed-by: AngeloGioacchino Del Regno --- drivers/video/backlight/qcom-wled.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/video/backlight/qcom-wled.c b/drivers/video/backlight/qcom-wled.c index 27e8949c7922..66ce77ee3099 100644 --- a/drivers/video/backlight/qcom-wled.c +++ b/drivers/video/backlight/qcom-wled.c @@ -1255,17 +1255,17 @@ static const struct wled_var_cfg wled5_ovp_cfg = { static u32 wled3_num_strings_values_fn(u32 idx) { - return idx + 1; + return idx; } static const struct wled_var_cfg wled3_num_strings_cfg = { .fn = wled3_num_strings_values_fn, - .size = 3, + .size = 4, /* [0, 3] */ }; static const struct wled_var_cfg wled4_num_strings_cfg = { .fn = wled3_num_strings_values_fn, - .size = 4, + .size = 5, /* [0, 4] */ }; static u32 wled3_switch_freq_values_fn(u32 idx) @@ -1520,8 +1520,6 @@ static int wled_configure(struct wled *wled) *bool_opts[i].val_ptr = true; } - cfg->num_strings = cfg->num_strings + 1; - string_len = of_property_count_elems_of_size(dev->of_node, "qcom,enabled-strings", sizeof(u32)); -- 2.33.0