From patchwork Mon May 31 13:12:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "gregkh@linuxfoundation.org" X-Patchwork-Id: 450511 Delivered-To: patch@linaro.org Received: by 2002:a02:c735:0:0:0:0:0 with SMTP id h21csp887356jao; Mon, 31 May 2021 07:38:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwh8pSbEhHRjaXYRWwQUcGGN+1kJMm0Zysxn1pyznYtbP5uGXrfRbxerYDnolxJ7Kdro1/N X-Received: by 2002:a05:6e02:12a6:: with SMTP id f6mr2746278ilr.121.1622471939283; Mon, 31 May 2021 07:38:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622471939; cv=none; d=google.com; s=arc-20160816; b=YUvdDIj1vAyo+c+/5UEC1fy1pz0G9f3Z53RwWBHTVUI8SYSwzZfQsok8FAyAoA0csz VPEcbJEfddSFHE8H6vxuHg1X4e4SqU93piKp8o9BLIUxNZD8ccJz4Lakg+tKZVW/mcLw H1bG0CHoZDlzVTDs/LgHPi6Bz/av/ABwlaYh/QGP248640P7Mo9n9Lv25LzX1uNHrxOW vWU4qS4rfweLn84m+YN2q9+Z9Nlx3ywXMJknI/G48wx+NZYESUuo2f+CiIHrBLA1/KQ7 W1gHa1AGptt96PNaxe0pD9rDPKc//FFEr5u/U0MfonDeNInhUx6i8njSaJbrfq7ubxVC mgWg== 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=kUmbPl0YrRwF3Q92BXbemxm7Z+HtGBG0d82gbIupIO0N6ncw4S6T4B6pjKPlzbbw9p pXpABDYvg7mr6Wg3fQB/Zl3z82fLBbK2niZlkzaXoPB5HQkftI6uJBvUwM6rKvfl3JgW bZzyxu+tgS+5CWNmYXhqjkOLh+zfeUZ9M3iV7fe5VD4gPoVR4KLYAk44c/CAy5FfF93b o2HWfiZomV/FHmEb5wx9PG0NWpkdZ+luEfVjJK0X+fI+/wRtoM0vAe0z6MlX7jtseq+v pvEXMsuqDgd3lWiPUvuv3pLfhVloBBZD15OQY9fpcm6vM6qilhyI/xHQQwl+L3UnpWVr WNEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="077L/n5t"; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 x5si16471919ilu.87.2021.05.31.07.38.59; Mon, 31 May 2021 07:38:59 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-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="077L/n5t"; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 S233892AbhEaOkd (ORCPT + 12 others); Mon, 31 May 2021 10:40:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:36602 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233992AbhEaOhk (ORCPT ); Mon, 31 May 2021 10:37:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A8138617ED; Mon, 31 May 2021 13:52:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622469129; bh=Xdmu0No1qD89vu5RbDro4R5XL0d4XQoB0rtetHFaD4I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=077L/n5tFwbDF1hJBBxSNHZ//gBSApCABcbLiePCY35/9z3RwsRp4MaOPITXiqsr5 j6XMzLWNXTC7EnDG5byQHK4Hs00QNeHb6FJqQioA+g9KjvoeLEtO+S1prVBtSeebUE 7IH5O7MQ8X0gu4oxlXS1ZhIJosC/V+rVivDAKJDo= 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.12 080/296] iio: adc: ad7124: Fix potential overflow due to non sequential channel numbers Date: Mon, 31 May 2021 15:12:15 +0200 Message-Id: <20210531130706.553969054@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130703.762129381@linuxfoundation.org> References: <20210531130703.762129381@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@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)