Received: by 10.213.65.68 with SMTP id h4csp1717758imn; Mon, 19 Mar 2018 11:19:23 -0700 (PDT) X-Google-Smtp-Source: AG47ELuy/rwJLi3aH9Mj6v0NarU5vVQ3tnpfziNQH/3ncY8T3l0BoE7m02MYasWIayCT4CEpeaNy X-Received: by 2002:a17:902:670f:: with SMTP id f15-v6mr13604497plk.188.1521483563182; Mon, 19 Mar 2018 11:19:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521483563; cv=none; d=google.com; s=arc-20160816; b=LDjdNA4ZPLgMz7D3fPX4f3kMPTjrDHDJhC2qs1wp/dTh37MfCU7gKWtl4/qqANllta 1YcAKUm69yMc4OZ10J/T/EMQ6xShV6uH5WKCWuiaHE3X/1hwCyMoi76eAPu4emnTGO4E qQxha6EbtetsXYEue4mbE8MHL6HBiEA8dtG6SjxYSY7pTwu/IqzOqBFM2d2vHZvzc12e UXX0d811OF4y7BUJ566yNW/s2Vnbf3vB6vN/uYQtYaUcc0KAbNcAdKhf1eC8D4A1alYj qZfJ1SOZ4BAqyVzlxCGWjhm/CqI90SkI7ytswsKFpvdBTgSdj2bMkYFwovimfJ733CI8 VmgA== 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=h04dD/GypLRZwSKIS2sLMLCkKvA1nriEMHrdRTbLB3s=; b=JsCq1Dv9M9JDc6+9IEQoi7vJ6Jg5Sg3tc3/9Kv2Nlai1bK/NQIiKYy96GpXCBSV4xD 4S86VpTrvCkDXotZX2Hi4ppXKvlMDrbRBuSqVeuCC9mV/deDKQ1N34Wq3k7hA+yy/92N ABaVFXnjoprIqX4AHvnMBZMgOiqoajuhrdSFBVaCNmjxA0Cs8m3a3Nahd9QWSn6yrOzl gCsi1Bh3ROlfoOUxHfk6EyQbjGXu/vSKVJPj+sAyB30ztc3d2jjBSmpRh8lJKm3wWgU+ UvumsJ6TQJhCQdMWOFsT7b/C9cgV0MYv9hf693eWp1T8iv20Bv35sGW296e1GlUgFC6G Gk7A== 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 y72-v6si422656plh.72.2018.03.19.11.19.08; Mon, 19 Mar 2018 11:19:23 -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 S969078AbeCSSRA (ORCPT + 99 others); Mon, 19 Mar 2018 14:17:00 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45286 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030872AbeCSSQr (ORCPT ); Mon, 19 Mar 2018 14:16:47 -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 4DB8B123F; Mon, 19 Mar 2018 18:16:46 +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.4 078/134] wil6210: fix memory access violation in wil_memcpy_from/toio_32 Date: Mon, 19 Mar 2018 19:06:01 +0100 Message-Id: <20180319171900.560753155@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319171849.024066323@linuxfoundation.org> References: <20180319171849.024066323@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.4-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 @@ -125,9 +125,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_toio_32(volatile void __iomem *dst, const void *src, @@ -136,8 +142,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); + } } static void wil_disconnect_cid(struct wil6210_priv *wil, int cid,