mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Amerigo Wang <amwang@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: WANG Cong <amwang@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Neil Horman <nhorman@tuxdriver.com>,
	WANG Cong <xiyou.wangcong@gmail.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Wu Fengguang <fengguang.wu@intel.com>,
	Dan Carpenter <error27@gmail.com>, Tejun Heo <tj@kernel.org>
Subject: [RFC Patch] kcore: restrict access to the whole memory
Date: Wed, 22 Dec 2010 19:21:59 +0800	[thread overview]
Message-ID: <1293016926-1714-1-git-send-email-amwang@redhat.com> (raw)

This patch restricts /proc/kcore from accessing the whole memory,
instead, only an ELF header can be read.

The initial patch was done by Vivek.

Signed-off-by: WANG Cong <amwang@redhat.com>

---
diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
index 6a00688..2fd1df1 100644
--- a/fs/proc/Kconfig
+++ b/fs/proc/Kconfig
@@ -32,6 +32,14 @@ config PROC_KCORE
 	bool "/proc/kcore support" if !ARM
 	depends on PROC_FS && MMU
 
+config STRICT_PROC_KCORE
+	bool "Only export an ELF header from /proc/kcore"
+	depends on PROC_KCORE
+	default n
+	help
+	If this option is enabled, only an ELF header can be read from
+	/proc/kcore, instead of a whole ELF image.
+
 config PROC_VMCORE
 	bool "/proc/vmcore support"
 	depends on PROC_FS && CRASH_DUMP
diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
index 6f37c39..c45ff00 100644
--- a/fs/proc/kcore.c
+++ b/fs/proc/kcore.c
@@ -90,7 +90,12 @@ static size_t get_kcore_size(int *nphdr, size_t *elf_buflen)
 			roundup(sizeof(struct elf_prpsinfo), 4) +
 			roundup(sizeof(struct task_struct), 4);
 	*elf_buflen = PAGE_ALIGN(*elf_buflen);
+#ifdef CONFIG_STRICT_PROC_KCORE
+	return *elf_buflen;
+#else
 	return size + *elf_buflen;
+#endif
+
 }
 
 static void free_kclist_ents(struct list_head *head)
@@ -429,7 +434,7 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
 	size_t size, tsz;
 	size_t elf_buflen;
 	int nphdr;
-	unsigned long start;
+	unsigned long __maybe_unused start;
 
 	read_lock(&kclist_lock);
 	size = get_kcore_size(&nphdr, &elf_buflen);
@@ -473,6 +478,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
 	} else
 		read_unlock(&kclist_lock);
 
+#ifdef CONFIG_STRICT_PROC_KCORE
+	return acc;
+#else
 	/*
 	 * Check to see if our file offset matches with any of
 	 * the addresses in the elf_phdr on our list.
@@ -537,6 +545,7 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
 	}
 
 	return acc;
+#endif
 }
 
 

             reply	other threads:[~2010-12-22 11:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-22 11:21 Amerigo Wang [this message]
2010-12-22 23:02 ` Andrew Morton
2010-12-23 10:01   ` Cong Wang
2010-12-23 14:39     ` Eugene Teo

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=1293016926-1714-1-git-send-email-amwang@redhat.com \
    --to=amwang@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=error27@gmail.com \
    --cc=fengguang.wu@intel.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    --cc=tj@kernel.org \
    --cc=xiyou.wangcong@gmail.com \
    /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

Powered by JetHome