Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp635983ybh; Tue, 21 Jul 2020 04:20:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLtlyY2ozXOpgv9lVr5s5TwDwGtlPbgEQjCmx4sEMaDiX9NXqzQNnqUByRcNQ0VLGJkoE/ X-Received: by 2002:a17:906:469a:: with SMTP id a26mr21350784ejr.198.1595330412997; Tue, 21 Jul 2020 04:20:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595330412; cv=none; d=google.com; s=arc-20160816; b=EiNmyW2+hcgRu0mf4Q+vOoPugcJ12+g1/GAs1jCo94X+xZeCa3YGNKDelRI10jd2xU WDu0hO4gbaEJJbQBw2ypxp7eIMP3inR1cf6I1rE5S79l4aJv+NGbsUuuH/CKiOacPuM1 G2cz1JnZhu0S7ygVuCl4Mj9xF5Axsb3T6UlcuPSxCOvuAEYQwqB78npfKHMMLGeYzmlJ 6YogKxjF5lch+35HnbAsiymYres9ISec7LhoOca9zhrtTP9Vg2MGJcar385ZsRAyzIoC SVCRZtSQzACKlM3bIY0mYzznCK0Msbq/wKoxow5wizZrUoCqDoi3251GqmyrBPRhexWl YKdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=D8jCzns4y/B3F77NIoDpU/N5LFdkUBE405IeC/iq0Xw=; b=NcJ5c4AWOyZdPpOtt1epHPJRwWH5+i0HnN5ofIJFCpwgJWQrmKAEmbPb9ENgPDNtne 4wAK+dPq4ErJ8Uyf6QmWEzYjpx60ulN0eJ56WMllGzYG4E6JePcS7bHG1i4cRbJZnEhM mErsfoHw7hret26S+8eDkZa/SsI5eG1LI9DX3gl68zeGZrpw7QNd2fre6eHGJhw/Pjsw 0uMmbFDi/mJ9Bo+yQVKl6WRz8MrygtiZcXAHViQhsPWCP9LLE2TwwbSEPV8Z4z1VBVJ0 eunfP7r65Nd7aA3P1foi37KgnRFWJ+YTf+MUKhrvr7iWcUmIPiZrFb2VwdhcaTR1tBJD CCYA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b15si11068829edt.394.2020.07.21.04.19.49; Tue, 21 Jul 2020 04:20:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727916AbgGULTn (ORCPT + 99 others); Tue, 21 Jul 2020 07:19:43 -0400 Received: from exmail.andestech.com ([60.248.187.195]:44066 "EHLO ATCSQR.andestech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727043AbgGULTm (ORCPT ); Tue, 21 Jul 2020 07:19:42 -0400 X-Greylist: delayed 725 seconds by postgrey-1.27 at vger.kernel.org; Tue, 21 Jul 2020 07:19:41 EDT Received: from ATCSQR.andestech.com (localhost [127.0.0.2] (may be forged)) by ATCSQR.andestech.com with ESMTP id 06LAwicE080338 for ; Tue, 21 Jul 2020 18:58:44 +0800 (GMT-8) (envelope-from nickhu@andestech.com) Received: from mail.andestech.com (atcpcs16.andestech.com [10.0.1.222]) by ATCSQR.andestech.com with ESMTP id 06LAwPXe080275; Tue, 21 Jul 2020 18:58:25 +0800 (GMT-8) (envelope-from nickhu@andestech.com) Received: from atcfdc88 (10.0.15.132) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.123.3; Tue, 21 Jul 2020 19:07:15 +0800 Date: Tue, 21 Jul 2020 19:07:17 +0800 From: Nick Hu To: Christoph Hellwig CC: , , Subject: Re: [PATCH 2/2] nds32: use get_kernel_nofault in dump_mem Message-ID: <20200721110717.GA19721@atcfdc88> References: <20200720114448.205876-1-hch@lst.de> <20200720114448.205876-2-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20200720114448.205876-2-hch@lst.de> User-Agent: Mutt/1.9.4 (2018-02-28) X-Originating-IP: [10.0.15.132] X-DNSRBL: X-MAIL: ATCSQR.andestech.com 06LAwPXe080275 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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