Received: by 10.192.165.148 with SMTP id m20csp2523322imm; Sun, 22 Apr 2018 08:48:46 -0700 (PDT) X-Google-Smtp-Source: AIpwx49YzAVvlQmtF+cfbHxypxXsekcau9f0pJSu7YyZgLxtMzJYtxEeBolXXaKuMnod0EROEJ0u X-Received: by 10.98.68.135 with SMTP id m7mr16867545pfi.57.1524412126781; Sun, 22 Apr 2018 08:48:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524412126; cv=none; d=google.com; s=arc-20160816; b=utu8nwQlQd5qNhQKQQYiU2AQpR/XQJR1lad1MoQFvboR8jzmZV15KoEtET7hh/zvPB 5rlsPHuUq3GizZMyasdY2E3xyIYYaaBkvBForoEyhDzk+rzanv+/iE7Z4pKVNyFVJaid 8KGtJdOTh0la9ndp9Uv2F0OIGvCn6uHyHlJX0IU+B02FzKqClky60yzjy6oLAdj+zk8w uGg8fRyHZLzNvRsP/1Clrvr045w6dGrexgeqZMQVeD1XSME6GIKZm8om3SxRaKYQZv/Z MWiy6aIh24GBTN1U6RQ7QJKS1dVTE3VQ3TCsue1W2zPwAVvLmIe4KAO/OBcI6BdtihgI GoBg== 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=Pwt9sG9cLd7kjwejlOsHvhV8W7uGe1pQMHHSfcZDrv4=; b=oqcPXlLOIgaj4s1ibat8+ZoEAxP7jCEuTuIe2I+hNGQ7mdtVlOpFFoQ78XKo7y/lOY VkrW5BZt+Y7CHHoBupyj9/kvkhI2mjisAVXAkZqkMn7WhWGhTTtgmUmMzfe3ZVYsu9j5 CUoHgLld8PXyT0PXuPFUV47EvdCKmEOid7Ngf9B18s1T4v8Xik2PdQDYikYE/Eq1mz9x 6WYJZ7HgMsrpH5ovNYqlF03WqycV+ChixFyraUsRrT5TsHZYKhzrhBc0LF0qmxFSM0ym RqOXvuXW8Xe5vKj3LKROu4DXl6CMBIB4+XZCFqGT4QoUjju8qcJAcoqLf1gZlNoFkWz5 ulpw== 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 o14si2979367pgf.174.2018.04.22.08.48.32; Sun, 22 Apr 2018 08:48:46 -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 S1755032AbeDVPqo (ORCPT + 99 others); Sun, 22 Apr 2018 11:46:44 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:48328 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754415AbeDVOCJ (ORCPT ); Sun, 22 Apr 2018 10:02: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 D4476C9B; Sun, 22 Apr 2018 14:02:08 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chuanhua Lei , Matt Redfearn , Ralf Baechle , linux-mips@linux-mips.org, James Hogan Subject: [PATCH 4.16 174/196] MIPS: memset.S: EVA & fault support for small_memset Date: Sun, 22 Apr 2018 15:53:14 +0200 Message-Id: <20180422135113.252054528@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135104.278511750@linuxfoundation.org> References: <20180422135104.278511750@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.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Matt Redfearn commit 8a8158c85e1e774a44fbe81106fa41138580dfd1 upstream. The MIPS kernel memset / bzero implementation includes a small_memset branch which is used when the region to be set is smaller than a long (4 bytes on 32bit, 8 bytes on 64bit). The current small_memset implementation uses a simple store byte loop to write the destination. There are 2 issues with this implementation: 1. When EVA mode is active, user and kernel address spaces may overlap. Currently the use of the sb instruction means kernel mode addressing is always used and an intended write to userspace may actually overwrite some critical kernel data. 2. If the write triggers a page fault, for example by calling __clear_user(NULL, 2), instead of gracefully handling the fault, an OOPS is triggered. Fix these issues by replacing the sb instruction with the EX() macro, which will emit EVA compatible instuctions as required. Additionally implement a fault fixup for small_memset which sets a2 to the number of bytes that could not be cleared (as defined by __clear_user). Reported-by: Chuanhua Lei Signed-off-by: Matt Redfearn Cc: Ralf Baechle Cc: linux-mips@linux-mips.org Cc: stable@vger.kernel.org Patchwork: https://patchwork.linux-mips.org/patch/18975/ Signed-off-by: James Hogan Signed-off-by: Greg Kroah-Hartman --- arch/mips/lib/memset.S | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/arch/mips/lib/memset.S +++ b/arch/mips/lib/memset.S @@ -219,7 +219,7 @@ 1: PTR_ADDIU a0, 1 /* fill bytewise */ R10KCBARRIER(0(ra)) bne t1, a0, 1b - sb a1, -1(a0) + EX(sb, a1, -1(a0), .Lsmall_fixup\@) 2: jr ra /* done */ move a2, zero @@ -260,6 +260,11 @@ jr ra andi v1, a2, STORMASK +.Lsmall_fixup\@: + PTR_SUBU a2, t1, a0 + jr ra + PTR_ADDIU a2, 1 + .endm /*