Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp600247pxb; Wed, 3 Mar 2021 10:26:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJz7sAXppKO+3oyePmSTLNhhllVhYF6oWbofbE8Cx2KmuLaCqbWVT/4sYdte3w57eibwJr6D X-Received: by 2002:aa7:c889:: with SMTP id p9mr649246eds.82.1614795966509; Wed, 03 Mar 2021 10:26:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614795966; cv=none; d=google.com; s=arc-20160816; b=eR26Exi9FHQ1HzYN9UOuH1Ze8WHBJ1v3EXoirSm47lcZR17t1KK8afZVpWynV2tfgo tVDNZsx1pnBUjzd5diUaLCge6VaKWB5NN+LYKwg9+cPZbV6lPHEaaJPaeJ/W7E5vLp/W yk1tLHha2jfMduQtGeSTZcvuoOVf+Ts9n2kRe1cqwGCQFKOWKRy8+Cm14cWV5iI/LYp2 w8hKaySEzqf9WKoDU93e9LeYMLmiUF1pgSVdLhDyoQsKaFE9TsBio9wp65k6pAkjODwY 4Y2fHIw6hP7SvV17+ymsgLAO4V4b+7bRXnO22PAHltRozU+4yxrTHS3bUUm7oaSnbYoW hjPg== 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=RnqPhiVqpWAllpJaAOwxL6sHs6mdUNwODKKGdiqYB0U=; b=vVNe7lV26drbgjzj2G+c1GSGWRbpsCtd/5dyC4HwKYhlQnk93q6NPwFG9lSkIpimVI EbD8xtn0ji75aYfqb0wrykc4MsXfHAczhvDyVCYzHsvfpIvu+GxLWhpddb8FW9D/1nR7 Df2yFMGFLdRqZSNjjyQKCVqQ938tBOVhuw+snXI9PanSYDIKpzSQmDlh6v9Aru1NR1LO HqPLOsHEa36MDEjLpCPYPvXNuy7wD8C8fZciyOHWFfbgx53jL0vQYPbYJNGaAyQ5RL2b GtbwDvS68raypqlhnLys0HJw5vClWBtJUptDCl8SXZ3CYxIPIAvRUQDKzIqMMVBxYfBZ aOAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hc6e58rp; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l13si16332554ejg.121.2021.03.03.10.25.04; Wed, 03 Mar 2021 10:26:06 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=hc6e58rp; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378077AbhCBBDy (ORCPT + 99 others); Mon, 1 Mar 2021 20:03:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:59846 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238112AbhCAS4i (ORCPT ); Mon, 1 Mar 2021 13:56:38 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5BD1D651F5; Mon, 1 Mar 2021 17:19:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614619199; bh=ORluSZcnlpOLMcZTmsMboY6MswbuOCMKTiOq7fmiNR4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hc6e58rpsq+9otd5NthuU0TLj9NNyRMFO+oL2tMl9fnMk6y/ONgc4WxzRrnjiYl9j Gh7IdTGkmZEbk6dG37hvGj5NxVyL04ADyfaFTNX6etxtbmpb80g0suqWsSIIo0nydJ 5HC/h+aOufC3UztQE/oUOrqz6Xn6OLibCZJgx6qU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kees Cook , "Gustavo A. R. Silva" , Serge Semin , Mark Brown , Sasha Levin Subject: [PATCH 5.10 369/663] spi: dw: Avoid stack content exposure Date: Mon, 1 Mar 2021 17:10:17 +0100 Message-Id: <20210301161200.103107910@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161141.760350206@linuxfoundation.org> References: <20210301161141.760350206@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: Kees Cook [ Upstream commit 386f771aad15dd535f2368b4adc9958c0160edd4 ] Since "data" is u32, &data is a "u32 *" type, which means pointer math will move in u32-sized steps. This was meant to be a byte offset, so cast &data to "char *" to aim the copy into the correct location. Seen with -Warray-bounds (and found by Coverity): In file included from ./include/linux/string.h:269, from ./arch/powerpc/include/asm/paca.h:15, from ./arch/powerpc/include/asm/current.h:13, from ./include/linux/mutex.h:14, from ./include/linux/notifier.h:14, from ./include/linux/clk.h:14, from drivers/spi/spi-dw-bt1.c:12: In function 'memcpy', inlined from 'dw_spi_bt1_dirmap_copy_from_map' at drivers/spi/spi-dw-bt1.c:87:3: ./include/linux/fortify-string.h:20:29: warning: '__builtin_memcpy' offset 4 is out of the bounds [0, 4] of object 'data' with type 'u32' {aka 'unsigned int'} [-Warray-bounds] 20 | #define __underlying_memcpy __builtin_memcpy | ^ ./include/linux/fortify-string.h:191:9: note: in expansion of macro '__underlying_memcpy' 191 | return __underlying_memcpy(p, q, size); | ^~~~~~~~~~~~~~~~~~~ drivers/spi/spi-dw-bt1.c: In function 'dw_spi_bt1_dirmap_copy_from_map': drivers/spi/spi-dw-bt1.c:77:6: note: 'data' declared here 77 | u32 data; | ^~~~ Addresses-Coverity: CID 1497771 Out-of-bounds access Fixes: abf00907538e ("spi: dw: Add Baikal-T1 SPI Controller glue driver") Signed-off-by: Kees Cook Reviewed-by: Gustavo A. R. Silva Acked-by: Serge Semin Link: https://lore.kernel.org/r/20210211203714.1929862-1-keescook@chromium.org Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-dw-bt1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/spi/spi-dw-bt1.c b/drivers/spi/spi-dw-bt1.c index c279b7891e3ac..bc9d5eab3c589 100644 --- a/drivers/spi/spi-dw-bt1.c +++ b/drivers/spi/spi-dw-bt1.c @@ -84,7 +84,7 @@ static void dw_spi_bt1_dirmap_copy_from_map(void *to, void __iomem *from, size_t if (shift) { chunk = min_t(size_t, 4 - shift, len); data = readl_relaxed(from - shift); - memcpy(to, &data + shift, chunk); + memcpy(to, (char *)&data + shift, chunk); from += chunk; to += chunk; len -= chunk; -- 2.27.0