Received: by 10.213.65.68 with SMTP id h4csp1723247imn; Mon, 19 Mar 2018 11:28:21 -0700 (PDT) X-Google-Smtp-Source: AG47ELs4VkQolkEckPJcKnYsVzI266dRCJeczc5/6pWY/+kVues4/9U5H6R+FGKTEnStuubas4wv X-Received: by 10.101.97.26 with SMTP id z26mr9884195pgu.44.1521484101560; Mon, 19 Mar 2018 11:28:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521484101; cv=none; d=google.com; s=arc-20160816; b=IGC9rcb6vWhBdPB+CbXUP5HS42RyZbBMohxVqM0sKwR5YSfrTwbI7kAKymnZl2LpM2 7YaXaTL14orbeoWL+FMh5w+mcI4txRPr1cqq++/fQcnLuj9hxHxbnPfDQvUUmW3+niSC bR5Th72PnrIspnGh9rULzxvF/f876WNR3ED9wTTRFyPXGUg1MoqqC4+efml6aalBpAxZ QzcCpF/XwkbLauwA8yS3ZmmGZcJNdsZZmuTtTJeRxU9TLjKZQP0QdlmX3lvxJAik/yqp eNSSXd7JQON8V/RR0oORGyMvxApNqtoQdrrqO1qmXix/cCJoM3JpLc2kSKwKeh9uMwb/ hTsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=15uYaYbL7FH7jWx31/m2mQhE9pKC7thxW5vg0tJ3bEo=; b=b1/XBCG31ntgRQNmar+RQn9aL/9eFF1L8HoEdBamPvTEaVBX1txWTAqOZwPujtrkDI AQCoLvyb8QgUbb08FD0UlHcK9nbYl2aIA+970V9la3yOV1Q3GJIHM0FQB+GrfzIp5gJ7 8MNyfrOuByhgLRTwDbGnRBj9xz7mZQlQYz6/px7FZ/7hnxsaFi72wKbpOxlI+A3GfOQT fzRD/0OcrMedxJF/BXGz0DLHGgOxxLFD6/nrlGa7UYjwKO4JIpZLjY4CamBSBc0ASX4Z SxiCXovlyiRlkFQfzfrJ7g8QxnLzK9m2riGhO5NnzzLevZAd4rOl50omCZ371HPkZbjI Oykw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a59-v6si418358plc.501.2018.03.19.11.28.07; Mon, 19 Mar 2018 11:28:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031628AbeCSSZS (ORCPT + 99 others); Mon, 19 Mar 2018 14:25:18 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:50262 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031581AbeCSSZJ (ORCPT ); Mon, 19 Mar 2018 14:25:09 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id E1F84FDA; Mon, 19 Mar 2018 18:25:07 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dedy Lansky , Maya Erez , Kalle Valo , Sasha Levin Subject: [PATCH 4.9 161/241] wil6210: fix memory access violation in wil_memcpy_from/toio_32 Date: Mon, 19 Mar 2018 19:07:06 +0100 Message-Id: <20180319180757.833009819@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180751.172155436@linuxfoundation.org> References: <20180319180751.172155436@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dedy Lansky [ Upstream commit 0f6edfe2bbbb59d161580cb4870fcc46f5490f85 ] In case count is not multiple of 4, there is a read access in wil_memcpy_toio_32() from outside src buffer boundary. In wil_memcpy_fromio_32(), in case count is not multiple of 4, there is a write access to outside dst io memory boundary. Fix these issues with proper handling of the last 1 to 4 copied bytes. Signed-off-by: Dedy Lansky Signed-off-by: Maya Erez Signed-off-by: Kalle Valo Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/net/wireless/ath/wil6210/main.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) --- a/drivers/net/wireless/ath/wil6210/main.c +++ b/drivers/net/wireless/ath/wil6210/main.c @@ -129,9 +129,15 @@ void wil_memcpy_fromio_32(void *dst, con u32 *d = dst; const volatile u32 __iomem *s = src; - /* size_t is unsigned, if (count%4 != 0) it will wrap */ - for (count += 4; count > 4; count -= 4) + for (; count >= 4; count -= 4) *d++ = __raw_readl(s++); + + if (unlikely(count)) { + /* count can be 1..3 */ + u32 tmp = __raw_readl(s); + + memcpy(d, &tmp, count); + } } void wil_memcpy_fromio_halp_vote(struct wil6210_priv *wil, void *dst, @@ -148,8 +154,16 @@ void wil_memcpy_toio_32(volatile void __ volatile u32 __iomem *d = dst; const u32 *s = src; - for (count += 4; count > 4; count -= 4) + for (; count >= 4; count -= 4) __raw_writel(*s++, d++); + + if (unlikely(count)) { + /* count can be 1..3 */ + u32 tmp = 0; + + memcpy(&tmp, s, count); + __raw_writel(tmp, d); + } } void wil_memcpy_toio_halp_vote(struct wil6210_priv *wil,