From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65236C4346B for ; Fri, 18 Sep 2020 12:46:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 052DC21D24 for ; Fri, 18 Sep 2020 12:46:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 052DC21D24 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arndb.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 34D276B006E; Fri, 18 Sep 2020 08:46:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2881A6B006C; Fri, 18 Sep 2020 08:46:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F31FD6B005D; Fri, 18 Sep 2020 08:46:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0180.hostedemail.com [216.40.44.180]) by kanga.kvack.org (Postfix) with ESMTP id DA9E86B005A for ; Fri, 18 Sep 2020 08:46:40 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id A8E8E3629 for ; Fri, 18 Sep 2020 12:46:40 +0000 (UTC) X-FDA: 77276156160.02.table85_33052242712b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id 96439100D211F for ; Fri, 18 Sep 2020 12:46:40 +0000 (UTC) X-HE-Tag: table85_33052242712b X-Filterd-Recvd-Size: 5855 Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.134]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Fri, 18 Sep 2020 12:46:39 +0000 (UTC) Received: from threadripper.lan ([149.172.98.151]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.129]) with ESMTPA (Nemesis) id 1MTRAS-1jtycg3laG-00Ti0L; Fri, 18 Sep 2020 14:46:34 +0200 From: Arnd Bergmann To: Christoph Hellwig , Russell King , Alexander Viro Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, Arnd Bergmann Subject: [PATCH v2 2/9] ARM: traps: use get_kernel_nofault instead of set_fs() Date: Fri, 18 Sep 2020 14:46:17 +0200 Message-Id: <20200918124624.1469673-3-arnd@arndb.de> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200918124624.1469673-1-arnd@arndb.de> References: <20200918124624.1469673-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:Gy/6r3hP6+Xw0VZ1kPuBOfmudRbDMtnh6jF154kk+qnOsu9JUCQ cQK0bo1hDNYXTK9JI2Na6UKfmHCGL9OWP+7LGyS/kOe6Uc9yJbO9xExzSioQ0OF5BPd/C1V nmlIEcSh3DpIrVLDUZebSlnT9QnSnvqCMQd9I2RYk49O2SSMFV8/sb0VnF6GCOz06mOntBv vtRVwI+wzeyGhICf15/8w== X-UI-Out-Filterresults: notjunk:1;V03:K0:DMblnyBKhY4=:9xYkhBDiYrvF2PKMOZ5/jd 7itoiVV6ScsHcK8wPs3xmfxSSrugMrRfii48gNLwyhVjnLhHsCHeIToONufxWhSJtWjqp50Rd dIhEumG+L/4r73Q7OyhK/FrDYOmZctzBbZbyaVJ4wQqNud37Mn9XLeJ8YXD11XGCYC0p6i9Ge aOPWKJtnHknCvEXZxHrj6X8nCWU097zi0wIqq8hmcU+urPAHVQ7Y29zGk/ELMlP4oGdhPlU52 6I+dJDkdUkKfntHzL5sCVutRX7EueaRKoTpxc2faPKlwJQxnGn7NyNFxjeypshD9UPmkv0qIz uylSZc/nektnaiR3D6IRhQZJMwJDykBoIe8C3jk0bbNnCInQBu4lL/0wQ2RHfnusS4U0glwC8 SD2DQohnsrGmHMGnbqEnN7XTejaUW+b9phi85MVOtGtIEuN4980eeaFVIsMTkklxbhhq3oHCf L/0jbGnUehzANInlLiBFQiyHWJ6O4vsTWFpWso1N3zvn1ePT3/CLrnhkUTYZrdnoAHZ+GQAbH 3ZfCZ13w4NlZrcq9AiIZ93tkymhgVfkaxx4TATAiRc5BNr+tkMSj0wWdKy4ArwL6Sk95+LKBK GxcEz1kzhIFPShl/11Yi7N2GGdiN0cZntPvNNU8dwnwdzcSzUnJS8OjxdNgYRBjR8O6eyP7Cr dlsU4otbC8UOXe3bQ6WT2de5wyXNscPVST3gquGhFq+RSacYFwmiUJq4YwmSjeapSR6o3uXck zD+Ip58BziCarZCj5aMUGzFfn/jRUcoejVakvpvdBJ3pK87EOfqMQYxnulXte+co+uheW/4yI FNjRnYXt1zm6T5mNTFcR7DRZP8334b7k9fdnpA8MGg/BI710j6z9SMcAT4z3EUHAhn6bPeJ Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: ARM uses set_fs() and __get_user() to allow the stack dumping code to access possibly invalid pointers carefully. These can be changed to the simpler get_kernel_nofault(), and allow the eventual removal of set_fs(). dump_instr() will print either kernel or user space pointers, depending on how it was called. For dump_mem(), I assume we are only interested in kernel pointers, and the only time that this is called with user_mode(regs)=3D=3Dtrue is when the regs themselves are unreliable as a result of the condition that caused the trap. Signed-off-by: Arnd Bergmann --- arch/arm/kernel/traps.c | 47 ++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c index 17d5a785df28..c3964a283b63 100644 --- a/arch/arm/kernel/traps.c +++ b/arch/arm/kernel/traps.c @@ -122,17 +122,8 @@ static void dump_mem(const char *lvl, const char *st= r, unsigned long bottom, unsigned long top) { unsigned long first; - mm_segment_t fs; int i; =20 - /* - * 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. - */ - fs =3D get_fs(); - set_fs(KERNEL_DS); - printk("%s%s(0x%08lx to 0x%08lx)\n", lvl, str, bottom, top); =20 for (first =3D bottom & ~31; first < top; first +=3D 32) { @@ -145,7 +136,7 @@ static void dump_mem(const char *lvl, const char *str= , unsigned long bottom, for (p =3D first, i =3D 0; i < 8 && p < top; i++, p +=3D 4) { if (p >=3D bottom && p < top) { unsigned long val; - if (__get_user(val, (unsigned long *)p) =3D=3D 0) + if (get_kernel_nofault(val, (unsigned long *)p)) sprintf(str + i * 9, " %08lx", val); else sprintf(str + i * 9, " ????????"); @@ -153,11 +144,9 @@ static void dump_mem(const char *lvl, const char *st= r, unsigned long bottom, } printk("%s%04lx:%s\n", lvl, first & 0xffff, str); } - - set_fs(fs); } =20 -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 =3D instruction_pointer(regs); const int thumb =3D thumb_mode(regs); @@ -173,10 +162,20 @@ static void __dump_instr(const char *lvl, struct pt= _regs *regs) for (i =3D -4; i < 1 + !!thumb; i++) { unsigned int val, bad; =20 - if (thumb) - bad =3D get_user(val, &((u16 *)addr)[i]); - else - bad =3D get_user(val, &((u32 *)addr)[i]); + if (!user_mode(regs)) { + if (thumb) { + u16 val16; + bad =3D get_kernel_nofault(val16, &((u16 *)addr)[i]); + val =3D val16; + } else { + bad =3D get_kernel_nofault(val, &((u32 *)addr)[i]); + } + } else { + if (thumb) + bad =3D get_user(val, &((u16 *)addr)[i]); + else + bad =3D get_user(val, &((u32 *)addr)[i]); + } =20 if (!bad) p +=3D sprintf(p, i =3D=3D 0 ? "(%0*x) " : "%0*x ", @@ -189,20 +188,6 @@ static void __dump_instr(const char *lvl, struct pt_= regs *regs) printk("%sCode: %s\n", lvl, str); } =20 -static void dump_instr(const char *lvl, struct pt_regs *regs) -{ - mm_segment_t fs; - - if (!user_mode(regs)) { - fs =3D get_fs(); - set_fs(KERNEL_DS); - __dump_instr(lvl, regs); - set_fs(fs); - } else { - __dump_instr(lvl, regs); - } -} - #ifdef CONFIG_ARM_UNWIND static inline void dump_backtrace(struct pt_regs *regs, struct task_stru= ct *tsk, const char *loglvl) --=20 2.27.0