Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp4436490pxb; Tue, 5 Oct 2021 03:07:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyuODsqGBYcGOiqfQdlJ4owJTybMcEzdCMduharcWlUCgLpVs3milyIBmzNEUUNBV6s5rn X-Received: by 2002:a05:6a00:238a:b0:44b:e2bb:e5ff with SMTP id f10-20020a056a00238a00b0044be2bbe5ffmr31183488pfc.14.1633428437984; Tue, 05 Oct 2021 03:07:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633428437; cv=none; d=google.com; s=arc-20160816; b=SAMrV+wWorkbtMZ7okfIfydmEwedI/ivayN5bfA75ZtrCXvh3Tzdw5ZTKigi/ahBEi kvHKB7FPU/8ickMHSQ91MtrjqFq6CHVCrrjF7Qt8puAuZJXN88IxZi4jDcyb9hAPwca/ 2etgU+H5YTqDOJTHK4FHo0KKDamcgIx+w0j3YNuYphzLNYbBt3vzs1+YjN4TKHcE5uh4 eYld79UCaeWY4Np0Af+QW2lC1XbdwNIRzD0xnSR9iK7l2QFiCZxBWvxr6Fv7s6tbhMI0 dw7o8JlVBf2zDluTQ+vt4qgKZKIgcroCYTIf93tCAbkSNgpS+Ekau8FfpX/vPhdHkBkM dhgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date; bh=7Yd/U89BNomtIyXcRzw9hwVG5HMwief1sN4Y8sqWwqQ=; b=TrdBSJtF0aLGW8s9z9d+YvJ/1oSQrZkfhOZKN+cRwoyA5P2qO6LOsSDIsPP/UOQXtd JTPDDotyihJ0+aNDCXXhIgCcNm+1tsH+fBIkKD0+R2YNJO23Fp3CumJvn0NoXSRmgpv6 3yRA3u1zQV+03yycZUYoHqV5oGNUsykbWEZM3X77NaGcb9Ojxs0R9Pgb44eevr/WvG/V wlz+5/2QvGOoAish24jCAdFnhHSrgRNoAF6NDJBdtYnhiNXrn65sQ6rT+M/WfkARcMPD pjTY1+jpntTgvmzlFH9V+ROalTc23DZ1dQ+U6INe5ZYvp/KDT8mumjT9W17bdcFsc4TO dnWw== 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 u1si21685578plh.344.2021.10.05.03.06.59; Tue, 05 Oct 2021 03:07:17 -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 S233825AbhJEKID (ORCPT + 99 others); Tue, 5 Oct 2021 06:08:03 -0400 Received: from relay05.th.seeweb.it ([5.144.164.166]:43233 "EHLO relay05.th.seeweb.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232658AbhJEKIA (ORCPT ); Tue, 5 Oct 2021 06:08:00 -0400 Received: from SoMainline.org (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 ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by m-r2.th.seeweb.it (Postfix) with ESMTPSA id C2A4E3EE89; Tue, 5 Oct 2021 12:06:07 +0200 (CEST) Date: Tue, 5 Oct 2021 12:06:06 +0200 From: Marijn Suijten To: Daniel Thompson Cc: phone-devel@vger.kernel.org, Andy Gross , Bjorn Andersson , Lee Jones , Jingoo Han , ~postmarketos/upstreaming@lists.sr.ht, AngeloGioacchino Del Regno , Konrad Dybcio , Martin Botka , Jami Kettunen , Pavel Dubrova , 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: Re: [PATCH 05/10] backlight: qcom-wled: Fix off-by-one maximum with default num_strings Message-ID: <20211005100606.faxra73mzkvjd4f6@SoMainline.org> Mail-Followup-To: Daniel Thompson , phone-devel@vger.kernel.org, Andy Gross , Bjorn Andersson , Lee Jones , Jingoo Han , ~postmarketos/upstreaming@lists.sr.ht, AngeloGioacchino Del Regno , Konrad Dybcio , Martin Botka , Jami Kettunen , Pavel Dubrova , 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 References: <20211004192741.621870-1-marijn.suijten@somainline.org> <20211004192741.621870-6-marijn.suijten@somainline.org> <20211005091947.7msztp5l554c7cy4@maple.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211005091947.7msztp5l554c7cy4@maple.lan> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-10-05 10:19:47, Daniel Thompson wrote: > On Mon, Oct 04, 2021 at 09:27:36PM +0200, Marijn Suijten wrote: > > 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] */ > > 0 is not a valid value for this property. These comments represent the possible loop iterations the DT "cfg parser" runs through, starting at j=0 and running up until and including j=3. Should I make that more clear or omit these comments entirely? - Marijn > > }; > > > > static const struct wled_var_cfg wled4_num_strings_cfg = { > > .fn = wled3_num_strings_values_fn, > > - .size = 4, > > + .size = 5, /* [0, 4] */ > > Ditto. > > > > }; > > > > 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 > >