Received: by 10.223.164.202 with SMTP id h10csp207176wrb; Mon, 13 Nov 2017 05:16:33 -0800 (PST) X-Google-Smtp-Source: AGs4zMbOeYC6wnMG++ChWRBq6KiNeOjozIn45K/ZoFpYQ2tPmhmoUtFrqxWUuIL2PQv/T6TWtFNf X-Received: by 10.98.67.154 with SMTP id l26mr9930467pfi.212.1510578993747; Mon, 13 Nov 2017 05:16:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510578993; cv=none; d=google.com; s=arc-20160816; b=1G/t3hjsyiL2bz78IbExDwa6zUkd9BkDo2B3Ezu1IEO9TTl2QHoTyB6Vi9sWi+ivlf 7kqFo+Bg8IH7AAydK3nN/CEGULcwGXaFSGSdh0q8vMdsuwpIh4zwG6O5kmG5jRKRV73W 7B5nZ5NyE4yBqN21xbT9nf4Fgq7LVvf7/tq/ovVM0lTkfTsyGSyn3jnaHvkdaNr4cScm vhj4ja4Li0v3tDVN2hLD5jZGgvR8OaU0+YQK1ca59tGmVQgqhjRnqbEGmBiTxoNk4SQB YnQ4f1lLScgMRRwlTdRwdVcjessL1TJszJp+v2WavVNO83bYqlv90JWbRMpSuel5nPVp qwoA== 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=SEcXoCbguTzHzHmc3UaLHna7z/wFKu6wxIc9l4oANko=; b=JP49aRSXi/Hoa+3tqQ5lA4kdgeOHMqUOWu6h2p2NZ8p10jRaHQkcAUX7fw5Xo6ir0x v1nd0WXwFot2npfECcADM2sNgct/DM3Gpspm5JsBWyjCh2cYtaFi2M1XKI/ZBeC3jSPK cTacRcsExR4E+XzXK62mSZg7izY/6EZDNB6F55wzu+BiiAFDDG/1T/gDn42z5gyBFGFV yb/FBPai/kcLSe9c2yUyDyQbaHoQD5YvBc16g/ncHXsY78pL3NUrRHt/0EyErZP84eRj rSDmQumJU3ePIRkKNMwFhkfImgqHT8A2QfLn24e0NDi5WDRrV7+SmaKZ3e28I3T6ZM9a CDiQ== 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 w19si15182862pfa.59.2017.11.13.05.16.20; Mon, 13 Nov 2017 05:16:33 -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; 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 S1755069AbdKMNPt (ORCPT + 95 others); Mon, 13 Nov 2017 08:15:49 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:51272 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754003AbdKMNCn (ORCPT ); Mon, 13 Nov 2017 08:02:43 -0500 Received: from localhost (LFbn-1-12253-150.w90-92.abo.wanadoo.fr [90.92.67.150]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id E62AB9C; Mon, 13 Nov 2017 13:02:42 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Rutland , Russell King Subject: [PATCH 4.9 61/87] ARM: 8720/1: ensure dump_instr() checks addr_limit Date: Mon, 13 Nov 2017 13:56:18 +0100 Message-Id: <20171113125620.906786407@linuxfoundation.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171113125615.304035578@linuxfoundation.org> References: <20171113125615.304035578@linuxfoundation.org> User-Agent: quilt/0.65 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: Mark Rutland commit b9dd05c7002ee0ca8b676428b2268c26399b5e31 upstream. When CONFIG_DEBUG_USER is enabled, it's possible for a user to deliberately trigger dump_instr() with a chosen kernel address. Let's avoid problems resulting from this by using get_user() rather than __get_user(), ensuring that we don't erroneously access kernel memory. So that we can use the same code to dump user instructions and kernel instructions, the common dumping code is factored out to __dump_instr(), with the fs manipulated appropriately in dump_instr() around calls to this. Signed-off-by: Mark Rutland Signed-off-by: Russell King Signed-off-by: Greg Kroah-Hartman --- arch/arm/kernel/traps.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) --- a/arch/arm/kernel/traps.c +++ b/arch/arm/kernel/traps.c @@ -152,30 +152,26 @@ static void dump_mem(const char *lvl, co set_fs(fs); } -static void dump_instr(const char *lvl, struct pt_regs *regs) +static void __dump_instr(const char *lvl, struct pt_regs *regs) { unsigned long addr = instruction_pointer(regs); const int thumb = thumb_mode(regs); const int width = thumb ? 4 : 8; - mm_segment_t fs; char str[sizeof("00000000 ") * 5 + 2 + 1], *p = str; int i; /* - * We need to switch to kernel mode so that we can use __get_user - * to safely read from kernel space. Note that we now dump the - * code first, just in case the backtrace kills us. + * Note that we now dump the code first, just in case the backtrace + * kills us. */ - fs = get_fs(); - set_fs(KERNEL_DS); for (i = -4; i < 1 + !!thumb; i++) { unsigned int val, bad; if (thumb) - bad = __get_user(val, &((u16 *)addr)[i]); + bad = get_user(val, &((u16 *)addr)[i]); else - bad = __get_user(val, &((u32 *)addr)[i]); + bad = get_user(val, &((u32 *)addr)[i]); if (!bad) p += sprintf(p, i == 0 ? "(%0*x) " : "%0*x ", @@ -186,8 +182,20 @@ static void dump_instr(const char *lvl, } } printk("%sCode: %s\n", lvl, str); +} - set_fs(fs); +static void dump_instr(const char *lvl, struct pt_regs *regs) +{ + mm_segment_t fs; + + if (!user_mode(regs)) { + fs = get_fs(); + set_fs(KERNEL_DS); + __dump_instr(lvl, regs); + set_fs(fs); + } else { + __dump_instr(lvl, regs); + } } #ifdef CONFIG_ARM_UNWIND From 1583956368806498081@xxx Mon Nov 13 13:08:27 +0000 2017 X-GM-THRID: 1583956368806498081 X-Gmail-Labels: Inbox,Category Promotions,HistoricalUnread