From: Nick Hu <nickhu@andestech.com>
To: Christoph Hellwig <hch@lst.de>
Cc: <green.hu@gmail.com>, <deanbo422@gmail.com>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] nds32: use get_kernel_nofault in dump_mem
Date: Tue, 21 Jul 2020 19:07:17 +0800 [thread overview]
Message-ID: <20200721110717.GA19721@atcfdc88> (raw)
In-Reply-To: <20200720114448.205876-2-hch@lst.de>
On Mon, Jul 20, 2020 at 01:44:48PM +0200, Christoph Hellwig wrote:
> Use the proper get_kernel_nofault helper to access an unsafe kernel
> pointer without faulting instead of playing with set_fs and get_user.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> arch/nds32/kernel/traps.c | 15 +++------------
> 1 file changed, 3 insertions(+), 12 deletions(-)
>
> diff --git a/arch/nds32/kernel/traps.c b/arch/nds32/kernel/traps.c
> index b66f889bc6df9b..ee0d9ae192a504 100644
> --- a/arch/nds32/kernel/traps.c
> +++ b/arch/nds32/kernel/traps.c
> @@ -25,17 +25,8 @@ extern void show_pte(struct mm_struct *mm, unsigned long addr);
> void dump_mem(const char *lvl, 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);
> -
> pr_emerg("%s(0x%08lx to 0x%08lx)\n", lvl, bottom, top);
>
> for (first = bottom & ~31; first < top; first += 32) {
> @@ -48,7 +39,9 @@ void dump_mem(const char *lvl, unsigned long bottom, unsigned long top)
> 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) == 0)
> sprintf(str + i * 9, " %08lx", val);
> else
> sprintf(str + i * 9, " ????????");
> @@ -56,8 +49,6 @@ void dump_mem(const char *lvl, unsigned long bottom, unsigned long top)
> }
> pr_emerg("%s%04lx:%s\n", lvl, first & 0xffff, str);
> }
> -
> - set_fs(fs);
> }
>
> EXPORT_SYMBOL(dump_mem);
> --
> 2.27.0
>
Hi Christoph,
Thank you!
Acked-by: Nick Hu <nickhu@andestech.com>
next prev parent reply other threads:[~2020-07-21 11:19 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-20 11:44 [PATCH 1/2] nds32: remove dump_instr Christoph Hellwig
2020-07-20 11:44 ` [PATCH 2/2] nds32: use get_kernel_nofault in dump_mem Christoph Hellwig
2020-07-21 11:07 ` Nick Hu [this message]
2020-07-21 11:28 ` Christoph Hellwig
2021-01-28 10:16 ` Christoph Hellwig
2021-02-24 7:47 ` Christoph Hellwig
2021-02-24 8:59 ` Greentime Hu
2021-02-24 9:02 ` Christoph Hellwig
2020-07-21 11:08 ` [PATCH 1/2] nds32: remove dump_instr Nick Hu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200721110717.GA19721@atcfdc88 \
--to=nickhu@andestech.com \
--cc=deanbo422@gmail.com \
--cc=green.hu@gmail.com \
--cc=hch@lst.de \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox