From patchwork Thu Oct 1 14:12:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11811535 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E61016CA for ; Thu, 1 Oct 2020 14:15:03 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B29A920B1F for ; Thu, 1 Oct 2020 14:15:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="GlVdHfZv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B29A920B1F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arndb.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+X2w+yLRwzuwRJp2PkbrNKJdS5d7C8TWWoA2CTXKWB4=; b=GlVdHfZvp8NMG3jfvyOM0j8V/ 3AVsF1cmt+TqmHBylpRXYBhzMhFZvmlvvZPiiM6+JKzhtUpPQrv8p9mqJAi6/rPzlct1WycvUzJJu zsImWvj+zC7ojX7773KGaJbwuDUFaUigNBZoBJwlQ5FO1gQM0m3H2zlaedQkIHIhYBv1kz9hSws/O rQTesqKtfRaTXOaQ5LB19wMq8Ux9IB15dJ4okzGhT/vmmnqnejH6AU0lADtryX6cOMdSxSO4TzUM9 AKD+0GjYDj4AtlQPwc/38XXfBFJWMKRycSv6mMup1spoOJszYY2Mkv42KPc7dwzcmwhSlX3O9Q18w /h6EzI/hg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kNzKR-0001DZ-9t; Thu, 01 Oct 2020 14:13:03 +0000 Received: from mout.kundenserver.de ([217.72.192.74]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kNzKN-00019A-4v for linux-arm-kernel@lists.infradead.org; Thu, 01 Oct 2020 14:13:00 +0000 Received: from threadripper.lan ([46.223.126.90]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1Mi2Fj-1ksOCT0Dcf-00e4nJ; Thu, 01 Oct 2020 16:12:52 +0200 From: Arnd Bergmann To: Russell King , Christoph Hellwig Subject: [PATCH v3 02/10] ARM: traps: use get_kernel_nofault instead of set_fs() Date: Thu, 1 Oct 2020 16:12:25 +0200 Message-Id: <20201001141233.119343-3-arnd@arndb.de> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201001141233.119343-1-arnd@arndb.de> References: <20201001141233.119343-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:bdOfhwwBBRSt/4DOOJUnmGtWrsvKQpezNqOznMTEofVRfuUQlXA X87CCp0XIB1Oa5guDvzEWLOmiOSrvDxOopnL87e93NYoWsre4aIkXzGrxlbH2ym5kNTLI18 ca4Ho0AXD0m7+Cy6A5vM4/eBgni/drXtxn7O69DSEVOkarAPXcTfVI0bU1cTLu0pQssoo8f Iu8KTgt6Y7CliDwvjbTMA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:Szc4dFsfUBQ=:nxTDskwhGfcu7ntfGfAaY+ Dd87fn4NarNP2ZDAd34jAMNnWjle8Z8Y40KlZCId3CLHJNmcd0VgIUH435tCedDcA2iVG8Mjp NI0saGFNQSvCKjYXru9oVIK/Hu092AIEmlXuoNUCk3V2i7yUjpBMMDCc0ob9H5Ic3SIU9p+JN QGxDJr6PArOdidNfXE3U+xPQoQbpA8dwL3i/0ogruuC806fXckMTOzE4GAXxo76Ojr03s13Ex im9qJpp7afwvZpqFNovt7YSI9So/vMueQFtQHr26MTMMMjigvHADShV/GmuGrYN6g741Hg7OM PSlm271Fxk65rjbFKDYIWPqLXiHoYQOlurJUtnCBHu1kKY1PS+JDFLJLR+kp73clhD7i/RyMB qz1APo7A05M8MxbFenXvRuD1WgYD7wGeU3yb39ZjOkydYpGOv20hPRLUJa0jqFx44mxFijmpj Y85WbeYL3D7nTEW9OQt6Su7gHvJpNvJ+VG0WccfE475shveN+wOJaHHa7CD6oguiWrstxvqHc NFqSeZJk8BBgRYi1dvnuT42ndGFJ2akvvG1Mamzu8vORSer1FlTexDM6jbujYolrzjkJolI7T igB/ESc3cepL10X/CjspXmECItQEIK8HesSTXpGBP0OScOVJoCPAEfrEtlSzjbJS6KIqiUkNI zv/BqMkN6ZZqr3evUfbyGktFanBMPpjUDHsJHc32+h3AlEas9uzZrrCXrocTpNFfGbXWGKZPL ur9R/fXrEFYrhIejn6Vx1oONXWDU/euG/FLAfAZLXkNqaz5kd7L8zPdE6M59pfmfgTwt5detd N0IZHwqihu/kbX6kNo+kiU+H6mrT/4miiTzZ7ku9FblfrbvepgUylk5KkgXSD4sruVXmZzI X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201001_101259_469507_378A1ECF X-CRM114-Status: GOOD ( 21.13 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [217.72.192.74 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [217.72.192.74 listed in wl.mailspike.net] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, Arnd Bergmann , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Viro , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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)==true is when the regs themselves are unreliable as a result of the condition that caused the trap. Reviewed-by: Christoph Hellwig 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 *str, unsigned long bottom, unsigned long top) { unsigned long first; - mm_segment_t fs; 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. - */ - fs = get_fs(); - set_fs(KERNEL_DS); - printk("%s%s(0x%08lx to 0x%08lx)\n", lvl, str, bottom, top); for (first = bottom & ~31; first < top; first += 32) { @@ -145,7 +136,7 @@ static void dump_mem(const char *lvl, const char *str, unsigned long bottom, for (p = first, i = 0; i < 8 && p < top; i++, p += 4) { if (p >= bottom && p < top) { unsigned long val; - if (__get_user(val, (unsigned long *)p) == 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 *str, unsigned long bottom, } printk("%s%04lx:%s\n", lvl, first & 0xffff, str); } - - 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); @@ -173,10 +162,20 @@ static void __dump_instr(const char *lvl, struct pt_regs *regs) for (i = -4; i < 1 + !!thumb; i++) { unsigned int val, bad; - if (thumb) - bad = get_user(val, &((u16 *)addr)[i]); - else - bad = get_user(val, &((u32 *)addr)[i]); + if (!user_mode(regs)) { + if (thumb) { + u16 val16; + bad = get_kernel_nofault(val16, &((u16 *)addr)[i]); + val = val16; + } else { + bad = get_kernel_nofault(val, &((u32 *)addr)[i]); + } + } else { + if (thumb) + bad = get_user(val, &((u16 *)addr)[i]); + else + bad = get_user(val, &((u32 *)addr)[i]); + } if (!bad) p += sprintf(p, i == 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); } -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 static inline void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk, const char *loglvl)