Skip to contentSkip to conversation

FIx 'noexec' behavior

PATCH Alex Riesen 2 participants 3 messages Dec 7, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw
Quoted 1 line · wli

You took a fault in do_mmap_pgoff().

...

Review

Quoted 4 lines
(quoted diff) +4 -0
+		if (file->f_vfsmnt && (prot & PROT_EXEC)) {
+			if (file->f_vfsmnt->mnt_flags & MNT_NOEXEC)
+				return -EPERM;
+		}

I had to put a check for 'file' (as Ulrich suggested). Otherwise it deadlocks again.
Is it possible for ->f_vfsmnt to be NULL at all? Should it be tested?

mm/mmap.c Sun Dec 7 14:37:33 2003 +1 -1
diff -Nru a/mm/mmap.c b/mm/mmap.c
@@ -478,7 +478,7 @@
        if (file && (!file->f_op || !file->f_op->mmap))
                return -ENODEV;
 
-       if ((prot & PROT_EXEC) && (file->f_vfsmnt->mnt_flags & MNT_NOEXEC))
+       if ((prot & PROT_EXEC) && file && (file->f_vfsmnt->mnt_flags & MNT_NOEXEC))
                return -EPERM;
 
        if (!len)
#1 lore raw
Quoted 7 lines · Alex Riesen

I had to put a check for 'file' (as Ulrich suggested). Otherwise it deadlocks again.
Is it possible for ->f_vfsmnt to be NULL at all? Should it be tested? diff -Nru a/mm/mmap.c b/mm/mmap.c

mm/mmap.c Sun Dec 7 14:37:33 2003 line 484

Quoted 8 lines
mm/mmap.c Sun Dec 7 14:37:33 2003 +1 -1
@@ -478,7 +478,7 @@
        if (file && (!file->f_op || !file->f_op->mmap))
                return -ENODEV;
 
-       if ((prot & PROT_EXEC) && (file->f_vfsmnt->mnt_flags & MNT_NOEXEC))
+       if ((prot & PROT_EXEC) && file && (file->f_vfsmnt->mnt_flags & MNT_NOEXEC))
                return -EPERM;
 
        if (!len)

This does not resemble the code I was looking at from current bk.

-- wli

#2 lore raw
In reply to Alex Riesen
Quoted 10 lines · wli
Quoted 10 lines

I had to put a check for 'file' (as Ulrich suggested). Otherwise it deadlocks again.
Is it possible for ->f_vfsmnt to be NULL at all? Should it be tested? diff -Nru a/mm/mmap.c b/mm/mmap.c

mm/mmap.c Sun Dec 7 14:37:33 2003 +0 -0
@@ -478,7 +478,7 @@
        if (file && (!file->f_op || !file->f_op->mmap))
                return -ENODEV;
 
Quoted 8 lines

mm/mmap.c Sun Dec 7 14:37:33 2003 line 484

Quoted 5 lines
mm/mmap.c Sun Dec 7 14:37:33 2003 +1 -1
-       if ((prot & PROT_EXEC) && (file->f_vfsmnt->mnt_flags & MNT_NOEXEC))
+       if ((prot & PROT_EXEC) && file && (file->f_vfsmnt->mnt_flags & MNT_NOEXEC))
                return -EPERM;
 
        if (!len)

This does not resemble the code I was looking at from current bk.

probably you were looking at the already fixed code:

[email protected], 2003-12-06 14:34:40-08:00, [email protected] +1 -0
Fix the PROT_EXEC breakage on anonymous mmap.

Clean up the tests while at it.

	if (file) {
		if (!file->f_op || !file->f_op->mmap)
			return -ENODEV;

		if ((prot & PROT_EXEC) && (file->f_vfsmnt->mnt_flags & MNT_NOEXEC))
			return -EPERM;
	}

The code I was looking at was the one from Ulrich:

ChangeSet 1.1507 2003/12/04 22:26:06 [email protected]
[PATCH] Fix 'noexec' behaviour

We should not allow mmap() with PROT_EXEC on mounts marked "noexec", since otherwise there is no way for user-supplied executable loaders (like ld.so and emulator environments) to properly honour the "noexec"ness of the target.

	if ((prot & PROT_EXEC) && (file->f_vfsmnt->mnt_flags & MNT_NOEXEC))
		return -EPERM;