From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756404AbcIGHdC (ORCPT ); Wed, 7 Sep 2016 03:33:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43554 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752960AbcIGHdB (ORCPT ); Wed, 7 Sep 2016 03:33:01 -0400 Date: Wed, 7 Sep 2016 09:32:57 +0200 From: Jiri Olsa To: Kees Cook Cc: Andi Kleen , Jiri Olsa , lkml , Ingo Molnar , Adrian Hunter , KAMEZAWA Hiroyuki , Linus Torvalds Subject: Re: [PATCH] fs/proc/kcore.c: Omit kernel text area for hardened usercopy feature Message-ID: <20160907073257.GB8619@krava> References: <1472819145-27260-1-git-send-email-jolsa@kernel.org> <20160902151713.GM5871@two.firstfloor.org> <20160905084722.GA3134@krava> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.7.0 (2016-08-17) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 07 Sep 2016 07:33:00 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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