Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2570677pxj; Mon, 10 May 2021 06:09:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhnSsXc1EqeG6+CALdqUgdLO6ZBWunZ/0dyU1eq2VFcKFqb6lncmKjTF4CMd69eTPSmkw3 X-Received: by 2002:aa7:c789:: with SMTP id n9mr29804701eds.352.1620652164515; Mon, 10 May 2021 06:09:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620652164; cv=none; d=google.com; s=arc-20160816; b=HS/93ypIPcIjQJ1AuvjJWFfjdq77JwqiDqrREnDWp+fqMtmt3Tcj9OvcCg+dCzEoQq r2GxDqkvpgDFS1Hhr70hgmiadJxPIg15iBuwRauYOFGI3jou1PMFrzsczQtzlynUp2ln YI/VlAQ7QePypK0kRF095iWF2d9EdeXlUjWJ6Gk1UWC+g8XcMwHNQ6h3kX5uyfPSzZXi UbMvUe0RmyVHr0GI1k0M2Gr/pp4Tj5ldyFjJM/JHyriVOy2+oepnkF7xqgwXNYsZ3JNz bdZtHFlbqX9Jv5V8qssj3/YRSo2qrxOf+pxXvVHTtL6oy2KnXRmSlz0goGcj/0+2hSVx 2DEg== 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=PjOlhmCbAbyUbUH7pil1I907GgA6nAM7F2t7vQHJi14=; b=zuIY6/OdM6SxV59TnGeeEMJdpHsAs+KnjV1vo8M1YkmtwF2qk6wk7NlZvLWYdYpAFX HTpUa+b8UiJzEh8y0eYGxfesibOpXENeZw+/8UMHhMfy/Fcgxxc9cYrFm15AeWYwF5WB Yb49vtxi26W+POyQBMQgmunNLKyNM+wn8KhcQhSJqiuZnRoYJbKatGr7xFS9i182XKqw GD5/rLgQuu9/ZJ09CiL2+IN+X/pjUxnX52QCqUDxNqSwZNhBrB99Q0/3qcNdpk4rcYBI yqHSx9NBENbNNB4GvuOhvw22AjHB/9cgBltiIDhzh4kwYySaXOtXT8d9XQDWgODJYoVy b1MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b=f9lveGxF; 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 e9si14383617edc.514.2021.05.10.06.08.59; Mon, 10 May 2021 06:09: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=@deviqon.com header.s=google header.b=f9lveGxF; 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 S1351448AbhEJNGx (ORCPT + 99 others); Mon, 10 May 2021 09:06:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351167AbhEJNDC (ORCPT ); Mon, 10 May 2021 09:03:02 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAC1FC061361 for ; Mon, 10 May 2021 05:56:00 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id l13so16497720wru.11 for ; Mon, 10 May 2021 05:56:00 -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=PjOlhmCbAbyUbUH7pil1I907GgA6nAM7F2t7vQHJi14=; b=f9lveGxFe9Pw8WYVlGxIEgVuO1mnm7e2GgPSpQGuhH/T2sjSEST44fTvFD+tp/lIzi l12Qf+xSoCOYm/RxYEcaz6XwDoOsuAG+UUBpPK8nX+aGhC2BBawQOU2ZDUT3RnRJUzDh uucUDHJuS5NOdIvek5tQEBO3Z5BbpLO/m/QQ4PLJieBfwdpZJom4VnQDZHpQ59S1Y3Jn AuZJEIRF5iOmaDEyonyDmEcSSEBEnoIWLsnndskhAS9exaxVyKIIYgmJddbQEdFejIFu 8iDI+MQVHXyShSpy0aVLKNwf47BfbRU6I+p02s9D9aYLqW+kikf+eAmxiWUR3dfIkzWr f6zQ== 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=PjOlhmCbAbyUbUH7pil1I907GgA6nAM7F2t7vQHJi14=; b=DFFG7r0VBdUbeWKD1Uy9Egjk4sqmQK+e1ckcXoWIdPpBzgTY34ILi+M9/XayDeJmhp esGFzm4hUXTu7mUqIY/4RhTvBAQgj/7hByA7Q+3cJ+um3Sx0OAF9lXfINC4pM+tag5ng Bohay5LpIP9JJDXIf0koUXx8wZcLdDlRW6TYcwvxG3FYzO4NTtDZdG5vOIzdDgN+Rxqk Il6aD4MC04/+u7hntn5lLVXDbCVfv0rl6ISapCsPwSniPKpDKTYpG83T1WgR8oQwAJq2 lugx2YqVh+yaXqBluxWK3ugGEM7G0xgcmzMgahytaFBZzj63CWhEjDEEbPgZVQe7Hvnv EK0w== X-Gm-Message-State: AOAM530Z6OfXeT84H1TuwZRMd1OX10l+csMHMsSsfK/o4/jALP0NHx7V zC7HxqFNM+JKEA7IAgXHF9T67ikNQ18Sgw== X-Received: by 2002:adf:d4ca:: with SMTP id w10mr31894907wrk.244.1620651359564; Mon, 10 May 2021 05:55:59 -0700 (PDT) Received: from neptune.. ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id n2sm23134329wmb.32.2021.05.10.05.55.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 May 2021 05:55:59 -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 Subject: [PATCH 09/11] iio: adc: ad7124: Fix potential overflow due to non sequential channel numbers Date: Mon, 10 May 2021 15:55:21 +0300 Message-Id: <20210510125523.1271237-10-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510125523.1271237-1-aardelean@deviqon.com> References: <20210510125523.1271237-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 --- 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