From: David Hildenbrand <david@redhat.com>
To: Lorenzo Stoakes <lstoakes@gmail.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>
Cc: Baoquan He <bhe@redhat.com>, Uladzislau Rezki <urezki@gmail.com>,
Matthew Wilcox <willy@infradead.org>,
Liu Shixin <liushixin2@huawei.com>, Jiri Olsa <jolsa@kernel.org>
Subject: Re: [PATCH v2 1/4] fs/proc/kcore: Avoid bounce buffer for ktext data
Date: Mon, 20 Mar 2023 10:58:48 +0100 [thread overview]
Message-ID: <2593f450-f65b-53ea-8b5d-d0bab89c1bfb@redhat.com> (raw)
In-Reply-To: <2ed992d6604965fd9eea05fed4473ddf54540989.1679209395.git.lstoakes@gmail.com>
On 19.03.23 08:09, 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 <lstoakes@gmail.com>
> ---
> 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:
Looks correct to me. The only difference between copy_to_user() and
_copy_to_user() is the check_copy_size() check, that ends up calling
check_kernel_text_object().
Reviewed-by: David Hildenbrand <david@redhat.com>
--
Thanks,
David / dhildenb
next prev parent reply other threads:[~2023-03-20 9:58 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-19 7:09 [PATCH v2 0/4] convert read_kcore(), vread() to use iterators Lorenzo Stoakes
2023-03-19 7:09 ` [PATCH v2 1/4] fs/proc/kcore: Avoid bounce buffer for ktext data Lorenzo Stoakes
2023-03-20 9:58 ` David Hildenbrand [this message]
2023-03-19 7:09 ` [PATCH v2 2/4] mm: vmalloc: use rwsem, mutex for vmap_area_lock and vmap_block->lock Lorenzo Stoakes
2023-03-19 20:10 ` Andrew Morton
2023-03-19 20:29 ` Lorenzo Stoakes
2023-03-19 20:47 ` Matthew Wilcox
2023-03-19 21:16 ` Lorenzo Stoakes
2023-03-20 8:40 ` Lorenzo Stoakes
2023-03-20 7:54 ` Uladzislau Rezki
2023-03-20 8:25 ` Lorenzo Stoakes
2023-03-20 8:32 ` Uladzislau Rezki
2023-03-20 8:35 ` Lorenzo Stoakes
2023-03-20 11:20 ` Uladzislau Rezki
2023-03-21 1:09 ` Dave Chinner
2023-03-21 5:23 ` Uladzislau Rezki
2023-03-21 7:45 ` Lorenzo Stoakes
2023-03-21 8:54 ` Uladzislau Rezki
2023-03-21 10:05 ` Dave Chinner
2023-03-21 10:24 ` Uladzislau Rezki
2023-03-22 13:18 ` Uladzislau Rezki
2023-03-22 17:47 ` Matthew Wilcox
2023-03-22 18:01 ` Uladzislau Rezki
2023-03-22 19:15 ` Uladzislau Rezki
2023-03-23 12:47 ` Uladzislau Rezki
2023-03-24 5:25 ` Dave Chinner
2023-03-24 5:31 ` Matthew Wilcox
2023-03-27 0:38 ` Dave Chinner
2023-03-27 17:22 ` Uladzislau Rezki
2023-03-28 2:53 ` Dave Chinner
2023-03-28 12:40 ` Uladzislau Rezki
2023-03-19 7:09 ` [PATCH v2 3/4] fs/proc/kcore: convert read_kcore() to read_kcore_iter() Lorenzo Stoakes
2023-03-19 7:09 ` [PATCH v2 4/4] mm: vmalloc: convert vread() to vread_iter() Lorenzo Stoakes
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=2593f450-f65b-53ea-8b5d-d0bab89c1bfb@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=bhe@redhat.com \
--cc=jolsa@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=liushixin2@huawei.com \
--cc=lstoakes@gmail.com \
--cc=urezki@gmail.com \
--cc=willy@infradead.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;
as well as URLs for NNTP newsgroup(s).