From: Jiri Olsa <jolsa@redhat.com>
To: Kees Cook <keescook@chromium.org>
Cc: Andi Kleen <andi@firstfloor.org>, Jiri Olsa <jolsa@kernel.org>,
lkml <linux-kernel@vger.kernel.org>,
Ingo Molnar <mingo@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH] fs/proc/kcore.c: Omit kernel text area for hardened usercopy feature
Date: Wed, 7 Sep 2016 09:32:57 +0200 [thread overview]
Message-ID: <20160907073257.GB8619@krava> (raw)
In-Reply-To: <CAGXu5jLfvx0w+uVbrcVky7hS-6VsSRStOjEyCt6TUqgA7s6OVg@mail.gmail.com>
On Tue, Sep 06, 2016 at 01:56:40PM -0400, Kees Cook wrote:
SNIP
> > static __must_check __always_inline int
> > diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
> > index a939f5ed7f89..c7a22a8a157e 100644
> > --- a/fs/proc/kcore.c
> > +++ b/fs/proc/kcore.c
> > @@ -516,7 +516,7 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
> > if (kern_addr_valid(start)) {
> > unsigned long n;
> >
> > - n = copy_to_user(buffer, (char *)start, tsz);
> > + n = copy_to_user_nocheck(buffer, (char *)start, tsz);
> > /*
> > * We cannot distinguish between fault on source
> > * and fault on destination. When this happens
>
> This patch is x86-specific (but ARCH_PROC_KCORE_TEXT is on multiple
> architectures), which I don't think we want. Instead, let's get the
> usercopy helper code centralized (Al Viro is looking at this already),
> and then we can design arch-agnostic methods to handle this.
>
> In the meantime, how about continuing to use a bounce buffer like
> already done in the vmalloc_or_module_addr() case immediately above?
ok, sounds good.. so something like below? untested
thanks,
jirka
---
diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
index a939f5ed7f89..de07c273f725 100644
--- a/fs/proc/kcore.c
+++ b/fs/proc/kcore.c
@@ -515,8 +515,20 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
} else {
if (kern_addr_valid(start)) {
unsigned long n;
+ char *buf;
- n = copy_to_user(buffer, (char *)start, tsz);
+ buf = kzalloc(tsz, GFP_KERNEL);
+ if (!buf)
+ return -ENOMEM;
+
+ /*
+ * Using bounce buffer to bypass the hardened
+ * user copy kernel text checks.
+ */
+ memcpy(buf, (char *) start, tsz);
+
+ n = copy_to_user(buffer, buf, tsz);
+ kfree(buf);
/*
* We cannot distinguish between fault on source
* and fault on destination. When this happens
next prev parent reply other threads:[~2016-09-07 7:33 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-02 12:25 [PATCH] fs/proc/kcore.c: Omit kernel text area for hardened usercopy feature Jiri Olsa
2016-09-02 15:17 ` Andi Kleen
2016-09-02 16:15 ` Jiri Olsa
2016-09-05 8:47 ` Jiri Olsa
2016-09-05 16:27 ` Andi Kleen
2016-09-06 17:56 ` Kees Cook
2016-09-06 18:34 ` Linus Torvalds
2016-09-06 19:41 ` Andi Kleen
2016-09-06 19:48 ` Linus Torvalds
2016-09-07 17:17 ` Kees Cook
2016-09-07 17:24 ` Linus Torvalds
2016-09-07 7:32 ` Jiri Olsa [this message]
2016-09-07 16:38 ` Andi Kleen
2016-09-07 16:58 ` Linus Torvalds
2016-09-07 19:25 ` Jiri Olsa
2016-09-07 21:24 ` Jiri Olsa
2016-09-07 22:52 ` Linus Torvalds
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=20160907073257.GB8619@krava \
--to=jolsa@redhat.com \
--cc=adrian.hunter@intel.com \
--cc=andi@firstfloor.org \
--cc=jolsa@kernel.org \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=torvalds@linux-foundation.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