Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2652183pxj; Mon, 31 May 2021 07:26:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGJAofQgp0kwNuIZb4M66CLmHGuR3fjoRlFZ44Z3Kyss1tapmvdQf0I4sA1OmkVejgT/HI X-Received: by 2002:a6b:cf13:: with SMTP id o19mr11312360ioa.206.1622471184304; Mon, 31 May 2021 07:26:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622471184; cv=none; d=google.com; s=arc-20160816; b=wWwkprzehs1Ae2QQCbry3uPJRKbEDqDkHUR0QGhtXAk3JjQDurCoOn6etU99BXfeGI E0+Rs7A8HPv3/hpj6pKw669Xrkr8A1n2jNyyPjaDUkDruvwaEfc/pXs5o7EybwA77ScP MEGdkMEhVEPBhJ59fyj1YFpsEbesIzsufAziwZ+mtw4E4wiVanCQMwgPifhTX+ojkSOw IZynYzIRVMHK50FUfLNazE2Rpj0nHON2C5Ydl+ygEJJJItsxhVfeRvIhPic+eUbep9cy w18hbNUkxS2U67ZYdH1uFyP4CghAty9bWhkCOMKsCvHK1F4rVXhwurjfk1vYUEYCHWMz KjUQ== 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=deyEw6ZO+idsFQvhGiFL0SYfrRvvHofJsytmTovNrXo=; b=aD0Wt7d6cx8IYitiEKa/tsrBp4QIKKkkY5hh10T6+7AxZVrmXb2ArHZUQ+FtRB6TbL /pcaLKx0wt67zTL/cZUAqsGsud+9UYJP7jlG5mi7MRg5FWXXh91BdObNZISZXWDi6NmZ K4XDsCiThLcHE98Bp4k7BSKXqdYWlJ0WF5VYIpTHzg8wBgrlAfHes60Uu6eMeOTQh/km nxfB2HkxInZjhY4jtteJhEoEcO4ciwZMKBrhKQozFIF0akMFtH1vvcpOLVaqTAPF0r1y hmgCaHcNY3z2O6IQaomHtjAqVOdTbPnqXonFaiOEq2i9rl/7Z11zOxY1vZkP6rkWWenQ +kjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JClpubnk; 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 t2si10522586ilo.160.2021.05.31.07.26.11; Mon, 31 May 2021 07:26:24 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JClpubnk; 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 S232591AbhEaO1I (ORCPT + 99 others); Mon, 31 May 2021 10:27:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:55412 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232540AbhEaNvv (ORCPT ); Mon, 31 May 2021 09:51:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E3A5C616E9; Mon, 31 May 2021 13:32:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622467962; bh=Xdmu0No1qD89vu5RbDro4R5XL0d4XQoB0rtetHFaD4I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JClpubnkwpZu9a8XdEDS/Dk+cQBcP1l3HiVHtFKrRnnh+qARk7mt75GqHbrgXSIvB HwNfWrlZfYblMuU0mEexuTJt7W1P/68wIZ/j/B+HodSiPZsAo9eyn1ryCWp90pKMWG WTgfbi4QrYHjoVSunX6pil09VRCpWvbY6///nF7s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexandru Ardelean , Jonathan Cameron , Alexandru Ardelean , Stable@vger.kernel.org Subject: [PATCH 5.10 065/252] iio: adc: ad7124: Fix potential overflow due to non sequential channel numbers Date: Mon, 31 May 2021 15:12:10 +0200 Message-Id: <20210531130700.196502617@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130657.971257589@linuxfoundation.org> References: <20210531130657.971257589@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: Jonathan Cameron commit f2a772c51206b0c3f262e4f6a3812c89a650191b upstream. Channel numbering must start at 0 and then not have any holes, or it is possible to overflow the available storage. Note this bug was introduced as part of a fix to ensure we didn't rely on the ordering of child nodes. So we need to support arbitrary ordering but they all need to be there somewhere. Note I hit this when using qemu to test the rest of this series. Arguably this isn't the best fix, but it is probably the most minimal option for backporting etc. Alexandru's sign-off is here because he carried this patch in a larger set that Jonathan then applied. Fixes: d7857e4ee1ba6 ("iio: adc: ad7124: Fix DT channel configuration") Reviewed-by: Alexandru Ardelean Signed-off-by: Jonathan Cameron Signed-off-by: Alexandru Ardelean Cc: Signed-off-by: Greg Kroah-Hartman --- drivers/iio/adc/ad7124.c | 7 +++++++ 1 file changed, 7 insertions(+) --- a/drivers/iio/adc/ad7124.c +++ b/drivers/iio/adc/ad7124.c @@ -616,6 +616,13 @@ static int ad7124_of_parse_channel_confi if (ret) goto err; + if (channel >= indio_dev->num_channels) { + dev_err(indio_dev->dev.parent, + "Channel index >= number of channels\n"); + ret = -EINVAL; + goto err; + } + ret = of_property_read_u32_array(child, "diff-channels", ain, 2); if (ret)