* [PATCH 01/02] x86: Useless inode var, printks and coding style fixes
@ 2013-09-18 21:27 Geyslan G. Bem
2013-09-18 21:27 ` [PATCH 02/02] x86_64: Add safe check in a.out loaders and some coding style Geyslan G. Bem
2013-09-18 23:38 ` [PATCH 01/02] x86: Useless inode var, printks and coding style fixes Geyslan Gregório Bem
0 siblings, 2 replies; 4+ messages in thread
From: Geyslan G. Bem @ 2013-09-18 21:27 UTC (permalink / raw)
To: viro, linux-fsdevel; +Cc: linux-kernel, Geyslan G. Bem
file size read only one time: useless prior value allocation.
It's not necessary to verify f_op in the load_aout_library, since the
prior kernel_read/vfs_read function already does.
Coding style fixes and printk replacements.
Tested using qemu, a handcrafted a.out binary and a a.out linked with a
cross-compiled ld.
Signed-off-by: Geyslan G. Bem <geyslan@gmail.com>
---
fs/binfmt_aout.c | 41 ++++++++++++++++++-----------------------
1 file changed, 18 insertions(+), 23 deletions(-)
diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
index 89dec7f..2307467 100644
--- a/fs/binfmt_aout.c
+++ b/fs/binfmt_aout.c
@@ -25,6 +25,7 @@
#include <linux/init.h>
#include <linux/coredump.h>
#include <linux/slab.h>
+#include <linux/ratelimit.h>
#include <asm/uaccess.h>
#include <asm/cacheflush.h>
@@ -142,7 +143,8 @@ static int set_brk(unsigned long start, unsigned long end)
* memory and creates the pointer tables from them, and puts their
* addresses on the "stack", returning the new stack pointer value.
*/
-static unsigned long __user *create_aout_tables(char __user *p, struct linux_binprm * bprm)
+static unsigned long __user *create_aout_tables(char __user *p,
+ struct linux_binprm *bprm)
{
char __user * __user *argv;
char __user * __user *envp;
@@ -213,7 +215,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
if ((N_MAGIC(ex) != ZMAGIC && N_MAGIC(ex) != OMAGIC &&
N_MAGIC(ex) != QMAGIC && N_MAGIC(ex) != NMAGIC) ||
N_TRSIZE(ex) || N_DRSIZE(ex) ||
- i_size_read(file_inode(bprm->file)) < ex.a_text+ex.a_data+N_SYMSIZE(ex)+N_TXTOFF(ex)) {
+ i_size_read(file_inode(bprm->file)) <
+ ex.a_text + ex.a_data + N_SYMSIZE(ex) + N_TXTOFF(ex)) {
return -ENOEXEC;
}
@@ -292,19 +295,16 @@ static int load_aout_binary(struct linux_binprm * bprm)
}
} else {
if ((ex.a_text & 0xfff || ex.a_data & 0xfff) &&
- (N_MAGIC(ex) != NMAGIC) && printk_ratelimit())
+ (N_MAGIC(ex) != NMAGIC))
{
- printk(KERN_NOTICE "executable not page aligned\n");
+ pr_notice_ratelimited("executable not page aligned\n");
}
- if ((fd_offset & ~PAGE_MASK) != 0 && printk_ratelimit())
- {
- printk(KERN_WARNING
- "fd_offset is not page aligned. Please convert program: %s\n",
- bprm->file->f_path.dentry->d_name.name);
- }
+ if ((fd_offset & ~PAGE_MASK) != 0)
+ pr_warn_ratelimited("fd_offset is not page aligned. Please convert program: %s\n",
+ bprm->file->f_path.dentry->d_name.name);
- if (!bprm->file->f_op->mmap||((fd_offset & ~PAGE_MASK) != 0)) {
+ if ((fd_offset & ~PAGE_MASK) != 0) {
vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
read_code(bprm->file, N_TXTADDR(ex), fd_offset,
ex.a_text + ex.a_data);
@@ -350,14 +350,11 @@ beyond_if:
static int load_aout_library(struct file *file)
{
- struct inode * inode;
unsigned long bss, start_addr, len;
unsigned long error;
int retval;
struct exec ex;
- inode = file_inode(file);
-
retval = -ENOEXEC;
error = kernel_read(file, 0, (char *) &ex, sizeof(ex));
if (error != sizeof(ex))
@@ -366,7 +363,8 @@ static int load_aout_library(struct file *file)
/* We come in here for the regular a.out style of shared libraries */
if ((N_MAGIC(ex) != ZMAGIC && N_MAGIC(ex) != QMAGIC) || N_TRSIZE(ex) ||
N_DRSIZE(ex) || ((ex.a_entry & 0xfff) && N_MAGIC(ex) == ZMAGIC) ||
- i_size_read(inode) < ex.a_text+ex.a_data+N_SYMSIZE(ex)+N_TXTOFF(ex)) {
+ i_size_read(file_inode(file)) <
+ ex.a_text + ex.a_data + N_SYMSIZE(ex) + N_TXTOFF(ex)) {
goto out;
}
@@ -374,7 +372,7 @@ static int load_aout_library(struct file *file)
* 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)
+ if (!file->f_op->mmap)
goto out;
if (N_FLAGS(ex))
@@ -386,14 +384,11 @@ static int load_aout_library(struct file *file)
start_addr = ex.a_entry & 0xfffff000;
if ((N_TXTOFF(ex) & ~PAGE_MASK) != 0) {
- if (printk_ratelimit())
- {
- printk(KERN_WARNING
- "N_TXTOFF is not page aligned. Please convert library: %s\n",
- file->f_path.dentry->d_name.name);
- }
+ pr_warn_ratelimited("N_TXTOFF is not page aligned. Please convert library: %s\n",
+ file->f_path.dentry->d_name.name);
+
vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
-
+
read_code(file, start_addr, N_TXTOFF(ex),
ex.a_text + ex.a_data);
retval = 0;
--
1.8.4
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 02/02] x86_64: Add safe check in a.out loaders and some coding style
2013-09-18 21:27 [PATCH 01/02] x86: Useless inode var, printks and coding style fixes Geyslan G. Bem
@ 2013-09-18 21:27 ` Geyslan G. Bem
2013-09-18 22:38 ` Geyslan Gregório Bem
2013-09-18 23:38 ` [PATCH 01/02] x86: Useless inode var, printks and coding style fixes Geyslan Gregório Bem
1 sibling, 1 reply; 4+ messages in thread
From: Geyslan G. Bem @ 2013-09-18 21:27 UTC (permalink / raw)
To: viro, linux-fsdevel; +Cc: linux-kernel, Geyslan G. Bem
ia32_aout had no safe checks concerning the mmap and f_op in this module.
It's not necessary to verify f_op in the load_aout_library, since the
prior kernel_read/vfs_read function already does.
Coding style and printks fixes.
Tested using qemu, a handcrafted a.out binary and a a.out linked with a
cross-compiled ld.
Signed-off-by: Geyslan G. Bem <geyslan@gmail.com>
---
arch/x86/ia32/ia32_aout.c | 25 ++++++-------------------
1 file changed, 6 insertions(+), 19 deletions(-)
diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
index 15a8319..46a0346 100644
--- a/arch/x86/ia32/ia32_aout.c
+++ b/arch/x86/ia32/ia32_aout.c
@@ -24,7 +24,7 @@
#include <linux/binfmts.h>
#include <linux/personality.h>
#include <linux/init.h>
-#include <linux/jiffies.h>
+#include <linux/ratelimit.h>
#include <asm/uaccess.h>
#include <asm/pgalloc.h>
@@ -346,21 +346,13 @@ static int load_aout_binary(struct linux_binprm *bprm)
}
} else {
#ifdef WARN_OLD
- static unsigned long error_time, error_time2;
if ((ex.a_text & 0xfff || ex.a_data & 0xfff) &&
- (N_MAGIC(ex) != NMAGIC) &&
- time_after(jiffies, error_time2 + 5*HZ)) {
- printk(KERN_NOTICE "executable not page aligned\n");
- error_time2 = jiffies;
- }
+ (N_MAGIC(ex) != NMAGIC))
+ pr_notice_ratelimited("executable not page aligned\n");
- if ((fd_offset & ~PAGE_MASK) != 0 &&
- time_after(jiffies, error_time + 5*HZ)) {
- printk(KERN_WARNING
- "fd_offset is not page aligned. Please convert program: %s\n",
+ if ((fd_offset & ~PAGE_MASK) != 0)
+ pr_warn_ratelimited("fd_offset is not page aligned. Please convert program: %s\n",
bprm->file->f_path.dentry->d_name.name);
- error_time = jiffies;
- }
#endif
if ((fd_offset & ~PAGE_MASK) != 0) {
@@ -451,13 +443,8 @@ static int load_aout_library(struct file *file)
if ((N_TXTOFF(ex) & ~PAGE_MASK) != 0) {
#ifdef WARN_OLD
- static unsigned long error_time;
- if (time_after(jiffies, error_time + 5*HZ)) {
- printk(KERN_WARNING
- "N_TXTOFF is not page aligned. Please convert library: %s\n",
+ pr_warn_ratelimited("N_TXTOFF is not page aligned. Please convert library: %s\n",
file->f_path.dentry->d_name.name);
- error_time = jiffies;
- }
#endif
vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
--
1.8.4
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 02/02] x86_64: Add safe check in a.out loaders and some coding style
2013-09-18 21:27 ` [PATCH 02/02] x86_64: Add safe check in a.out loaders and some coding style Geyslan G. Bem
@ 2013-09-18 22:38 ` Geyslan Gregório Bem
0 siblings, 0 replies; 4+ messages in thread
From: Geyslan Gregório Bem @ 2013-09-18 22:38 UTC (permalink / raw)
To: viro, linux-fsdevel; +Cc: linux-kernel, Geyslan G. Bem
Please, disregard this due to problems reversing the commit.
I'll send the entire one soon.
Geyslan Gregório Bem
hackingbits.com
2013/9/18 Geyslan G. Bem <geyslan@gmail.com>:
> ia32_aout had no safe checks concerning the mmap and f_op in this module.
> It's not necessary to verify f_op in the load_aout_library, since the
> prior kernel_read/vfs_read function already does.
> Coding style and printks fixes.
>
> Tested using qemu, a handcrafted a.out binary and a a.out linked with a
> cross-compiled ld.
>
> Signed-off-by: Geyslan G. Bem <geyslan@gmail.com>
> ---
> arch/x86/ia32/ia32_aout.c | 25 ++++++-------------------
> 1 file changed, 6 insertions(+), 19 deletions(-)
>
> diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
> index 15a8319..46a0346 100644
> --- a/arch/x86/ia32/ia32_aout.c
> +++ b/arch/x86/ia32/ia32_aout.c
> @@ -24,7 +24,7 @@
> #include <linux/binfmts.h>
> #include <linux/personality.h>
> #include <linux/init.h>
> -#include <linux/jiffies.h>
> +#include <linux/ratelimit.h>
>
> #include <asm/uaccess.h>
> #include <asm/pgalloc.h>
> @@ -346,21 +346,13 @@ static int load_aout_binary(struct linux_binprm *bprm)
> }
> } else {
> #ifdef WARN_OLD
> - static unsigned long error_time, error_time2;
> if ((ex.a_text & 0xfff || ex.a_data & 0xfff) &&
> - (N_MAGIC(ex) != NMAGIC) &&
> - time_after(jiffies, error_time2 + 5*HZ)) {
> - printk(KERN_NOTICE "executable not page aligned\n");
> - error_time2 = jiffies;
> - }
> + (N_MAGIC(ex) != NMAGIC))
> + pr_notice_ratelimited("executable not page aligned\n");
>
> - if ((fd_offset & ~PAGE_MASK) != 0 &&
> - time_after(jiffies, error_time + 5*HZ)) {
> - printk(KERN_WARNING
> - "fd_offset is not page aligned. Please convert program: %s\n",
> + if ((fd_offset & ~PAGE_MASK) != 0)
> + pr_warn_ratelimited("fd_offset is not page aligned. Please convert program: %s\n",
> bprm->file->f_path.dentry->d_name.name);
> - error_time = jiffies;
> - }
> #endif
>
> if ((fd_offset & ~PAGE_MASK) != 0) {
> @@ -451,13 +443,8 @@ static int load_aout_library(struct file *file)
>
> if ((N_TXTOFF(ex) & ~PAGE_MASK) != 0) {
> #ifdef WARN_OLD
> - static unsigned long error_time;
> - if (time_after(jiffies, error_time + 5*HZ)) {
> - printk(KERN_WARNING
> - "N_TXTOFF is not page aligned. Please convert library: %s\n",
> + pr_warn_ratelimited("N_TXTOFF is not page aligned. Please convert library: %s\n",
> file->f_path.dentry->d_name.name);
> - error_time = jiffies;
> - }
> #endif
> vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
>
> --
> 1.8.4
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 01/02] x86: Useless inode var, printks and coding style fixes
2013-09-18 21:27 [PATCH 01/02] x86: Useless inode var, printks and coding style fixes Geyslan G. Bem
2013-09-18 21:27 ` [PATCH 02/02] x86_64: Add safe check in a.out loaders and some coding style Geyslan G. Bem
@ 2013-09-18 23:38 ` Geyslan Gregório Bem
1 sibling, 0 replies; 4+ messages in thread
From: Geyslan Gregório Bem @ 2013-09-18 23:38 UTC (permalink / raw)
To: viro, linux-fsdevel
This is the last version of the "[PATCH 01/02] x86: Useless inode var,
printks and coding style fixes".
Sorry about the mess.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-09-18 23:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-18 21:27 [PATCH 01/02] x86: Useless inode var, printks and coding style fixes Geyslan G. Bem
2013-09-18 21:27 ` [PATCH 02/02] x86_64: Add safe check in a.out loaders and some coding style Geyslan G. Bem
2013-09-18 22:38 ` Geyslan Gregório Bem
2013-09-18 23:38 ` [PATCH 01/02] x86: Useless inode var, printks and coding style fixes Geyslan Gregório Bem
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).