From patchwork Fri Nov 6 14:45:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dongliang Mu X-Patchwork-Id: 7569471 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 16C3AC05C6 for ; Fri, 6 Nov 2015 14:46:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 263B2206AD for ; Fri, 6 Nov 2015 14:46:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 296202045E for ; Fri, 6 Nov 2015 14:46:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161579AbbKFOpn (ORCPT ); Fri, 6 Nov 2015 09:45:43 -0500 Received: from mail-pa0-f54.google.com ([209.85.220.54]:34909 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161411AbbKFOpl (ORCPT ); Fri, 6 Nov 2015 09:45:41 -0500 Received: by pasz6 with SMTP id z6so129060909pas.2; Fri, 06 Nov 2015 06:45:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=+s/1yRLftc4JiwEY0mfGAWwAOfPqtjWUEh2AnMFOpCA=; b=Li9twg+34rwjeZhSNVeTxcX38WKzijTwRz29Ft17eeKykXl3afStEZ40xbThflgKda n36gedg/tPw1sFIGVVp+w5J3zOdo1aBMlamp1BQXNxqH1/M0EbfKlpuZ6crinKQwwApO rpXmu6faWxrjgy6lmwr8X1JPeoqJUBAPynL/iSOfYHVZcDLQQrMUHipvdMi+hJu2H8Uo vOnpDw9vhlRjA8ds1RCS6RhWJ1+3O1P+UzsznZkq3R1BJ8SFnqmueVfLnz5GHGaIEySU q8wXv/3eXuKR9RqdEUq/KA8s+k143kAIlntXCi1FBufUswuMxDHhU19Ka7no/xZ+KInc Estg== X-Received: by 10.68.111.101 with SMTP id ih5mr18615831pbb.84.1446821140511; Fri, 06 Nov 2015 06:45:40 -0800 (PST) Received: from ?IPv6:2001:250:5002:8100::3:795f? ([2001:250:5002:8100::3:795f]) by smtp.gmail.com with ESMTPSA id rm10sm488720pbc.96.2015.11.06.06.45.37 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Nov 2015 06:45:39 -0800 (PST) Message-ID: <563CBD0E.4060404@gmail.com> Date: Fri, 06 Nov 2015 22:45:34 +0800 From: mudongliang User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.8.0 MIME-Version: 1.0 To: viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, "linux-kernel@vger.kernel.org" Subject: [PATCH] load_elf_binary: change code style Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_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 From 3d17cc86be5d44bcd9ed37840b81f0000c739594 Mon Sep 17 00:00:00 2001 From: mudongliang Date: Wed, 4 Nov 2015 22:47:47 +0800 Subject: [PATCH] this writing is a little easier to understand. Signed-off-by: mudongliang --- fs/binfmt_elf.c | 100 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 6b65996..fbc450d 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -717,61 +717,61 @@ static int load_elf_binary(struct linux_binprm *bprm) start_data = 0; end_data = 0; - for (i = 0; i < loc->elf_ex.e_phnum; i++) { - if (elf_ppnt->p_type == PT_INTERP) { - /* This is the program interpreter used for - * shared libraries - for now assume that this - * is an a.out format binary - */ - retval = -ENOEXEC; - if (elf_ppnt->p_filesz > PATH_MAX || - elf_ppnt->p_filesz < 2) - goto out_free_ph; - - retval = -ENOMEM; - elf_interpreter = kmalloc(elf_ppnt->p_filesz, - GFP_KERNEL); - if (!elf_interpreter) - goto out_free_ph; - - retval = kernel_read(bprm->file, elf_ppnt->p_offset, - elf_interpreter, - elf_ppnt->p_filesz); - if (retval != elf_ppnt->p_filesz) { - if (retval >= 0) - retval = -EIO; - goto out_free_interp; - } - /* make sure path is NULL terminated */ - retval = -ENOEXEC; - if (elf_interpreter[elf_ppnt->p_filesz - 1] != '\0') - goto out_free_interp; + for (i = 0; i < loc->elf_ex.e_phnum; i++, elf_ppnt++) { + if (elf_ppnt->p_type != PT_INTERP) + continue; - interpreter = open_exec(elf_interpreter); - retval = PTR_ERR(interpreter); - if (IS_ERR(interpreter)) - goto out_free_interp; + /* This is the program interpreter used for + * shared libraries - for now assume that this + * is an a.out format binary + */ + retval = -ENOEXEC; + if (elf_ppnt->p_filesz > PATH_MAX || + elf_ppnt->p_filesz < 2) + goto out_free_ph; - /* - * If the binary is not readable then enforce - * mm->dumpable = 0 regardless of the interpreter's - * permissions. - */ - would_dump(bprm, interpreter); + retval = -ENOMEM; + elf_interpreter = kmalloc(elf_ppnt->p_filesz, + GFP_KERNEL); + if (!elf_interpreter) + goto out_free_ph; + + retval = kernel_read(bprm->file, elf_ppnt->p_offset, + elf_interpreter, + elf_ppnt->p_filesz); + if (retval != elf_ppnt->p_filesz) { + if (retval >= 0) + retval = -EIO; + goto out_free_interp; + } + /* make sure path is NULL terminated */ + retval = -ENOEXEC; + if (elf_interpreter[elf_ppnt->p_filesz - 1] != '\0') + goto out_free_interp; - retval = kernel_read(interpreter, 0, bprm->buf, - BINPRM_BUF_SIZE); - if (retval != BINPRM_BUF_SIZE) { - if (retval >= 0) - retval = -EIO; - goto out_free_dentry; - } + interpreter = open_exec(elf_interpreter); + retval = PTR_ERR(interpreter); + if (IS_ERR(interpreter)) + goto out_free_interp; - /* Get the exec headers */ - loc->interp_elf_ex = *((struct elfhdr *)bprm->buf); - break; + /* + * If the binary is not readable then enforce + * mm->dumpable = 0 regardless of the interpreter's + * permissions. + */ + would_dump(bprm, interpreter); + + retval = kernel_read(interpreter, 0, bprm->buf, + BINPRM_BUF_SIZE); + if (retval != BINPRM_BUF_SIZE) { + if (retval >= 0) + retval = -EIO; + goto out_free_dentry; } - elf_ppnt++; + + /* Get the exec headers */ + loc->interp_elf_ex = *((struct elfhdr *)bprm->buf); + break; } elf_ppnt = elf_phdata;