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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBA66C6FD1C for ; Wed, 22 Mar 2023 22:50:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229497AbjCVWu4 (ORCPT ); Wed, 22 Mar 2023 18:50:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229597AbjCVWuy (ORCPT ); Wed, 22 Mar 2023 18:50:54 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E41A06E90 for ; Wed, 22 Mar 2023 15:50:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 9E65BB81D54 for ; Wed, 22 Mar 2023 22:50:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 346FAC433D2; Wed, 22 Mar 2023 22:50:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1679525450; bh=+8SmVT4TRpFH+r4dEhxae82IC3JykMCMbWI7LIA5i9Y=; h=Date:To:From:Subject:From; b=U8qGb5b5XFZepBpZH81xJOrnekHnkYmEyiizYSvzMN1VWpKm8tKjvjEvPevuEw2h9 +T/XSBQOTR9iVxcJnwkSl3OZFbwElpIIO2FurTk3crDwdcDukQ7Mi8VYy3nFgrSmo7 OG0QiT/wbnU+enoZ2xGWdj7eYeM3uItTJYylpWM8= Date: Wed, 22 Mar 2023 15:50:49 -0700 To: mm-commits@vger.kernel.org, willy@infradead.org, viro@zeniv.linux.org.uk, urezki@gmail.com, liushixin2@huawei.com, jolsa@kernel.org, david@redhat.com, bhe@redhat.com, axboe@kernel.dk, lstoakes@gmail.com, akpm@linux-foundation.org From: Andrew Morton Subject: + fs-proc-kcore-avoid-bounce-buffer-for-ktext-data.patch added to mm-unstable branch Message-Id: <20230322225050.346FAC433D2@smtp.kernel.org> Precedence: bulk Reply-To: linux-kernel@vger.kernel.org List-ID: X-Mailing-List: mm-commits@vger.kernel.org The patch titled Subject: fs/proc/kcore: avoid bounce buffer for ktext data has been added to the -mm mm-unstable branch. Its filename is fs-proc-kcore-avoid-bounce-buffer-for-ktext-data.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/fs-proc-kcore-avoid-bounce-buffer-for-ktext-data.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Lorenzo Stoakes Subject: fs/proc/kcore: avoid bounce buffer for ktext data Date: Wed, 22 Mar 2023 18:57:01 +0000 Patch series "convert read_kcore(), vread() to use iterators", v7. While reviewing Baoquan's recent changes to permit vread() access to vm_map_ram regions of vmalloc allocations, Willy pointed out [1] that it would be nice to refactor vread() as a whole, since its only user is read_kcore() and the existing form of vread() necessitates the use of a bounce buffer. This patch series does exactly that, as well as adjusting how we read the kernel text section to avoid the use of a bounce buffer in this case as well. This has been tested against the test case which motivated Baoquan's changes in the first place [2] which continues to function correctly, as do the vmalloc self tests. This patch (of 4): 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. Link: https://lore.kernel.org/all/Y8WfDSRkc%2FOHP3oD@casper.infradead.org/ [1] Link: https://lore.kernel.org/all/87ilk6gos2.fsf@oracle.com/T/#u [2] Link: https://lkml.kernel.org/r/fd39b0bfa7edc76d360def7d034baaee71d90158.1679511146.git.lstoakes@gmail.com Signed-off-by: Lorenzo Stoakes Reviewed-by: David Hildenbrand Cc: Alexander Viro Cc: Baoquan He Cc: Jens Axboe Cc: Jiri Olsa Cc: Liu Shixin Cc: Matthew Wilcox (Oracle) Cc: Uladzislau Rezki (Sony) Signed-off-by: Andrew Morton --- --- a/fs/proc/kcore.c~fs-proc-kcore-avoid-bounce-buffer-for-ktext-data +++ a/fs/proc/kcore.c @@ -541,19 +541,12 @@ read_kcore(struct file *file, char __use 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: _ Patches currently in -mm which might be from lstoakes@gmail.com are mm-prefer-xxx_page-alloc-free-functions-for-order-0-pages.patch mm-refactor-do_fault_around.patch mm-pefer-fault_around_pages-to-fault_around_bytes.patch maintainers-add-myself-as-vmalloc-reviewer.patch mm-remove-unused-vmf_insert_mixed_prot.patch mm-remove-vmf_insert_pfn_xxx_prot-for-huge-page-table-entries.patch drm-ttm-remove-comment-referencing-now-removed-vmf_insert_mixed_prot.patch fs-proc-kcore-avoid-bounce-buffer-for-ktext-data.patch fs-proc-kcore-convert-read_kcore-to-read_kcore_iter.patch iov_iter-add-copy_page_to_iter_nofault.patch mm-vmalloc-convert-vread-to-vread_iter.patch mm-mmap-vma_merge-further-improve-prev-next-vma-naming.patch mm-mmap-vma_merge-fold-curr-next-assignment-logic.patch mm-mmap-vma_merge-explicitly-assign-res-vma-extend-invariants.patch mm-mmap-vma_merge-init-cleanup-be-explicit-about-the-non-mergeable-case.patch