Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3300953pxk; Mon, 21 Sep 2020 10:04:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOEYiqaB8XpMqSiyDBtgEgbYR1VJFEHeANsP7SekwLUr0CXuHnAcQlMrzzozvzUw+KfUlS X-Received: by 2002:a50:d9c1:: with SMTP id x1mr601230edj.283.1600707848035; Mon, 21 Sep 2020 10:04:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600707848; cv=none; d=google.com; s=arc-20160816; b=ET7zhcWA9cVAAiRqmDdI2VV3nW+1qRD5K2h0CcmfB8nTIyibKZto73jMFal3fBLOlo 1mAMTkJeeLVvJldp+RkuSXZWFlgf62QhZMJRdBloXmsYngFQL8k2b7bhjjFta3zBMqmZ o1zj5gFvONCwrBZNbt0UICP7NiELuwOtKyd0IpwC3dgVxCz0xHgjssGISxeU+4aI1XaZ Sazp1yt8rpNJtE32UrzdIADSxmiMF/JG08c80PgAL3QibNgexEuAlQU8rYx5Ff32eyRy i3BC0Epcmic/lLIHH4WaxA3sJ1KiqZNQmqgJOSSHqEV24o995AQFz4d472hWuELMZVJs ZMKQ== 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=lS2tPa2tfJhiLfGIwwaXDhJvzvShwA0sFlj6OHFrbNxncpdg3adtKfQ6/EibWBF04h z50HtdqlTsMvsTe/GAYxsKDaUjf0OniRMisE7HZWnS6xjOepSbIr15nPsNfiQToOztk0 FSWkeK6HBNs6TzImiv4JCBPZ6waM/MfY58Jh8MbqT2O8g8n+oWCbBJ5dYLfhYz41nCkT pp9p7KDt6KOqD7D2AyIg5v7OFNe3eT3uuHrRrK2qXrvHx2N497Mmt14YywCo5/hMaV4f PMefuVbJnScFWVLIktrYUo10CylQo//cb6D9/HRkljlTkBaCvaAwhk8UI1BFrCa5kxc8 PdJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bVWplTit; 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 b5si8617931ejq.317.2020.09.21.10.03.44; Mon, 21 Sep 2020 10:04:08 -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=bVWplTit; 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 S1728944AbgIUQjY (ORCPT + 99 others); Mon, 21 Sep 2020 12:39:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:41102 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728857AbgIUQjS (ORCPT ); Mon, 21 Sep 2020 12:39:18 -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 D23EF206DC; Mon, 21 Sep 2020 16:39:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600706357; bh=E2UGo2sQGtP/cvqzed6Qm48vWtNdhAPdX997cI1qKDY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bVWplTit2f6vCCwdLYx3Ex3URNjeesruki/gUEoXm1Bz8lIBIHKTvm6KZ/Qger+Km qjLQbY6ncGP+H6AIomqAZdaCaXNr0pwzYsd5x+jRfhxwwtns+hGYRovwjyzNkSFuno QLtJHar0Cye7au33DJ8pw2rlRevr/MsgiiQIt3Ps= 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.14 68/94] spi: spi-loopback-test: Fix out-of-bounds read Date: Mon, 21 Sep 2020 18:27:55 +0200 Message-Id: <20200921162038.649036624@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921162035.541285330@linuxfoundation.org> References: <20200921162035.541285330@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