Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3298963pxk; Mon, 21 Sep 2020 10:01:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXzaIcHi2rGLKi9+vowvWL48zZ5g1CuQfHBSa2kH1XHs2vyIbiYh8ZYVnqjdJgK032mqff X-Received: by 2002:aa7:d4d2:: with SMTP id t18mr599900edr.55.1600707706988; Mon, 21 Sep 2020 10:01:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600707706; cv=none; d=google.com; s=arc-20160816; b=flGHIHfWTrC7ScqbbPCwj3KZpZ0w7oEYkgJ9g4AJT9TqvrsjG3GXL+6p6mLxHrAMAf WPcOlXlmlKdew+UoW2iBP7stWYjZHoahXkFYpeUtrwZIZ89TMNjsEbFJCma5Otp19hBD 6Bxr84Cb35uKaTcoYHHI/bETZSD6pGFEpHwY0QBFTB/5DNOtEq7KAygdwEaPEsP7n7RY c1/zsgKMm1yuMZBmG3ED9Gax2NN3ivUwaakXxGn301ZFauHbfo8fXD7+PEHSFQZSdpw8 IKsUuivA8yVVwqNEgmdkodTWdlxqWdbAGaaKkJueYCUIfzDctiCS6fXpEKKhB5Rf2dam oDIw== 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=ndB8icfSU+eJrlsL1b1f3S3ZpZ07Df8uuLmb8pyp0ew=; b=Vd39bpq5jBY6+BmakKXtBM6baKpOEc2Vg70YqSwrx7IuskRrURTz4xDmGZn5ECUW0M GHy0wopVdDh6zV8Oe6TSaJvkgE6b0S83xfKErsAAo6dT3HkRXYDxaGACLfgbLbenzA52 GhhgCC23bK5uUCi1l4Kqif8PixNzWD7Dhkj0TT2Q1Kw6JRqC+H3evgR+cPWK1/VEs3Ra oRG96A/HhOhHNhHzyo4DjCtJvqlgeiXCuvFy3EnR4Kgir4gyx3pYz2zpOwdrpB0jlN4O 7zS50IaIaOAMVn43mMrrm8z2o9PUKKCuWIBn7oqg+xV4AlUIYszvmMrOu2NpqATLFUAy chwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HHlV0FKM; 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 h25si8391425edq.433.2020.09.21.10.01.22; Mon, 21 Sep 2020 10:01:46 -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=HHlV0FKM; 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 S1730066AbgIUQ6O (ORCPT + 99 others); Mon, 21 Sep 2020 12:58:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:46230 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728380AbgIUQmN (ORCPT ); Mon, 21 Sep 2020 12:42:13 -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 05B7A23976; Mon, 21 Sep 2020 16:42:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600706532; bh=E2UGo2sQGtP/cvqzed6Qm48vWtNdhAPdX997cI1qKDY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HHlV0FKMOqKJUpBwCkk1oOLxsGr5o8g4/whxJgpH7VBCznWGGUwr3t3bZG/8p9SCe Ui69Rsf7EZvONaBWig2f7EtDvE2mD2WWo8784lN69OCiqNTxVt+GDM/zLJRVlALhFV 5aLYUhvmeCfrBZEYf0d1gtgjo3eAhFSYt+wOxlD8= 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 4.19 14/49] spi: spi-loopback-test: Fix out-of-bounds read Date: Mon, 21 Sep 2020 18:27:58 +0200 Message-Id: <20200921162035.286175398@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921162034.660953761@linuxfoundation.org> References: <20200921162034.660953761@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 bed7403bb6b3a..b9a7117b6dce3 100644 --- a/drivers/spi/spi-loopback-test.c +++ b/drivers/spi/spi-loopback-test.c @@ -99,7 +99,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