From patchwork Sat Sep 28 23:32:21 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Geyslan G. Bem" X-Patchwork-Id: 2959441 Return-Path: X-Original-To: patchwork-v9fs-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 36A5B9F288 for ; Sat, 28 Sep 2013 23:37:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1B26D20200 for ; Sat, 28 Sep 2013 23:37:13 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 974C7201FF for ; Sat, 28 Sep 2013 23:37:11 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1VQ44T-0000pT-6B; Sat, 28 Sep 2013 23:37:09 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1VQ44S-0000pG-1C for v9fs-developer@lists.sourceforge.net; Sat, 28 Sep 2013 23:37:08 +0000 Received-SPF: pass (sog-mx-1.v43.ch3.sourceforge.com: domain of gmail.com designates 209.85.216.53 as permitted sender) client-ip=209.85.216.53; envelope-from=geyslan@gmail.com; helo=mail-qa0-f53.google.com; Received: from mail-qa0-f53.google.com ([209.85.216.53]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1VQ44R-0001OJ-28 for v9fs-developer@lists.sourceforge.net; Sat, 28 Sep 2013 23:37:07 +0000 Received: by mail-qa0-f53.google.com with SMTP id k4so1399968qaq.5 for ; Sat, 28 Sep 2013 16:37:01 -0700 (PDT) X-Received: by 10.49.4.74 with SMTP id i10mr18754566qei.15.1380411421504; Sat, 28 Sep 2013 16:37:01 -0700 (PDT) Received: from localhost.localdomain (189-48-112-205.user.veloxzone.com.br. [189.48.112.205]) by mx.google.com with ESMTPSA id 5sm34534915qao.3.1969.12.31.16.00.00 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 28 Sep 2013 16:37:01 -0700 (PDT) From: "Geyslan G. Bem" To: ericvh@gmail.com, rminnich@sandia.gov, lucho@ionkov.net Date: Sat, 28 Sep 2013 20:32:21 -0300 Message-Id: <1380411144-9236-9-git-send-email-geyslan@gmail.com> X-Mailer: git-send-email 1.8.4 In-Reply-To: <1380411144-9236-1-git-send-email-geyslan@gmail.com> References: <1380411144-9236-1-git-send-email-geyslan@gmail.com> X-Spam-Score: -1.6 (-) X-Headers-End: 1VQ44R-0001OJ-28 Cc: v9fs-developer@lists.sourceforge.net, "Geyslan G. Bem" , linux-kernel@vger.kernel.org Subject: [V9fs-developer] [PATCH v3 1/2] binfmt_aout: x86: Useless inode var, printks coding style fixes X-BeenThere: v9fs-developer@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: v9fs-developer-bounces@lists.sourceforge.net X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP file size used only once, so removed due its useless prior allocation. It's not necessary to verify f_op in the load_aout_library, since the prior kernel_read/vfs_read function already does. Made coding style fixes and printk replacements. Tested using qemu, a handcrafted a.out binary and an a.out linked with a cross-compiled ld. Signed-off-by: Geyslan G. Bem --- fs/binfmt_aout.c | 98 +++++++++++++++++++++++++++----------------------------- 1 file changed, 48 insertions(+), 50 deletions(-) diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c index 89dec7f..c732b8e 100644 --- a/fs/binfmt_aout.c +++ b/fs/binfmt_aout.c @@ -25,13 +25,14 @@ #include #include #include +#include +#include -#include #include #include static int load_aout_binary(struct linux_binprm *); -static int load_aout_library(struct file*); +static int load_aout_library(struct file *); #ifdef CONFIG_COREDUMP /* @@ -62,7 +63,7 @@ static int aout_core_dump(struct coredump_params *cprm) fs = get_fs(); set_fs(KERNEL_DS); has_dumped = 1; - strncpy(dump.u_comm, current->comm, sizeof(dump.u_comm)); + strncpy(dump.u_comm, current->comm, sizeof(dump.u_comm)); dump.u_ar0 = offsetof(struct user, regs); dump.signal = cprm->siginfo->si_signo; aout_dump_thread(cprm->regs, &dump); @@ -78,9 +79,11 @@ static int aout_core_dump(struct coredump_params *cprm) /* make sure we actually have a data and stack area to dump */ set_fs(USER_DS); - if (!access_ok(VERIFY_READ, START_DATA(dump), dump.u_dsize << PAGE_SHIFT)) + if (!access_ok(VERIFY_READ, START_DATA(dump), + dump.u_dsize << PAGE_SHIFT)) dump.u_dsize = 0; - if (!access_ok(VERIFY_READ, START_STACK(dump), dump.u_ssize << PAGE_SHIFT)) + if (!access_ok(VERIFY_READ, START_STACK(dump), + dump.u_ssize << PAGE_SHIFT)) dump.u_ssize = 0; set_fs(KERNEL_DS); @@ -142,7 +145,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; @@ -150,7 +154,8 @@ static unsigned long __user *create_aout_tables(char __user *p, struct linux_bin int argc = bprm->argc; int envc = bprm->envc; - sp = (void __user *)((-(unsigned long)sizeof(char *)) & (unsigned long) p); + sp = (void __user *) ((-(unsigned long) sizeof(char *)) + & (unsigned long) p); #ifdef __alpha__ /* whee.. test-programs are so much fun. */ put_user(0, --sp); @@ -169,28 +174,28 @@ static unsigned long __user *create_aout_tables(char __user *p, struct linux_bin sp -= argc+1; argv = (char __user * __user *) sp; #ifndef __alpha__ - put_user((unsigned long) envp,--sp); - put_user((unsigned long) argv,--sp); + put_user((unsigned long) envp, --sp); + put_user((unsigned long) argv, --sp); #endif - put_user(argc,--sp); + put_user(argc, --sp); current->mm->arg_start = (unsigned long) p; - while (argc-->0) { + while (argc-- > 0) { char c; - put_user(p,argv++); + put_user(p, argv++); do { - get_user(c,p++); + get_user(c, p++); } while (c); } - put_user(NULL,argv); + put_user(NULL, argv); current->mm->arg_end = current->mm->env_start = (unsigned long) p; - while (envc-->0) { + while (envc-- > 0) { char c; - put_user(p,envp++); + put_user(p, envp++); do { - get_user(c,p++); + get_user(c, p++); } while (c); } - put_user(NULL,envp); + put_user(NULL, envp); current->mm->env_end = (unsigned long) p; return sp; } @@ -200,7 +205,7 @@ static unsigned long __user *create_aout_tables(char __user *p, struct linux_bin * libraries. There is no binary dependent code anywhere else. */ -static int load_aout_binary(struct linux_binprm * bprm) +static int load_aout_binary(struct linux_binprm *bprm) { struct pt_regs *regs = current_pt_regs(); struct exec ex; @@ -213,7 +218,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 +298,12 @@ 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()) - { - printk(KERN_NOTICE "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); - } + (N_MAGIC(ex) != NMAGIC)) + pr_notice_ratelimited("executable not page aligned\n"); - if (!bprm->file->f_op->mmap||((fd_offset & ~PAGE_MASK) != 0)) { + 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); 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); @@ -312,9 +311,10 @@ static int load_aout_binary(struct linux_binprm * bprm) } error = vm_mmap(bprm->file, N_TXTADDR(ex), ex.a_text, - PROT_READ | PROT_EXEC, - MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE, - fd_offset); + PROT_READ | PROT_EXEC, + (MAP_FIXED | MAP_PRIVATE + | MAP_DENYWRITE | MAP_EXECUTABLE), + fd_offset); if (error != N_TXTADDR(ex)) { send_sig(SIGKILL, current, 0); @@ -323,8 +323,10 @@ static int load_aout_binary(struct linux_binprm * bprm) error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data, PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE, + (MAP_FIXED | MAP_PRIVATE + | MAP_DENYWRITE | MAP_EXECUTABLE), fd_offset + ex.a_text); + if (error != N_DATADDR(ex)) { send_sig(SIGKILL, current, 0); return error; @@ -340,7 +342,8 @@ beyond_if: } current->mm->start_stack = - (unsigned long) create_aout_tables((char __user *) bprm->p, bprm); + (unsigned long) create_aout_tables((char __user *) bprm->p, + bprm); #ifdef __alpha__ regs->gp = ex.a_gpvalue; #endif @@ -350,14 +353,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 +366,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 +375,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)) @@ -383,17 +384,14 @@ static int load_aout_library(struct file *file) /* For QMAGIC, the starting address is 0x20 into the page. We mask this off to get the starting address for the page */ - start_addr = ex.a_entry & 0xfffff000; + 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;