Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3288778pxk; Mon, 21 Sep 2020 09:47:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKXJmja4xiEWSgJZQLg8VFJuDUVCdA79rf2ajggVlYtj1Fm2f3vmYE7YR5tI4xqMgn28Ic X-Received: by 2002:a05:6402:b72:: with SMTP id cb18mr505693edb.299.1600706820686; Mon, 21 Sep 2020 09:47:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600706820; cv=none; d=google.com; s=arc-20160816; b=Fn/BJATGRqYN9Z++05F90Nwo2umN6vQxfmi8w/OIxdJ9ipJpMdZdLCQeP5EeTvi/92 qVMKjWFzkp8nzD210oew/H2NqndSVtyM+l9WrRnLyaunB8kqCRYvVS+7QUrhKS/4de6k 7lubSr4kZe+znijmm0cNQcVMg7noMNfA9aLqEZ+2CWpVoTmyvhy+BAAIq4mbiSqWxvkg dtXGR5qUVP/x9XubvViHURaM4tWMnFxwOSioUaWx/mrMiOzc+PB0ZhOwCQVYa2so2xHl q4IHF3y106xp7QLtGIS06/lZg/X/rPnAKHHmD1hLIVny2KWQ7KoxNYIiQW/VKIT0MCBt gdCQ== 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=BQMsO/L7ijhQRzJvjEmFudNurqQCLDYqEvTuXIuhqmM=; b=yEhOt/CKyhdVxVtQ79GawXibgLhtofFul+uXbwyysTCF/GjQNOmg0+oJ+pAJnHPKiz ou3KR+ZaQMsqYvLmbQuslYzqlfzag32r8VAfwGInr89zkxHx6KPCUB4G9y02NksYRh8/ WYw9uJklUbN1dzHCO/k6wmOXWxtgoVDhROeDqWu4Nn0S0iGwmJN/BetUSkK+7jj5nmXD HMF6ZtqwrBxWZoe6f05yC36YmbsXXNAWivmGcbD1ADsZhwgM7oVtwvqTu2cJ23/hLzHq YK4mAMMla/CKjb1cnQChO8PKzhsRFoJvjZiwICGCv112fPp4EvMvb7UkkaderA/h1tEW nTLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="V4/mTc9N"; 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=fail (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 lk17si8664498ejb.188.2020.09.21.09.46.35; Mon, 21 Sep 2020 09:47:00 -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=@kernel.org header.s=default header.b="V4/mTc9N"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729601AbgIUQn0 (ORCPT + 99 others); Mon, 21 Sep 2020 12:43:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:47926 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729336AbgIUQnX (ORCPT ); Mon, 21 Sep 2020 12:43:23 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2BA68238E6; Mon, 21 Sep 2020 16:43:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600706602; bh=kTrpFz5CAoCPBtBgvwd9l4jFxoKG54s1sxlhsmpU9JM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V4/mTc9N3fc+PPBpdkCkpdTQj6tWH8Ybx43MbZ+A5TvSKsWVB5bHp/DmaUEYr4Vhd v/vTiwX/McRmZNd0BVFAA/X1ucj/60ifZrdl53uoXv4TjPU477APlNhy9DNOVP5cMJ eRE59hbkxr1E/YqFK+8mXtV75gadwBz8kzo77IEo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vincent Whitchurch , Mark Brown , Sasha Levin Subject: [PATCH 5.8 019/118] spi: spi-loopback-test: Fix out-of-bounds read Date: Mon, 21 Sep 2020 18:27:11 +0200 Message-Id: <20200921162037.215242220@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921162036.324813383@linuxfoundation.org> References: <20200921162036.324813383@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: Vincent Whitchurch [ Upstream commit 837ba18dfcd4db21ad58107c65bfe89753aa56d7 ] The "tx/rx-transfer - crossing PAGE_SIZE" test always fails when len=131071 and rx_offset >= 5: spi-loopback-test spi0.0: Running test tx/rx-transfer - crossing PAGE_SIZE ... with iteration values: len = 131071, tx_off = 0, rx_off = 3 with iteration values: len = 131071, tx_off = 0, rx_off = 4 with iteration values: len = 131071, tx_off = 0, rx_off = 5 loopback strangeness - rx changed outside of allowed range at: ...a4321000 spi_msg@ffffffd5a4157690 frame_length: 131071 actual_length: 131071 spi_transfer@ffffffd5a41576f8 len: 131071 tx_buf: ffffffd5a4340ffc Note that rx_offset > 3 can only occur if the SPI controller driver sets ->dma_alignment to a higher value than 4, so most SPI controller drivers are not affect. The allocated Rx buffer is of size SPI_TEST_MAX_SIZE_PLUS, which is 132 KiB (assuming 4 KiB pages). This test uses an initial offset into the rx_buf of PAGE_SIZE - 4, and a len of 131071, so the range expected to be written in this transfer ends at (4096 - 4) + 5 + 131071 == 132 KiB, which is also the end of the allocated buffer. But the code which verifies the content of the buffer reads a byte beyond the allocated buffer and spuriously fails because this out-of-bounds read doesn't return the expected value. Fix this by using ITERATE_LEN instead of ITERATE_MAX_LEN to avoid testing sizes which cause out-of-bounds reads. Signed-off-by: Vincent Whitchurch Link: https://lore.kernel.org/r/20200902132341.7079-1-vincent.whitchurch@axis.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-loopback-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/spi/spi-loopback-test.c b/drivers/spi/spi-loopback-test.c index b6d79cd156fb5..da1153ec9f0e3 100644 --- a/drivers/spi/spi-loopback-test.c +++ b/drivers/spi/spi-loopback-test.c @@ -90,7 +90,7 @@ static struct spi_test spi_tests[] = { { .description = "tx/rx-transfer - crossing PAGE_SIZE", .fill_option = FILL_COUNT_8, - .iterate_len = { ITERATE_MAX_LEN }, + .iterate_len = { ITERATE_LEN }, .iterate_tx_align = ITERATE_ALIGN, .iterate_rx_align = ITERATE_ALIGN, .transfer_count = 1, -- 2.25.1