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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65E4BEB64DD for ; Fri, 21 Jul 2023 13:48:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D93FC6B0071; Fri, 21 Jul 2023 09:48:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D44978D0002; Fri, 21 Jul 2023 09:48:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE5E48D0001; Fri, 21 Jul 2023 09:48:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id ACCAD6B0071 for ; Fri, 21 Jul 2023 09:48:53 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id BC9B21A031D for ; Fri, 21 Jul 2023 13:48:52 +0000 (UTC) X-FDA: 81035749704.18.C13AE70 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf13.hostedemail.com (Postfix) with ESMTP id E4C212001A for ; Fri, 21 Jul 2023 13:48:49 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fud8IBrH; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689947330; a=rsa-sha256; cv=none; b=e2keSFhf+2JBgZ4bl19vB72bMxgrO+AgS3Dp6tAygny1XSnFiZsFm8l9/u/lGhw8SrD80J 7kFZuWV1Uwk1SYPVHQe9y3P/0quEu4WZH6ELyqM6k0AxjGuUtZc/8VpC2DcknHJ3oAW3OF VHmoAeh4ZIbHZimXTzhL0zV1IManzp4= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fud8IBrH; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689947330; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+59IsCifznfcjfYMwQ8rMA4IccTRHGWrePtCutftbmo=; b=OF9G1OdRIJLpKJKV4O52iZG1laU4kdN0qwKIWFrnmaK3W0DgdKPGEQ0q1nr/hCMBa4KQ/P t/bv5n5X6xyIf2bPG3RENeBQTgGkSLpS17SfDb8H5DJan72XWirjXn8TgRAZNeEu+0MEDo /R/AeFKHb9CA1j4AWIw7Vd2Qndad99o= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689947329; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+59IsCifznfcjfYMwQ8rMA4IccTRHGWrePtCutftbmo=; b=fud8IBrHs5AnenFfOS7wLwUilSax4ucg8v8L61wxt/B+FmcvXbxRq5vyuSTxS/9y+HzpBh M/gVEOOTIGsh26bjeCyrR7FGIIeDDd0H6RGPcRNOjZW9wXMla0cexDpfzaR1igGIDbwJVV aVWyLZwpPd2nQumSmKIFKJiZbEmF8rA= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-512-_7G0T2gjOm2_EVha-4a6RQ-1; Fri, 21 Jul 2023 09:48:42 -0400 X-MC-Unique: _7G0T2gjOm2_EVha-4a6RQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 092A93815EEE; Fri, 21 Jul 2023 13:48:42 +0000 (UTC) Received: from localhost (ovpn-12-18.pek2.redhat.com [10.72.12.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1FE16492B03; Fri, 21 Jul 2023 13:48:40 +0000 (UTC) Date: Fri, 21 Jul 2023 21:48:37 +0800 From: Baoquan He To: Jiri Olsa Cc: Lorenzo Stoakes , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Andrew Morton , Uladzislau Rezki , Matthew Wilcox , David Hildenbrand , Liu Shixin , Jens Axboe , Alexander Viro Subject: Re: [PATCH v8 1/4] fs/proc/kcore: avoid bounce buffer for ktext data Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: E4C212001A X-Stat-Signature: herx1ntdaitozshpzmynb78b7f85wjpz X-HE-Tag: 1689947329-838373 X-HE-Meta: U2FsdGVkX1/24ZBwALfLMfEXC+AHpFuJMH91i9SsPPu6ncxNlfNFpMcxSwcikhapBcUgz3YLug2l0xzoawDmfHFYKtCXlKPmSMN5S3sypV1fEEgqXqhIT8VdoyjstlFUyE8Vdy72RhYKg0vlH9T49lSsEd60YRsIk6g7yP9YS5UgRoO4/wlqRoUWseg+J3+75ZAV5fT5UeBn2awUVht6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mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi Jiri, On 05/31/23 at 01:58pm, Jiri Olsa wrote: > On Thu, Mar 23, 2023 at 10:15:16AM +0000, Lorenzo Stoakes wrote: > > Commit df04abfd181a ("fs/proc/kcore.c: Add bounce buffer for ktext data") > > introduced the use of a bounce buffer to retrieve kernel text data for > > /proc/kcore in order to avoid failures arising from hardened user copies > > enabled by CONFIG_HARDENED_USERCOPY in check_kernel_text_object(). > > > > We can avoid doing this if instead of copy_to_user() we use _copy_to_user() > > which bypasses the hardening check. This is more efficient than using a > > bounce buffer and simplifies the code. > > > > We do so as part an overall effort to eliminate bounce buffer usage in the > > function with an eye to converting it an iterator read. > > > > Signed-off-by: Lorenzo Stoakes > > Reviewed-by: David Hildenbrand > > hi, > sorry for late feedback, but looks like this one breaks reading > /proc/kcore with objdump for me: > > # cat /proc/kallsyms | grep ksys_read > ffffffff8150ebc0 T ksys_read > # objdump -d --start-address=0xffffffff8150ebc0 --stop-address=0xffffffff8150ebd0 /proc/kcore > > /proc/kcore: file format elf64-x86-64 > > objdump: Reading section load1 failed because: Bad address > > reverting this makes it work again I met this too when I executed below command to trigger a kcore reading. I wanted to do a simple testing during system running and got this. makedumpfile --mem-usage /proc/kcore Later I tried your above objdump testing, it corrupted system too. Is there any conclusion about this issue you reported? I could miss things in the discussion or patch posting to fix this. Thanks Baoquan > > > > --- > > fs/proc/kcore.c | 17 +++++------------ > > 1 file changed, 5 insertions(+), 12 deletions(-) > > > > diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c > > index 71157ee35c1a..556f310d6aa4 100644 > > --- a/fs/proc/kcore.c > > +++ b/fs/proc/kcore.c > > @@ -541,19 +541,12 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) > > case KCORE_VMEMMAP: > > case KCORE_TEXT: > > /* > > - * Using bounce buffer to bypass the > > - * hardened user copy kernel text checks. > > + * We use _copy_to_user() to bypass usermode hardening > > + * which would otherwise prevent this operation. > > */ > > - if (copy_from_kernel_nofault(buf, (void *)start, tsz)) { > > - if (clear_user(buffer, tsz)) { > > - ret = -EFAULT; > > - goto out; > > - } > > - } else { > > - if (copy_to_user(buffer, buf, tsz)) { > > - ret = -EFAULT; > > - goto out; > > - } > > + if (_copy_to_user(buffer, (char *)start, tsz)) { > > + ret = -EFAULT; > > + goto out; > > } > > break; > > default: > > -- > > 2.39.2 > > >