linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/9] proc: protect /proc/<pid>/* files across execve
@ 2012-03-10 23:25 Djalal Harouni
  2012-03-10 23:25 ` [PATCH 1/9] exec: add a global execve counter Djalal Harouni
                   ` (10 more replies)
  0 siblings, 11 replies; 48+ messages in thread
From: Djalal Harouni @ 2012-03-10 23:25 UTC (permalink / raw)
  To: linux-kernel, kernel-hardening, Andrew Morton, Linus Torvalds,
	Al Viro, Alexey Dobriyan, Eric W. Biederman, Vasiliy Kulikov,
	Kees Cook, Solar Designer, WANG Cong, James Morris, Oleg Nesterov,
	linux-security-module, linux-fsdevel
  Cc: Alan Cox, Greg KH, Ingo Molnar, Stephen Wilson,
	Jason A. Donenfeld, Djalal Harouni

Procfs files and other important objects may contain sensitive information
which must not be seen, inherited or processed across execve.
The commit e268337dfe26dfc7efd422a804dbb27977a3cccc tries to fix the same
problem, but that leaves all the other sensitive /proc/<pid>/* files which
includes the {maps,smaps,numa_maps} files that can be used to bypass ASLR
(there is a PoC to demonstrate it). We should also note that currently the
/proc/<pid>/mem fix will pin mm_structs.

The following series tries to take another path to solve the same problem
by using a global execve counter and each task will have its own exec ID,
this way we can know if the processed files are attached to the reader or
the target tasks. With this solution we do not pin mm_structs of dead
processes and we can track special objects at each syscall.


There is a new proc_file_private struct which can be used to hold internal
data related to opened /proc/<pid>/* files, we also use it to store the
exec_id of the reader or the target tasks, it depends on the files being
processed. This struct offers a consistent and unified way to protect
all these sensitive files even the other /proc/* files.
There are also some new helper functions.


Currently we perform the protection in two different ways:

1) Use the target exec_id to bind files to their exec_id task:

For the REG files /proc/<pid>/{environ,pagemap,mem} we set the exec_id
of the proc_file_private to the target task, and we continue with
permission checks at open time, later on each read/write call the
permission checks are done + check the target exec_id if it equals the
exec_id of the proc_file_private that was set at open time, in other words
we bind the file to its task's exec_id, this way new exec programs can not
operate on the passed fd.


2) Use the reader exec_id to track reader behaviour (aggressive checks):

For the /proc/<pid>/{maps,smaps,numa_maps} we set the exec_id of the
proc_file_private to the current (reader) exec_id, and the permission
checks are only performed at read time + the exec_id check against reader,
this way we are sure that we are still dealing with the same reader. We do
this since currently it is not clear if the permission checks at open time
will work with glibc FORTIFY_SOURCE protection and without permission
checks at each syscall using the target exec_id will not work.

Hopefully it seems that perhaps we can work-around this, if the exec_id
design is accepted then I will split /proc/<pid>/{maps,smaps,numa_maps}
internal functions and implement proper permission checks so we can bind
all these files to their task's exec_id (track target instead of reader).


For the ONE and INF files /proc/<pid>/{stack,syscall,io,auxv,...} we also
use the reader exec_id since these sensitive files share their internal
logic with the other less important files, and performing permission
checks at open time will just break things.


Notes:
The exec_id idea was taken from the recent grsecurity patches, but I have
made some design changes so if there are bugs they are mine.


This was also discussed in this kernel-hardening thread:
http://www.openwall.com/lists/kernel-hardening/2012/02/10/1

This thread also includes other procfs files problems which currently I am
working on, I will try to continue with an other patch series as soon as
possible. Thanks to Vasiliy Kulikov and Solar Designer for their comments.


Finally I will just add Alan's thread that also explain the problem with
some historical discussions:
http://lkml.org/lkml/2012/1/29/35


Hope to get feedback to avoid new problems. Thanks.


Djalal Harouni (9):
  exec: add a global execve counter
  proc: add proc_file_private struct to store private information
  proc: new proc_exec_id_ok() helper function
  proc: protect /proc/<pid>/* INF files from reader across execve
  proc: add protection support for /proc/<pid>/* ONE files
  proc: protect /proc/<pid>/* ONE files from reader across execve
  proc: protect /proc/<pid>/{maps,smaps,numa_maps}
  proc: protect /proc/<pid>/{environ,pagemap} across execve
  proc: improve and clean up /proc/<pid>/mem protection
 
 fs/exec.c             |   11 ++
 fs/proc/array.c       |    4 +
 fs/proc/base.c        |  303 ++++++++++++++++++++++++++++++++++++++++++-------
 fs/proc/internal.h    |   31 +++++-
 fs/proc/task_mmu.c    |  106 +++++++++++++++--
 include/linux/sched.h |   32 +++++
 6 files changed, 431 insertions(+), 56 deletions(-)

^ permalink raw reply	[flat|nested] 48+ messages in thread

end of thread, other threads:[~2012-03-18 20:53 UTC | newest]

Thread overview: 48+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-10 23:25 [PATCH 0/9] proc: protect /proc/<pid>/* files across execve Djalal Harouni
2012-03-10 23:25 ` [PATCH 1/9] exec: add a global execve counter Djalal Harouni
2012-03-11  0:12   ` Linus Torvalds
2012-03-11  0:36     ` Linus Torvalds
2012-03-11  0:58       ` Linus Torvalds
2012-03-11  8:24         ` Solar Designer
2012-03-11  9:56           ` Ingo Molnar
2012-03-11 14:03       ` Alan Cox
2012-03-11 17:15         ` Djalal Harouni
2012-03-11  8:39     ` Djalal Harouni
2012-03-11  9:40     ` Solar Designer
2012-03-11 17:25   ` Oleg Nesterov
2012-03-11 17:49     ` self_exec_id/parent_exec_id && CLONE_PARENT Oleg Nesterov
2012-03-11 18:02       ` Linus Torvalds
2012-03-11 18:37         ` richard -rw- weinberger
2012-03-11 18:39           ` Oleg Nesterov
2012-03-14 18:55         ` [PATCH 0/1] (Was: self_exec_id/parent_exec_id && CLONE_PARENT) Oleg Nesterov
2012-03-14 18:55           ` [PATCH 1/1] CLONE_PARENT shouldn't allow to set ->exit_signal Oleg Nesterov
2012-03-18 18:25             ` Linus Torvalds
2012-03-18 20:53               ` Oleg Nesterov
2012-03-11 22:48     ` [PATCH 1/9] exec: add a global execve counter Linus Torvalds
2012-03-11 23:32       ` Djalal Harouni
2012-03-11 23:42         ` Linus Torvalds
2012-03-12  0:25           ` Djalal Harouni
2012-03-12 10:11             ` Linus Torvalds
2012-03-12 14:01               ` Djalal Harouni
2012-03-11 23:36     ` Djalal Harouni
2012-03-12 14:34       ` Oleg Nesterov
2012-03-10 23:25 ` [PATCH 2/9] proc: add proc_file_private struct to store private information Djalal Harouni
2012-03-10 23:25 ` [PATCH 3/9] proc: new proc_exec_id_ok() helper function Djalal Harouni
2012-03-10 23:25 ` [PATCH 4/9] proc: protect /proc/<pid>/* INF files from reader across execve Djalal Harouni
2012-03-10 23:25 ` [PATCH 5/9] proc: add protection support for /proc/<pid>/* ONE files Djalal Harouni
2012-03-10 23:25 ` [PATCH 6/9] proc: protect /proc/<pid>/* ONE files from reader across execve Djalal Harouni
2012-03-10 23:25 ` [PATCH 7/9] proc: protect /proc/<pid>/{maps,smaps,numa_maps} Djalal Harouni
2012-03-10 23:25 ` [PATCH 8/9] proc: protect /proc/<pid>/{environ,pagemap} across execve Djalal Harouni
2012-03-11  8:05   ` Alexey Dobriyan
2012-03-11 17:01     ` Djalal Harouni
2012-03-10 23:25 ` [PATCH 9/9] proc: improve and clean up /proc/<pid>/mem protection Djalal Harouni
2012-03-11  0:01 ` [PATCH 0/9] proc: protect /proc/<pid>/* files across execve Linus Torvalds
2012-03-11  0:27   ` Djalal Harouni
2012-03-11  8:46   ` Djalal Harouni
2012-03-11 10:35   ` exec_id protection from bad child exit signals (was: Re: [PATCH 0/9] proc: protect /proc/<pid>/* files across execve) Solar Designer
2012-03-11 18:20     ` Oleg Nesterov
2012-03-12 19:13 ` [PATCH 0/9] proc: protect /proc/<pid>/* files across execve Eric W. Biederman
2012-03-12 20:44   ` Djalal Harouni
2012-03-12 21:47     ` Eric W. Biederman
2012-03-12 22:41       ` Djalal Harouni
2012-03-12 23:10         ` Eric W. Biederman

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).