Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp2922321ybx; Fri, 8 Nov 2019 11:18:36 -0800 (PST) X-Google-Smtp-Source: APXvYqzmUB4jRiM4hL56AJr5w1/s3m9yU1oRrx8EYBSI29xIhPnZBPcPIw8pTqPGuPX2md3p32DR X-Received: by 2002:a17:906:27cc:: with SMTP id k12mr10423986ejc.181.1573240716241; Fri, 08 Nov 2019 11:18:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573240716; cv=none; d=google.com; s=arc-20160816; b=ke1eYRungvwce6h6bD/xpBcfyy0DD28v2MdsZ1gLHxSzXmO2wrVlWEjhamMkzdj4QN wOZIViQCm2U/QF57yEC6tNdo+r2Vn06dT9e5hYzAWD1ntDFOT+gxEQBT+19806w2uWUN oqDUqB8OuU9TMDTIsfo6RfLgeWb6ig0cgw2feDh9hl8kT2cImVywYIv4drPX/C5ILJvz 3RaZkBkCEsVT9GuYj+qvsjzPbZZGNBqKobRKVOwdLKLUlfXmFoy3NE+TOlFdS7W+IzPZ sL1iMpWZDahYv/7ky5k7HfHW46j7EI7YwVXERrpwwoqmtyFKK3E6i5KR0U9E0joqIvwp CDSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ob/rEhN3CthU0P5k6ne09vR6JDfoE4pn2pfBSO5Eo9A=; b=0xTvY5yjO8aaV0tWU7ibNXnVxafSLYbsrBANzNBBqwWTAx8TCPZ5RRS60TTvBZP5RL peqrkKB5ItcUonOIq1Bi+avoONFB0YHpmIvycSlCZIZpAMrR6z2q9m4V+Evnp0J6zBNM e66mHMGqO9NGXaaGMvWFisGOMrdugmDr8RH4LvXoKJ3cZ0J9XYX+MY3eqfTdUh7rUcUf Isnb4dKKBabDO+n4keRZNA3jOYMf0UPZbGDlWEVk2ZL6pc/jZhTGP9TItE2syJMfzrL0 s2pp+JVd2CheWTVTS+4AgB7okDSYvLoNwu4c/ZhFoGRJzdW3r4DA4SdyL0mCDAAgBbgi PtCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ucxIkpxy; 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 rv12si4283239ejb.372.2019.11.08.11.18.12; Fri, 08 Nov 2019 11:18:36 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=ucxIkpxy; 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 S2390264AbfKHTRm (ORCPT + 99 others); Fri, 8 Nov 2019 14:17:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:58064 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389940AbfKHTAs (ORCPT ); Fri, 8 Nov 2019 14:00:48 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 ECF1D2067B; Fri, 8 Nov 2019 19:00:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573239647; bh=EB16L9vTHdgOumIeosjbfNzBmnYiyoIdyewf7yrkr2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ucxIkpxyNzDR1gzvMf91imvtAb475hBs6d134N+ApZ19R2ysQluZqHjeKuyuMmd5+ tYFkW/R617k6b4ItlxcjPnS/NkfzMak0zfzgXlvOeL5Z7jDQMA6v3dP3u2yZYZWMgl 3/aa04BMkcVLBWdRdm5UPoZ5Y//dSM1hW7+BEgno= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jing Xiangfeng , Russell King , Sasha Levin Subject: [PATCH 4.19 14/79] ARM: mm: fix alignment handler faults under memory pressure Date: Fri, 8 Nov 2019 19:49:54 +0100 Message-Id: <20191108174752.634183234@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191108174745.495640141@linuxfoundation.org> References: <20191108174745.495640141@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Russell King [ Upstream commit 67e15fa5b487adb9b78a92789eeff2d6ec8f5cee ] When the system has high memory pressure, the page containing the instruction may be paged out. Using probe_kernel_address() means that if the page is swapped out, the resulting page fault will not be handled because page faults are disabled by this function. Use get_user() to read the instruction instead. Reported-by: Jing Xiangfeng Fixes: b255188f90e2 ("ARM: fix scheduling while atomic warning in alignment handling code") Signed-off-by: Russell King Signed-off-by: Sasha Levin --- arch/arm/mm/alignment.c | 44 +++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c index bd2c739d80839..84a6bbaf8cb20 100644 --- a/arch/arm/mm/alignment.c +++ b/arch/arm/mm/alignment.c @@ -768,6 +768,36 @@ do_alignment_t32_to_handler(unsigned long *pinstr, struct pt_regs *regs, return NULL; } +static int alignment_get_arm(struct pt_regs *regs, u32 *ip, unsigned long *inst) +{ + u32 instr = 0; + int fault; + + if (user_mode(regs)) + fault = get_user(instr, ip); + else + fault = probe_kernel_address(ip, instr); + + *inst = __mem_to_opcode_arm(instr); + + return fault; +} + +static int alignment_get_thumb(struct pt_regs *regs, u16 *ip, u16 *inst) +{ + u16 instr = 0; + int fault; + + if (user_mode(regs)) + fault = get_user(instr, ip); + else + fault = probe_kernel_address(ip, instr); + + *inst = __mem_to_opcode_thumb16(instr); + + return fault; +} + static int do_alignment(unsigned long addr, unsigned int fsr, struct pt_regs *regs) { @@ -775,10 +805,10 @@ do_alignment(unsigned long addr, unsigned int fsr, struct pt_regs *regs) unsigned long instr = 0, instrptr; int (*handler)(unsigned long addr, unsigned long instr, struct pt_regs *regs); unsigned int type; - unsigned int fault; u16 tinstr = 0; int isize = 4; int thumb2_32b = 0; + int fault; if (interrupts_enabled(regs)) local_irq_enable(); @@ -787,15 +817,14 @@ do_alignment(unsigned long addr, unsigned int fsr, struct pt_regs *regs) if (thumb_mode(regs)) { u16 *ptr = (u16 *)(instrptr & ~1); - fault = probe_kernel_address(ptr, tinstr); - tinstr = __mem_to_opcode_thumb16(tinstr); + + fault = alignment_get_thumb(regs, ptr, &tinstr); if (!fault) { if (cpu_architecture() >= CPU_ARCH_ARMv7 && IS_T32(tinstr)) { /* Thumb-2 32-bit */ - u16 tinst2 = 0; - fault = probe_kernel_address(ptr + 1, tinst2); - tinst2 = __mem_to_opcode_thumb16(tinst2); + u16 tinst2; + fault = alignment_get_thumb(regs, ptr + 1, &tinst2); instr = __opcode_thumb32_compose(tinstr, tinst2); thumb2_32b = 1; } else { @@ -804,8 +833,7 @@ do_alignment(unsigned long addr, unsigned int fsr, struct pt_regs *regs) } } } else { - fault = probe_kernel_address((void *)instrptr, instr); - instr = __mem_to_opcode_arm(instr); + fault = alignment_get_arm(regs, (void *)instrptr, &instr); } if (fault) { -- 2.20.1