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.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 56184C00A89 for ; Fri, 30 Oct 2020 15:49:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D11B8221FA for ; Fri, 30 Oct 2020 15:49:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="TWyfwhH4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D11B8221FA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 465876B0074; Fri, 30 Oct 2020 11:49:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3ED9D6B0075; Fri, 30 Oct 2020 11:49:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2B7186B0078; Fri, 30 Oct 2020 11:49:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0182.hostedemail.com [216.40.44.182]) by kanga.kvack.org (Postfix) with ESMTP id E52C66B0074 for ; Fri, 30 Oct 2020 11:49:34 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 8CC2D247F for ; Fri, 30 Oct 2020 15:49:34 +0000 (UTC) X-FDA: 77429026668.05.egg26_530151d27297 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id 6DD69180199C6 for ; Fri, 30 Oct 2020 15:49:34 +0000 (UTC) X-HE-Tag: egg26_530151d27297 X-Filterd-Recvd-Size: 5222 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Fri, 30 Oct 2020 15:49:33 +0000 (UTC) Received: from localhost.localdomain (HSI-KBW-46-223-126-90.hsi.kabel-badenwuerttemberg.de [46.223.126.90]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 45B6C2151B; Fri, 30 Oct 2020 15:49:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604072972; bh=ZWVfnKETIZSkSXx6wtt9uwQPqWB73y+8PUTcomvoy2w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TWyfwhH4qhKP35A1ntbbH2uTPQAKolFdHFHrtSWwJy5Sq5MvZ555anM/3vysGQt3y VQVFD3UKiR9sA0ZvC/Z2NGFLAwjkgRWm6gMwYLIrEkgPnGIiqou5iSFnPMElVNJU08 Q5LxJVIxJgvA6T5x1TmH6oh+G31HTu67VEszV24o= From: Arnd Bergmann To: Russell King , Christoph Hellwig Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, viro@zeniv.linux.org.uk, linus.walleij@linaro.org, arnd@arndb.de Subject: [PATCH 2/9] ARM: traps: use get_kernel_nofault instead of set_fs() Date: Fri, 30 Oct 2020 16:49:12 +0100 Message-Id: <20201030154919.1246645-2-arnd@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201030154919.1246645-1-arnd@kernel.org> References: <20201030154519.1245983-1-arnd@kernel.org> <20201030154919.1246645-1-arnd@kernel.org> MIME-Version: 1.0 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: From: Arnd Bergmann 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. 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 *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