Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3277016pxj; Tue, 11 May 2021 00:19:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwJ3MWcQ9p8+Ux7B/qwvbn8bC78+UeI4Y0GlcKawqN4SckWfBNhsmVDdM2eI/4lGkOc+2l X-Received: by 2002:a6b:f808:: with SMTP id o8mr21602407ioh.140.1620717581599; Tue, 11 May 2021 00:19:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620717581; cv=none; d=google.com; s=arc-20160816; b=eP91CWqiM5ocYaQNGGcIXxgHjSsUKRLzGRLvcnFriYaf9xzpbr1BotEtZ2cwvZBriW QFZYycG+XNUY825HhpblJRUQdYzIaT0of9an5vUn8d4jksEhPapiTZ3m4xSzXpIIpniX M6UGDPUqA4G+MevbJFADKA+KjzQmxjszB870dr6+LE37nh0VpTIQMZSo8Rfpy35FBFEd mSCqKaim2QguWtWBJeX6fk+8HHR66Ox46JbCo17v1VyQQx4D5GCSHT6iM+xo0juVdbfT xs5wYDXfCLhkLKXxuHqvUQR4nnDhkkcSQvOp895zwJujGx4RonXsclE2Facjbf0XVjVK xE/w== 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 :dkim-signature; bh=MlVahHcRzJl/OmCKvY8N8NXLgxaRCwf7xRO5a1v6DG4=; b=vR+V3VE3r2Sj4ogsLo0o4KNcYLkrVOv5CphiIpd6QWVvSRXbIx/0uTfOIfmwq1/ixw p8uG8xtDRFpUIDAmzTZYFluklMRFylcEj2rzd1aKxnO5luba6Hey9CgvJxWNlKlIEd/j Xl3bcMxN39qlnBuvHloNVYZoLmJdttyPczeAbiXIPpwN10HkjDvX2FpBSUbLJo93/V7T CI21fA46AojARAU7VHodP0gja0ZnGOVOyB7t7MDmduoM5uOEkQwkm73fky9kojk/Rsfo qyprOTptwmeZVHm5hTXBroHUsVXJh0hqmyMaSIkbRv2T2ug8TGsJwiRHrD1UVzcLH13a h42Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b=BtT9If2o; 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=deviqon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n3si22127173ioh.98.2021.05.11.00.19.29; Tue, 11 May 2021 00:19:41 -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=@deviqon.com header.s=google header.b=BtT9If2o; 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=deviqon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230503AbhEKHTv (ORCPT + 99 others); Tue, 11 May 2021 03:19:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230375AbhEKHTp (ORCPT ); Tue, 11 May 2021 03:19:45 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9080FC061574 for ; Tue, 11 May 2021 00:18:38 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id n2so28231312ejy.7 for ; Tue, 11 May 2021 00:18:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MlVahHcRzJl/OmCKvY8N8NXLgxaRCwf7xRO5a1v6DG4=; b=BtT9If2o8biK/TQo2D8iH5bLbUNr2OSpCmPrMkG7+9NX0wPnU577xaNxF6GxpWPkOT WcKmoisQKH7iGLvW+j2yD81ooRu/VTCEhGr/WKvQjpREbjgAQvalT9/lo1e6DxHwruW9 JwUH9rcmjoEv4hANcCcOj/Pi2fEJjHICQISZ0bOX7RJO2Ydnp+zhGoHwjNGhZUdLfX7u G6EHOORr98nJSTWOj2OT+TjSgqD3kLDlfGpDmEf9QKjk02vacPFrNKsL2nguL2ZvSThb SJeKYo34GoQcDorGwmJvL1CUz2mMoBdtITAoUEud3dPiF1rnhXqDNIag/X5TuDeKKRWN 7YfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MlVahHcRzJl/OmCKvY8N8NXLgxaRCwf7xRO5a1v6DG4=; b=Rd/pp6R41WnXHef43rfA8eaqYOfzpKFlLsVO+0q+HGlPyfJSzVs0U+eczat10WeHZ7 aKlWdaFaJNepA3hN9lmDFyZeGuUYeUj1Ek+gzKmrAfmMNdqEXgxLLyqKjk/DWYkSgZwc SsthCap/lk3cdAgIbQU2EpWgVrAcny3wA19Q7zC3xDbXRkuz1RxLL6D2tQdkxeR1trCE 3eo9wo+wG5nvE12syB9ygkOpRqT0hF17xI9WopzKrVROFHihB8rkez4V5M8prX/GcCY9 ykvoHfSCwDTvs0LDVnCpahaQp4MSoyQ3l3YGgzMmpdMkUOnuf0z6tOYiVGvMlyjPN7vW bUgw== X-Gm-Message-State: AOAM530rTnIu0FI+e0W9ZbSnsTS437427V3lnvsZLkWbg+KZe12jZw3k QV6uKNjGsUvvz+S9GTXqWG8VXw== X-Received: by 2002:a17:906:2da1:: with SMTP id g1mr30189831eji.47.1620717517277; Tue, 11 May 2021 00:18:37 -0700 (PDT) Received: from neptune.. ([188.27.131.122]) by smtp.gmail.com with ESMTPSA id i6sm13871558eds.83.2021.05.11.00.18.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 00:18:37 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, Jonathan.Cameron@huawei.com, alexandru.tachici@analog.com, linux@deviqon.com, Alexandru Ardelean , Alexandru Ardelean Subject: [PATCH v2 02/12] iio: adc: ad7124: Fix potential overflow due to non sequential channel numbers Date: Tue, 11 May 2021 10:18:21 +0300 Message-Id: <20210511071831.576145-3-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210511071831.576145-1-aardelean@deviqon.com> References: <20210511071831.576145-1-aardelean@deviqon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jonathan Cameron 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. Fixes: d7857e4ee1ba6 ("iio: adc: ad7124: Fix DT channel configuration") Reviewed-by: Alexandru Ardelean Signed-off-by: Jonathan Cameron Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7124.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c index 437116a07cf1..a27db78ea13e 100644 --- a/drivers/iio/adc/ad7124.c +++ b/drivers/iio/adc/ad7124.c @@ -771,6 +771,13 @@ static int ad7124_of_parse_channel_config(struct iio_dev *indio_dev, 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) -- 2.31.1