Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1478022

Re: [PATCH] fs/proc/kcore.c: Omit kernel text area for hardened usercopy feature

From Jiri Olsa <jolsa@redhat.com>
Newsgroups linux.kernel
Subject Re: [PATCH] fs/proc/kcore.c: Omit kernel text area for hardened usercopy feature
Date 2016-09-07 09:40 +0200
Message-ID <seFCF-59y-17@gated-at.bofh.it> (permalink)
References <scVLz-7Si-25@gated-at.bofh.it> <scYq5-16w-19@gated-at.bofh.it> <sdXLk-1lQ-5@gated-at.bofh.it> <sesPd-55p-11@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] fs/proc/kcore.c: Omit kernel text area for hardened usercopy feature Jiri Olsa <jolsa@kernel.org> - 2016-09-02 14:30 +0200
  Re: [PATCH] fs/proc/kcore.c: Omit kernel text area for hardened  usercopy feature Andi Kleen <andi@firstfloor.org> - 2016-09-02 17:20 +0200
    Re: [PATCH] fs/proc/kcore.c: Omit kernel text area for hardened  usercopy feature Jiri Olsa <jolsa@redhat.com> - 2016-09-02 18:20 +0200
    Re: [PATCH] fs/proc/kcore.c: Omit kernel text area for hardened  usercopy feature Jiri Olsa <jolsa@redhat.com> - 2016-09-05 10:50 +0200
      Re: [PATCH] fs/proc/kcore.c: Omit kernel text area for hardened  usercopy feature Andi Kleen <andi@firstfloor.org> - 2016-09-05 18:30 +0200
      Re: [PATCH] fs/proc/kcore.c: Omit kernel text area for hardened  usercopy feature Kees Cook <keescook@chromium.org> - 2016-09-06 20:00 +0200
        Re: [PATCH] fs/proc/kcore.c: Omit kernel text area for hardened  usercopy feature Linus Torvalds <torvalds@linux-foundation.org> - 2016-09-06 20:40 +0200
          Re: [PATCH] fs/proc/kcore.c: Omit kernel text area for hardened  usercopy feature Andi Kleen <andi@firstfloor.org> - 2016-09-06 21:50 +0200
            Re: [PATCH] fs/proc/kcore.c: Omit kernel text area for hardened  usercopy feature Linus Torvalds <torvalds@linux-foundation.org> - 2016-09-06 21:50 +0200
              Re: [PATCH] fs/proc/kcore.c: Omit kernel text area for hardened  usercopy feature Kees Cook <keescook@chromium.org> - 2016-09-07 19:20 +0200
                Re: [PATCH] fs/proc/kcore.c: Omit kernel text area for hardened  usercopy feature Linus Torvalds <torvalds@linux-foundation.org> - 2016-09-07 19:30 +0200
        Re: [PATCH] fs/proc/kcore.c: Omit kernel text area for hardened  usercopy feature Jiri Olsa <jolsa@redhat.com> - 2016-09-07 09:40 +0200
          Re: [PATCH] fs/proc/kcore.c: Omit kernel text area for hardened  usercopy feature Andi Kleen <andi@firstfloor.org> - 2016-09-07 18:40 +0200
            Re: [PATCH] fs/proc/kcore.c: Omit kernel text area for hardened  usercopy feature Linus Torvalds <torvalds@linux-foundation.org> - 2016-09-07 19:00 +0200
              Re: [PATCH] fs/proc/kcore.c: Omit kernel text area for hardened  usercopy feature Jiri Olsa <jolsa@redhat.com> - 2016-09-07 21:30 +0200
                Re: [PATCH] fs/proc/kcore.c: Omit kernel text area for hardened  usercopy feature Jiri Olsa <jolsa@redhat.com> - 2016-09-07 23:30 +0200
                Re: [PATCH] fs/proc/kcore.c: Omit kernel text area for hardened  usercopy feature Linus Torvalds <torvalds@linux-foundation.org> - 2016-09-08 01:00 +0200

csiph-web