Skip to contentSkip to conversation

Require mmap handler for a.out executables

PATCH Marcel Holtmann 4 participants 5 messages Jul 26, 2006 – Jul 27, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi Linus,

with the nasty /proc privilege escalation (CVE-2006-3626) it became clear that we need to do something more to better protect us against people exploiting stuff in /proc. Besides the don't allow chmod stuff, Eugene also proposed to depend the a.out execution on the existence of the mmap handler. Since we are doing the same for ELF, this makes totally sense to me.

The attached patch implements the additional check for the mmap handler and I hope you consider it for upstream inclusion.

Regards

Marcel

[PATCH] Require mmap handler for a.out executables

Files supported by fs/proc/base.c, i.e. /proc/<pid>/*, are not capable of meeting the validity checks in ELF load_elf_*() handling because they have no mmap handler which is required by ELF. In order to stop a.out executables being used as part of an exploit attack against /proc-related vulnerabilities, we make a.out executables depend on ->mmap() existing.

---
commit 1597cf8405734e4747c808bb7e04115a6670dccf
tree 49050549aee6406dab0c021c5aa4e9bfc337bd8f
parent 44eb123126d289bac398cac0232309c228386671
author Marcel Holtmann <[email protected]> Wed, 26 Jul 2006 12:12:14 +0200 committer Marcel Holtmann <[email protected]> Wed, 26 Jul 2006 12:12:14 +0200

 fs/binfmt_aout.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
fs/binfmt_aout.c +6 -0
index f312103..5638acf 100644
@@ -278,6 +278,9 @@ static int load_aout_binary(struct linux
 		return -ENOEXEC;
 	}
 
+	if (!bprm->file->f_op || !bprm->file->f_op->mmap)
+		return -ENOEXEC;
+
 	fd_offset = N_TXTOFF(ex);
 
 	/* Check initial limits. This avoids letting people circumvent
@@ -476,6 +479,9 @@ static int load_aout_library(struct file
 		goto out;
 	}
 
+	if (!file->f_op || !file->f_op->mmap)
+		goto out;
+
 	if (N_FLAGS(ex))
 		goto out;
 
#1 lore raw

fs/binfmt_aout.c static int load_aout_binary(struct linux · line 283

Quoted 11 lines
fs/binfmt_aout.c +3 -0
index f312103..5638acf 100644
@@ -278,6 +278,9 @@ static int load_aout_binary(struct linux
 		return -ENOEXEC;
 	}
 
+	if (!bprm->file->f_op || !bprm->file->f_op->mmap)
+		return -ENOEXEC;
+

These checks need a big comment explanining why they are there, else people will remove them again by accident.

#2 lore raw
Quoted 9 lines · Christoph Hellwig
Quoted 9 lines
fs/binfmt_aout.c +0 -0
index f312103..5638acf 100644
@@ -278,6 +278,9 @@ static int load_aout_binary(struct linux
 		return -ENOEXEC;
 	}
 
Quoted 6 lines

fs/binfmt_aout.c static int load_aout_binary(struct linux · line 283

Quoted 3 lines
fs/binfmt_aout.c +3 -0
+	if (!bprm->file->f_op || !bprm->file->f_op->mmap)
+		return -ENOEXEC;
+

These checks need a big comment explanining why they are there, else people will remove them again by accident.

Since we fixed the /proc problem in a different way, I decided that it might be best to leave the a.out stuff alone, at least for now. It is conceivable that somebody actually might be using executables on some strange filesystem that doesn't support mmap, although I can't for the moment think of any good reason.

Linus

#3 lore raw

Hi Linus,

Quoted 15 lines
Quoted 8 lines
Quoted 8 lines
fs/binfmt_aout.c +0 -0
index f312103..5638acf 100644
@@ -278,6 +278,9 @@ static int load_aout_binary(struct linux
 		return -ENOEXEC;
 	}
 
Quoted 6 lines

fs/binfmt_aout.c static int load_aout_binary(struct linux · line 283

Quoted 3 lines
fs/binfmt_aout.c +3 -0
+	if (!bprm->file->f_op || !bprm->file->f_op->mmap)
+		return -ENOEXEC;
+

These checks need a big comment explanining why they are there, else people will remove them again by accident.

Quoted 5 lines

Since we fixed the /proc problem in a different way, I decided that it might be best to leave the a.out stuff alone, at least for now. It is conceivable that somebody actually might be using executables on some strange filesystem that doesn't support mmap, although I can't for the moment think of any good reason.

what do think about giving this a spin in -mm for some time and see if it will break for somebody.

Andrew, please include it.

Regards

Marcel

#4 lore raw
In reply to Christoph Hellwig
Quoted 8 lines · Christoph Hellwig
Quoted 8 lines
fs/binfmt_aout.c +0 -0
index f312103..5638acf 100644
@@ -278,6 +278,9 @@ static int load_aout_binary(struct linux
 		return -ENOEXEC;
 	}
 
Quoted 6 lines

fs/binfmt_aout.c static int load_aout_binary(struct linux · line 283

Quoted 3 lines
fs/binfmt_aout.c +3 -0
+	if (!bprm->file->f_op || !bprm->file->f_op->mmap)
+		return -ENOEXEC;
+

These checks need a big comment explanining why they are there, else people will remove them again by accident.

Here's a resend.

Like what Marcel wrote, Andrew, please include this patch in -mm for testing. Thanks.

Eugene
--

[PATCH] Require mmap handler for a.out executables

Files supported by fs/proc/base.c, i.e. /proc/<pid>/*, are not capable of meeting the validity checks in ELF load_elf_*() handling because they have no mmap handler which is required by ELF. In order to stop a.out executables being used as part of an exploit attack against /proc-related vulnerabilities, we make a.out executables depend on ->mmap() existing.

fs/binfmt_aout.c +12 -0
index f312103..2042dfa 100644
@@ -278,6 +278,12 @@ static int load_aout_binary(struct linux
                return -ENOEXEC;
        }
 
+       /* Requires a mmap handler. This prevents people from using a.out
+        * as part of an exploit attack against /proc-related vulnerabilities.
+        */
+       if (!bprm->file->f_op || !bprm->file->f_op->mmap)
+               return -ENOEXEC;
+
        fd_offset = N_TXTOFF(ex);
 
        /* Check initial limits. This avoids letting people circumvent
@@ -476,6 +482,12 @@ static int load_aout_library(struct file
                goto out;
        }
 
+       /* Requires a mmap handler. This prevents people from using a.out
+        * as part of an exploit attack against /proc-related vulnerabilities.
+        */
+       if (!file->f_op || !file->f_op->mmap)
+               goto out;
+
        if (N_FLAGS(ex))
                goto out;
 
Signature · 2 lines
eteo redhat.com  ph: +65 6490 4142  http://www.kernel.org/~eugeneteo
gpg fingerprint:  47B9 90F6 AE4A 9C51 37E0  D6E1 EA84 C6A2 58DF 8823