From patchwork Sat Nov 21 13:57:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Colomar X-Patchwork-Id: 11923391 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63984C64E75 for ; Sat, 21 Nov 2020 13:57:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2F56C22470 for ; Sat, 21 Nov 2020 13:57:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VaBp/PLm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727897AbgKUN5p (ORCPT ); Sat, 21 Nov 2020 08:57:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727741AbgKUN5o (ORCPT ); Sat, 21 Nov 2020 08:57:44 -0500 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB66DC0613CF; Sat, 21 Nov 2020 05:57:43 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id j7so13832133wrp.3; Sat, 21 Nov 2020 05:57:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hkIhGHP8YvYo+Fe39wHlU1jbDv53qs8LMyCMcK/zpZY=; b=VaBp/PLmuipBixL0nMuXp6MaXGOZSp43PZb/H349yWjQZbL8XgahpAKmvYSVtUba2K D94skssyBZrM3brTxpClvUnnYd55Xcs/DWqfm7uxaU5xscH5z/im4Rpf5Vo3C8OOi0LO RK2F7CcSvsxyFVCxJ0ZHYXTSmrCvENyfjs1dp+srb0+PNLeCNlGAEtga/jvq4PE2sFtJ f2Xv15CzfLKlizH75s7Mbo9lGdzMeDStHHrfv6NeoY4XSTKxLn8Cgr6opToqCueWKPbt EEr13/NldYV2iMxGshbX0FiQ4ddXMSUNFTUfuqAFderusNDI/beXx13TH0vVAFA+EXBF HxRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hkIhGHP8YvYo+Fe39wHlU1jbDv53qs8LMyCMcK/zpZY=; b=p6YBVWvUnrASZp0VExqbjBozqeqYcWnbzcYkaUkj9+vka3HD0Cibo/U1uOUOdc+U14 kotVa4HHMDy7glZF3KmzBP1/7Fuw4rKkz7c38y/Y7vOyXM/AwYBpxF8cHkNTQMDa3ymE prro12ktBCJAk9sfXbVyjCpDXkhKoWi6mjR5HSATrQNaStUk0hf2uCSWOcKEmST1/9Uw C1c1FkSJxynvbgYnc5QeoUVo16svYJ/z20KXzXgHAif/rNJy5sm/HPb2jZ7a8z4oQJNE hEwniWjFAmNwHDggHf3kf0NjipNg642EGCCR6Nd3Gn3JRfuZbMKpoo6Tilyu0YLHySo8 sYEQ== X-Gm-Message-State: AOAM533LOwlJePlMeMPr7wvoP0bgbOge6ztCf2lMXD7f4bw1zVHB4crU Js5m2O3Eg+Aa7+JISQE2D2g= X-Google-Smtp-Source: ABdhPJwmkpTRUbrB2W5NzI3x6cse1Q2KjRmZodLmHqIkyT6kUobzrzy8+QO4GAH4PsQV7LyCsl7HEw== X-Received: by 2002:adf:fe46:: with SMTP id m6mr22982503wrs.254.1605967061833; Sat, 21 Nov 2020 05:57:41 -0800 (PST) Received: from localhost.localdomain ([170.253.49.0]) by smtp.googlemail.com with ESMTPSA id 17sm41689951wma.3.2020.11.21.05.57.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Nov 2020 05:57:41 -0800 (PST) From: Alejandro Colomar To: Alexander Viro , linux-fsdevel@vger.kernel.org Cc: Alejandro Colomar , linux-kernel@vger.kernel.org Subject: [PATCH 1/4] fs/anon_inodes.c: Use "%s" + __func__ instead of hardcoding function name Date: Sat, 21 Nov 2020 14:57:33 +0100 Message-Id: <20201121135736.295705-2-alx.manpages@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201121135736.295705-1-alx.manpages@gmail.com> References: <20201121135736.295705-1-alx.manpages@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Signed-off-by: Alejandro Colomar --- fs/anon_inodes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c index 89714308c25b..7609d208bb53 100644 --- a/fs/anon_inodes.c +++ b/fs/anon_inodes.c @@ -152,11 +152,11 @@ static int __init anon_inode_init(void) { anon_inode_mnt = kern_mount(&anon_inode_fs_type); if (IS_ERR(anon_inode_mnt)) - panic("anon_inode_init() kernel mount failed (%ld)\n", PTR_ERR(anon_inode_mnt)); + panic("%s() kernel mount failed (%ld)\n", __func__, PTR_ERR(anon_inode_mnt)); anon_inode_inode = alloc_anon_inode(anon_inode_mnt->mnt_sb); if (IS_ERR(anon_inode_inode)) - panic("anon_inode_init() inode allocation failed (%ld)\n", PTR_ERR(anon_inode_inode)); + panic("%s() inode allocation failed (%ld)\n", __func__, PTR_ERR(anon_inode_inode)); return 0; } From patchwork Sat Nov 21 13:57:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Colomar X-Patchwork-Id: 11923393 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 939A0C6379D for ; Sat, 21 Nov 2020 13:57:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 55F152224A for ; Sat, 21 Nov 2020 13:57:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iSnyeTTp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727916AbgKUN5t (ORCPT ); Sat, 21 Nov 2020 08:57:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727741AbgKUN5q (ORCPT ); Sat, 21 Nov 2020 08:57:46 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54C2EC0613CF; Sat, 21 Nov 2020 05:57:46 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id 23so13776380wrc.8; Sat, 21 Nov 2020 05:57:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IBdOOGrn/h8+p7aSFzuIlfuYm/AP2B2TwuDG4m/SEKM=; b=iSnyeTTpiZrN90iOME8h0UtVWZ9MZLPNX3DO1Yu/mdMYgReiLPspvnV+L4B4sZK4Jr qOuCHciajhkpNWJmnojpLifGbHGSUX7gONY/WyjBADL1qS8MZahx6uE4wwjXrzYQmtvk F/iXZMWFz4PCXJZ0Lh3uBNP9cA74Nou3+t0em30gp4BKBxbzOxyeqU1PTx/KULZ3TpCz 71jdH1APskKAkLHgpipWutHXIQOdYfGWMyiwK5DOXh+ANZbQrRykLPppvVRuJ7niabqd jvO4SjZlN9VYFkcIZ9n1chge+HsYQqvSE58+LR7Xp81L5CwHZ8Sap1WNv4qVMXYA0ZDO dF2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IBdOOGrn/h8+p7aSFzuIlfuYm/AP2B2TwuDG4m/SEKM=; b=APBsLLC5g7bq36SgmJHYQMjlchj2k8zLNUgfRd93y/24VvxOygQFzCYEc4N1HnZ5aP JkIpFZhsYAizhs6Imjxs6EgT9OSAzk5nHiT2NDRnTUV4niupgb+tHq7LHFGGhG5jcIsZ 5MnuMkQlchMk5wjXFzNi1KpZo3ooKY2ukMO34lBY2xxWzZldZJQgsrew7zD4h27qhXS0 73wyEPGqETWvy2UBGelSip4HQZZaJtNk45geWtETwORiJx6/rqc8CBlTgUnIJl6bXL+/ iCS6Ig1qioJbI93ZKiTdJECIl2bNi+oAqCfu3EsmhmNngyRwt6uy2NMNSWsAmasc4LfR T02w== X-Gm-Message-State: AOAM531tjD4AUtvFKlg7QCUuqUlD2bHfSXaArGtcsR+iIh6gkB2t5VCH emeCWjbUsKy+Xu1t5RPhZ4w= X-Google-Smtp-Source: ABdhPJzl+T77MXUYUdUKaZj+wmpF+iqlKC2EwzOdBGmiXu+Jd6Vz/rqKqdGos7QT6mdBmSFYMY1d6A== X-Received: by 2002:a5d:4fc1:: with SMTP id h1mr22972821wrw.226.1605967064807; Sat, 21 Nov 2020 05:57:44 -0800 (PST) Received: from localhost.localdomain ([170.253.49.0]) by smtp.googlemail.com with ESMTPSA id 17sm41689951wma.3.2020.11.21.05.57.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Nov 2020 05:57:44 -0800 (PST) From: Alejandro Colomar To: Alexander Viro , linux-fsdevel@vger.kernel.org Cc: Alejandro Colomar , linux-kernel@vger.kernel.org Subject: [PATCH 2/4] fs/anon_inodes.c, fs/attr.c, fs/bad_inode.c, fs/binfmt_aout.c, fs/binfmt_elf.c: Cosmetic Date: Sat, 21 Nov 2020 14:57:34 +0100 Message-Id: <20201121135736.295705-3-alx.manpages@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201121135736.295705-1-alx.manpages@gmail.com> References: <20201121135736.295705-1-alx.manpages@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org This patch contains only trivial changes: Some of them found with checkpatch.pl in strict mode. - Remove trailing whitespace. - Remove spaces coming before tabs. - Fix typos in comments. - Convert spaces into tabs. - Add a space around operators that should have them, and remove them when they shouldn't have them sround, according to coding_style.rst. - Use braces accordint to coding_style.rst. - Align multi-line function prototypes, and other similar cases. - Remove or add blank lines: * Add blank lines after declarations, and before code. * Remove blank lines after function definitions and before EXPORT_SYMBOL(). - Remove redundant parentheses, when the don't improve readability. - Fix comments' style according to coding_style.rst. - Simplify comparisons against NULL, using '!' (or nothing at all). - Use C89 comments (/* */), instead of C99 (//). Signed-off-by: Alejandro Colomar --- fs/anon_inodes.c | 1 + fs/attr.c | 7 +-- fs/bad_inode.c | 50 +++++++++--------- fs/binfmt_aout.c | 94 +++++++++++++++++----------------- fs/binfmt_elf.c | 129 ++++++++++++++++++++++++----------------------- 5 files changed, 143 insertions(+), 138 deletions(-) diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c index 7609d208bb53..bef68dbcbb88 100644 --- a/fs/anon_inodes.c +++ b/fs/anon_inodes.c @@ -43,6 +43,7 @@ static const struct dentry_operations anon_inodefs_dentry_operations = { static int anon_inodefs_init_fs_context(struct fs_context *fc) { struct pseudo_fs_context *ctx = init_pseudo(fc, ANON_INODE_FS_MAGIC); + if (!ctx) return -ENOMEM; ctx->dops = &anon_inodefs_dentry_operations; diff --git a/fs/attr.c b/fs/attr.c index b4bbdbd4c8ca..b32ad8c678a5 100644 --- a/fs/attr.c +++ b/fs/attr.c @@ -64,7 +64,7 @@ int setattr_prepare(struct dentry *dentry, struct iattr *attr) unsigned int ia_valid = attr->ia_valid; /* - * First check size constraints. These can't be overriden using + * First check size constraints. These can't be overridden using * ATTR_FORCE. */ if (ia_valid & ATTR_SIZE) { @@ -220,7 +220,8 @@ EXPORT_SYMBOL(setattr_copy); * the file open for write, as there can be no conflicting delegation in * that case. */ -int notify_change(struct dentry * dentry, struct iattr * attr, struct inode **delegated_inode) +int notify_change(struct dentry *dentry, struct iattr *attr, + struct inode **delegated_inode) { struct inode *inode = dentry->d_inode; umode_t mode = inode->i_mode; @@ -284,7 +285,7 @@ int notify_change(struct dentry * dentry, struct iattr * attr, struct inode **de * no function will ever call notify_change with both ATTR_MODE and * ATTR_KILL_S*ID set. */ - if ((ia_valid & (ATTR_KILL_SUID|ATTR_KILL_SGID)) && + if ((ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) && (ia_valid & ATTR_MODE)) BUG(); diff --git a/fs/bad_inode.c b/fs/bad_inode.c index 54f0ce444272..f0457b6c17dc 100644 --- a/fs/bad_inode.c +++ b/fs/bad_inode.c @@ -22,25 +22,25 @@ static int bad_file_open(struct inode *inode, struct file *filp) return -EIO; } -static const struct file_operations bad_file_ops = -{ +static const struct file_operations bad_file_ops = { .open = bad_file_open, }; -static int bad_inode_create (struct inode *dir, struct dentry *dentry, - umode_t mode, bool excl) +static int bad_inode_create(struct inode *dir, struct dentry *dentry, + umode_t mode, bool excl) { return -EIO; } static struct dentry *bad_inode_lookup(struct inode *dir, - struct dentry *dentry, unsigned int flags) + struct dentry *dentry, + unsigned int flags) { return ERR_PTR(-EIO); } -static int bad_inode_link (struct dentry *old_dentry, struct inode *dir, - struct dentry *dentry) +static int bad_inode_link(struct dentry *old_dentry, struct inode *dir, + struct dentry *dentry) { return -EIO; } @@ -50,25 +50,25 @@ static int bad_inode_unlink(struct inode *dir, struct dentry *dentry) return -EIO; } -static int bad_inode_symlink (struct inode *dir, struct dentry *dentry, - const char *symname) +static int bad_inode_symlink(struct inode *dir, struct dentry *dentry, + const char *symname) { return -EIO; } static int bad_inode_mkdir(struct inode *dir, struct dentry *dentry, - umode_t mode) + umode_t mode) { return -EIO; } -static int bad_inode_rmdir (struct inode *dir, struct dentry *dentry) +static int bad_inode_rmdir(struct inode *dir, struct dentry *dentry) { return -EIO; } -static int bad_inode_mknod (struct inode *dir, struct dentry *dentry, - umode_t mode, dev_t rdev) +static int bad_inode_mknod(struct inode *dir, struct dentry *dentry, + umode_t mode, dev_t rdev) { return -EIO; } @@ -81,7 +81,7 @@ static int bad_inode_rename2(struct inode *old_dir, struct dentry *old_dentry, } static int bad_inode_readlink(struct dentry *dentry, char __user *buffer, - int buflen) + int buflen) { return -EIO; } @@ -103,7 +103,7 @@ static int bad_inode_setattr(struct dentry *direntry, struct iattr *attrs) } static ssize_t bad_inode_listxattr(struct dentry *dentry, char *buffer, - size_t buffer_size) + size_t buffer_size) { return -EIO; } @@ -152,8 +152,7 @@ static int bad_inode_set_acl(struct inode *inode, struct posix_acl *acl, return -EIO; } -static const struct inode_operations bad_inode_ops = -{ +static const struct inode_operations bad_inode_ops = { .create = bad_inode_create, .lookup = bad_inode_lookup, .link = bad_inode_link, @@ -181,12 +180,12 @@ static const struct inode_operations bad_inode_ops = /* * When a filesystem is unable to read an inode due to an I/O error in * its read_inode() function, it can call make_bad_inode() to return a - * set of stubs which will return EIO errors as required. + * set of stubs which will return EIO errors as required. * * We only need to do limited initialisation: all other fields are * preinitialised to zero automatically. */ - + /** * make_bad_inode - mark an inode bad due to an I/O error * @inode: Inode to mark bad @@ -195,7 +194,7 @@ static const struct inode_operations bad_inode_ops = * failure this function makes the inode "bad" and causes I/O operations * on it to fail from this point on. */ - + void make_bad_inode(struct inode *inode) { remove_inode_hash(inode); @@ -203,9 +202,9 @@ void make_bad_inode(struct inode *inode) inode->i_mode = S_IFREG; inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode); - inode->i_op = &bad_inode_ops; + inode->i_op = &bad_inode_ops; inode->i_opflags &= ~IOP_XATTR; - inode->i_fop = &bad_file_ops; + inode->i_fop = &bad_file_ops; } EXPORT_SYMBOL(make_bad_inode); @@ -214,19 +213,18 @@ EXPORT_SYMBOL(make_bad_inode); * &bad_inode_ops to cover the case of invalidated inodes as well as * those created by make_bad_inode() above. */ - + /** * is_bad_inode - is an inode errored * @inode: inode to test * * Returns true if the inode in question has been marked as bad. */ - + bool is_bad_inode(struct inode *inode) { - return (inode->i_op == &bad_inode_ops); + return (inode->i_op == &bad_inode_ops); } - EXPORT_SYMBOL(is_bad_inode); /** diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c index 3e84e9bb9084..92d6b70ddab0 100644 --- a/fs/binfmt_aout.c +++ b/fs/binfmt_aout.c @@ -32,7 +32,7 @@ #include static int load_aout_binary(struct linux_binprm *); -static int load_aout_library(struct file*); +static int load_aout_library(struct file *); static struct linux_binfmt aout_format = { .module = THIS_MODULE, @@ -56,7 +56,7 @@ 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; @@ -64,7 +64,7 @@ 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); @@ -78,34 +78,36 @@ static unsigned long __user *create_aout_tables(char __user *p, struct linux_bin put_user(bprm->exec, --sp); put_user(1001, --sp); #endif - sp -= envc+1; + sp -= envc + 1; envp = (char __user * __user *) sp; - sp -= argc+1; + 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); - current->mm->arg_start = (unsigned long) p; - while (argc-->0) { + put_user(argc, --sp); + current->mm->arg_start = (unsigned long)p; + 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); - current->mm->arg_end = current->mm->env_start = (unsigned long) p; - while (envc-->0) { + put_user(NULL, argv); + current->mm->arg_end = current->mm->env_start = (unsigned long)p; + 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); - current->mm->env_end = (unsigned long) p; + put_user(NULL, envp); + current->mm->env_end = (unsigned long)p; return sp; } @@ -114,7 +116,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; @@ -123,11 +125,14 @@ static int load_aout_binary(struct linux_binprm * bprm) unsigned long rlim; int retval; - ex = *((struct exec *) bprm->buf); /* exec-header */ + ex = *(struct exec *)bprm->buf; /* exec-header */ 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; } @@ -174,7 +179,6 @@ static int load_aout_binary(struct linux_binprm * bprm) if (retval < 0) return retval; - if (N_MAGIC(ex) == OMAGIC) { unsigned long text_addr, map_size; loff_t pos; @@ -183,35 +187,34 @@ static int load_aout_binary(struct linux_binprm * bprm) #ifdef __alpha__ pos = fd_offset; - map_size = ex.a_text+ex.a_data + PAGE_SIZE - 1; + map_size = ex.a_text + ex.a_data + PAGE_SIZE - 1; #else pos = 32; - map_size = ex.a_text+ex.a_data; + map_size = ex.a_text + ex.a_data; #endif error = vm_brk(text_addr & PAGE_MASK, map_size); if (error) return error; error = read_code(bprm->file, text_addr, pos, - ex.a_text+ex.a_data); + ex.a_text + ex.a_data); if ((signed long)error < 0) return error; } else { if ((ex.a_text & 0xfff || ex.a_data & 0xfff) && - (N_MAGIC(ex) != NMAGIC) && printk_ratelimit()) - { + (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 + if ((fd_offset & ~PAGE_MASK) != 0 && printk_ratelimit()) { + printk(KERN_WARNING "fd_offset is not page aligned. Please convert program: %pD\n", bprm->file); } - if (!bprm->file->f_op->mmap||((fd_offset & ~PAGE_MASK) != 0)) { - error = vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data); + if (!bprm->file->f_op->mmap || ((fd_offset & ~PAGE_MASK) != 0)) { + error = vm_brk(N_TXTADDR(ex), ex.a_text + ex.a_data); if (error) return error; @@ -221,9 +224,9 @@ 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)) return error; @@ -243,7 +246,7 @@ static int load_aout_binary(struct linux_binprm * bprm) return retval; 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 @@ -254,7 +257,7 @@ static int load_aout_binary(struct linux_binprm * bprm) static int load_aout_library(struct file *file) { - struct inode * inode; + struct inode *inode; unsigned long bss, start_addr, len; unsigned long error; int retval; @@ -271,7 +274,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(inode) < ex.a_text + ex.a_data + N_SYMSIZE(ex) + + N_TXTOFF(ex)) { goto out; } @@ -285,15 +289,15 @@ static int load_aout_library(struct file *file) if (N_FLAGS(ex)) goto out; - /* For QMAGIC, the starting address is 0x20 into the page. We mask - this off to get the starting address for the page */ - + /* + * 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; if ((N_TXTOFF(ex) & ~PAGE_MASK) != 0) { - if (printk_ratelimit()) - { - printk(KERN_WARNING + if (printk_ratelimit()) { + printk(KERN_WARNING "N_TXTOFF is not page aligned. Please convert library: %pD\n", file); } diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index fa50e8936f5f..955927ac2b80 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1025,10 +1025,12 @@ static int load_elf_binary(struct linux_binprm *bprm) start_data = 0; end_data = 0; - /* Now we do a little grungy work by mmapping the ELF image into - the correct location in memory. */ - for(i = 0, elf_ppnt = elf_phdata; - i < elf_ex->e_phnum; i++, elf_ppnt++) { + /* + * Now we do a little grungy work by mmapping the ELF image into + * the correct location in memory. + */ + for (i = 0, elf_ppnt = elf_phdata; i < elf_ex->e_phnum; + i++, elf_ppnt++) { int elf_prot, elf_flags; unsigned long k, vaddr; unsigned long total_size = 0; @@ -1037,12 +1039,14 @@ static int load_elf_binary(struct linux_binprm *bprm) if (elf_ppnt->p_type != PT_LOAD) continue; - if (unlikely (elf_brk > elf_bss)) { + if (unlikely(elf_brk > elf_bss)) { unsigned long nbyte; - - /* There was a PT_LOAD segment with p_memsz > p_filesz - before this one. Map anonymous pages, if needed, - and clear the area. */ + + /* + * There was a PT_LOAD segment with p_memsz > p_filesz + * before this one. Map anonymous pages, if needed, + * and clear the area. + */ retval = set_brk(elf_bss + load_bias, elf_brk + load_bias, bss_prot); @@ -1139,7 +1143,7 @@ static int load_elf_binary(struct linux_binprm *bprm) elf_prot, elf_flags, total_size); if (BAD_ADDR(error)) { retval = IS_ERR((void *)error) ? - PTR_ERR((void*)error) : -EINVAL; + PTR_ERR((void *)error) : -EINVAL; goto out_free_dentry; } @@ -1252,7 +1256,7 @@ static int load_elf_binary(struct linux_binprm *bprm) #endif /* ARCH_HAS_SETUP_ADDITIONAL_PAGES */ retval = create_elf_tables(bprm, elf_ex, - load_addr, interp_load_addr, e_entry); + load_addr, interp_load_addr, e_entry); if (retval < 0) goto out; @@ -1283,10 +1287,12 @@ static int load_elf_binary(struct linux_binprm *bprm) } if (current->personality & MMAP_PAGE_ZERO) { - /* Why this, you ask??? Well SVr4 maps page 0 as read-only, - and some applications "depend" upon this behavior. - Since we do not have the power to recompile these, we - emulate the SVr4 behavior. Sigh. */ + /* + * Why this, you ask??? Well SVr4 maps page 0 as read-only, + * and some applications "depend" upon this behavior. + * Since we do not have the power to recompile these, we + * emulate the SVr4 behavior. Sigh. + */ error = vm_mmap(NULL, 0, PAGE_SIZE, PROT_READ | PROT_EXEC, MAP_FIXED | MAP_PRIVATE, 0); } @@ -1325,8 +1331,10 @@ static int load_elf_binary(struct linux_binprm *bprm) } #ifdef CONFIG_USELIB -/* This is really simpleminded and specialized - we are loading an - a.out library that is given an ELF header. */ +/* + * This is really simpleminded and specialized - we are loading an + * a.out library that is given an ELF header. + */ static int load_elf_library(struct file *file) { struct elf_phdr *elf_phdata; @@ -1366,7 +1374,7 @@ static int load_elf_library(struct file *file) if (retval < 0) goto out_free_ph; - for (j = 0, i = 0; ip_type == PT_LOAD) j++; if (j != 1) @@ -1418,8 +1426,7 @@ static int load_elf_library(struct file *file) */ /* An ELF note in memory */ -struct memelfnote -{ +struct memelfnote { const char *name; int type; unsigned int datasz; @@ -1440,6 +1447,7 @@ static int notesize(struct memelfnote *en) static int writenote(struct memelfnote *men, struct coredump_params *cprm) { struct elf_note en; + en.n_namesz = strlen(men->name) + 1; en.n_descsz = men->datasz; en.n_type = men->type; @@ -1482,8 +1490,8 @@ static void fill_elf_note_phdr(struct elf_phdr *phdr, int sz, loff_t offset) phdr->p_align = 0; } -static void fill_note(struct memelfnote *note, const char *name, int type, - unsigned int sz, void *data) +static void fill_note(struct memelfnote *note, const char *name, int type, + unsigned int sz, void *data) { note->name = name; note->type = type; @@ -1496,7 +1504,7 @@ static void fill_note(struct memelfnote *note, const char *name, int type, * registers which need to be filled up separately. */ static void fill_prstatus(struct elf_prstatus *prstatus, - struct task_struct *p, long signr) + struct task_struct *p, long signr) { prstatus->pr_info.si_signo = prstatus->pr_cursig = signr; prstatus->pr_sigpend = p->pending.signal.sig[0]; @@ -1534,17 +1542,17 @@ static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p, { const struct cred *cred; unsigned int i, len; - + /* first copy the parameters from user space */ memset(psinfo, 0, sizeof(struct elf_prpsinfo)); len = mm->arg_end - mm->arg_start; if (len >= ELF_PRARGSZ) - len = ELF_PRARGSZ-1; + len = ELF_PRARGSZ - 1; if (copy_from_user(&psinfo->pr_psargs, - (const char __user *)mm->arg_start, len)) + (const char __user *)mm->arg_start, len)) return -EFAULT; - for(i = 0; i < len; i++) + for (i = 0; i < len; i++) if (psinfo->pr_psargs[i] == 0) psinfo->pr_psargs[i] = ' '; psinfo->pr_psargs[len] = 0; @@ -1568,14 +1576,15 @@ static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p, SET_GID(psinfo->pr_gid, from_kgid_munged(cred->user_ns, cred->gid)); rcu_read_unlock(); strncpy(psinfo->pr_fname, p->comm, sizeof(psinfo->pr_fname)); - + return 0; } static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm) { - elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv; + elf_addr_t *auxv = (elf_addr_t *)mm->saved_auxv; int i = 0; + do i += 2; while (auxv[i - 2] != AT_NULL); @@ -1583,13 +1592,13 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm) } static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata, - const kernel_siginfo_t *siginfo) + const kernel_siginfo_t *siginfo) { copy_siginfo_to_external(csigdata, siginfo); fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata); } -#define MAX_FILE_NOTE_SIZE (4*1024*1024) +#define MAX_FILE_NOTE_SIZE (4 * 1024 * 1024) /* * Format of NT_FILE note: * @@ -1605,7 +1614,7 @@ static int fill_files_note(struct memelfnote *note) { struct mm_struct *mm = current->mm; struct vm_area_struct *vma; - unsigned count, size, names_ofs, remaining, n; + unsigned int count, size, names_ofs, remaining, n; user_long_t *data; user_long_t *start_end_ofs; char *name_base, *name_curpos; @@ -1633,7 +1642,7 @@ static int fill_files_note(struct memelfnote *note) name_base = name_curpos = ((char *)data) + names_ofs; remaining = size - names_ofs; count = 0; - for (vma = mm->mmap; vma != NULL; vma = vma->vm_next) { + for (vma = mm->mmap; vma; vma = vma->vm_next) { struct file *file; const char *filename; @@ -1739,7 +1748,8 @@ static int fill_thread_core_info(struct elf_thread_core_info *t, */ fill_prstatus(&t->prstatus, t->task, signr); regset0_size = regset_get(t->task, &view->regsets[0], - sizeof(t->prstatus.pr_reg), &t->prstatus.pr_reg); + sizeof(t->prstatus.pr_reg), + &t->prstatus.pr_reg); if (regset0_size < 0) return 0; @@ -1762,7 +1772,7 @@ static int fill_thread_core_info(struct elf_thread_core_info *t, int ret; do_thread_regset_writeback(t->task, regset); - if (!note_type) // not for coredumps + if (!note_type) /* not for coredumps */ continue; if (regset->active && regset->active(t->task, regset) <= 0) continue; @@ -1798,16 +1808,14 @@ static int fill_note_info(struct elfhdr *elf, int phdrs, info->thread = NULL; psinfo = kmalloc(sizeof(*psinfo), GFP_KERNEL); - if (psinfo == NULL) { + if (!psinfo) { info->psinfo.data = NULL; /* So we don't free this wrongly */ return 0; } fill_note(&info->psinfo, "CORE", NT_PRPSINFO, sizeof(*psinfo), psinfo); - /* - * Figure out how many notes we're going to need for each thread. - */ + /* Figure out how many notes we're going to need for each thread. */ info->thread_notes = 0; for (i = 0; i < view->n; ++i) if (view->regsets[i].core_note_type != 0) @@ -1823,15 +1831,11 @@ static int fill_note_info(struct elfhdr *elf, int phdrs, return 0; } - /* - * Initialize the ELF file header. - */ + /* Initialize the ELF file header. */ fill_elf_header(elf, phdrs, view->e_machine, view->e_flags); - /* - * Allocate a structure for each thread. - */ + /* Allocate a structure for each thread. */ for (ct = &dump_task->mm->core_state->dumper; ct; ct = ct->next) { t = kzalloc(offsetof(struct elf_thread_core_info, notes[info->thread_notes]), @@ -1853,16 +1857,12 @@ static int fill_note_info(struct elfhdr *elf, int phdrs, } } - /* - * Now fill in each thread's information. - */ - for (t = info->thread; t != NULL; t = t->next) + /* Now fill in each thread's information. */ + for (t = info->thread; t; t = t->next) if (!fill_thread_core_info(t, view, siginfo->si_signo, &info->size)) return 0; - /* - * Fill in the two process-wide notes. - */ + /* Fill in the two process-wide notes. */ fill_psinfo(psinfo, dump_task->group_leader, dump_task->mm); info->size += notesize(&info->psinfo); @@ -1905,8 +1905,7 @@ static int write_note_info(struct elf_note_info *info, return 0; if (first && !writenote(&info->auxv, cprm)) return 0; - if (first && info->files.data && - !writenote(&info->files, cprm)) + if (first && info->files.data && !writenote(&info->files, cprm)) return 0; for (i = 1; i < info->thread_notes; ++i) @@ -1924,6 +1923,7 @@ static int write_note_info(struct elf_note_info *info, static void free_note_info(struct elf_note_info *info) { struct elf_thread_core_info *threads = info->thread; + while (threads) { unsigned int i; struct elf_thread_core_info *t = threads; @@ -1940,8 +1940,7 @@ static void free_note_info(struct elf_note_info *info) #else /* Here is the structure in which status of each thread is captured. */ -struct elf_thread_status -{ +struct elf_thread_status { struct list_head list; struct elf_prstatus prstatus; /* NT_PRSTATUS */ elf_fpregset_t fpu; /* NT_PRFPREG */ @@ -1959,20 +1958,21 @@ static int elf_dump_thread_status(long signr, struct elf_thread_status *t) { int sz = 0; struct task_struct *p = t->thread; + t->num_notes = 0; fill_prstatus(&t->prstatus, p, signr); - elf_core_copy_task_regs(p, &t->prstatus.pr_reg); - + elf_core_copy_task_regs(p, &t->prstatus.pr_reg); + fill_note(&t->notes[0], "CORE", NT_PRSTATUS, sizeof(t->prstatus), - &(t->prstatus)); + &t->prstatus); t->num_notes++; sz += notesize(&t->notes[0]); - if ((t->prstatus.pr_fpvalid = elf_core_copy_task_fpregs(p, NULL, - &t->fpu))) { + t->prstatus.pr_fpvalid = elf_core_copy_task_fpregs(p, NULL, &t->fpu); + if (t->prstatus.pr_fpvalid) { fill_note(&t->notes[1], "CORE", NT_PRFPREG, sizeof(t->fpu), - &(t->fpu)); + &t->fpu); t->num_notes++; sz += notesize(&t->notes[1]); } @@ -2179,7 +2179,8 @@ static int elf_core_dump(struct coredump_params *cprm) /* If segs > PN_XNUM(0xffff), then e_phnum overflows. To avoid * this, kernel supports extended numbering. Have a look at - * include/linux/elf.h for further information. */ + * include/linux/elf.h for further information. + */ e_phnum = segs > PN_XNUM ? PN_XNUM : segs; /* @@ -2257,7 +2258,7 @@ static int elf_core_dump(struct coredump_params *cprm) if (!elf_core_write_extra_phdrs(cprm, offset)) goto end_coredump; - /* write out the notes section */ + /* write out the notes section */ if (!write_note_info(&info, cprm)) goto end_coredump; From patchwork Sat Nov 21 13:57:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Colomar X-Patchwork-Id: 11923395 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4771DC388F9 for ; Sat, 21 Nov 2020 13:58:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B3F42145D for ; Sat, 21 Nov 2020 13:58:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="n4fGODwo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727931AbgKUN5z (ORCPT ); Sat, 21 Nov 2020 08:57:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727905AbgKUN5s (ORCPT ); Sat, 21 Nov 2020 08:57:48 -0500 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60A4CC061A4A; Sat, 21 Nov 2020 05:57:47 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id u12so13858797wrt.0; Sat, 21 Nov 2020 05:57:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6a1z7XonQ2cS2I/Jy3WeAqVi+Th8zgWS6ynCBcsLz98=; b=n4fGODwou2sJd3JSq/PGjSQgfAoN919dF/NbvR8AQH3/IaRLzuhVpi15UcInwdpBGE 7x6c7TrssblHY/FcCmirCav3P3M3XS+UfFZ8aSWmmZWGep33W5A5tP+qX97CfTJ+Yg3J CkUU+Mvua5dCyARVWg06f5jvYVUFRN8cqtuDCxxLfIwH1ccaN6EIiPvV97q5hAU4tLJZ 0FmYpasRQvnzH/EIQW2HyKf7lCSXXmdGOTB5BXR90A3Sqohxjxt8b6L8+/Ehxj5IQnkm 9dDivSFbjOSs8gP5bdGNsshi7gFa8vjkzgcMqgZbBCV5PJfLCGsyRlvLYcFqweSe/65O uLGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6a1z7XonQ2cS2I/Jy3WeAqVi+Th8zgWS6ynCBcsLz98=; b=Pwpop4dR7BSw5VYPQX7NDKKQkczOjNH25yO+837U4YC0qF29xQDVBJywuI6OVh0/xV WlQuKqkPK8Bl9fqlvFdh+3VYWDeuBCkh0ur9ie6G7k0Vbw6i6v6iGTCiW86h3LewOtq9 EA9tR4EZhyLly9Ypt1Pxf5jECv3920QicqTqKzr/khh5Wdf80DZOtTMCKtZPJwV9odSD DmZ9+hXtB8LWO2FwLw5rONabkdDyUizWtf6IGaUQuJ5Pp1POHdZoterSs42PAECcXtvW Lk0PioftFHbuC7KIdhnx27JiLTY7TBy8s0sgoSsB3PEx1hqHFF6ju7u5q082oNmr7ti8 WVmg== X-Gm-Message-State: AOAM5335kodtfiE+gyO4/o5AbDcN9cTSl0UeKN+wb2bXAqxP5mP6Ov6i IYAIR9VM71Woy9DKUOAyPng= X-Google-Smtp-Source: ABdhPJyFRr7Bz7zZhxXNDDK4uaRdC6KpUcFJKTkfIzMjlYZ2VTP9S60AchRdGLgDqfgARcs6UqKEZw== X-Received: by 2002:a5d:4703:: with SMTP id y3mr22087592wrq.416.1605967066133; Sat, 21 Nov 2020 05:57:46 -0800 (PST) Received: from localhost.localdomain ([170.253.49.0]) by smtp.googlemail.com with ESMTPSA id 17sm41689951wma.3.2020.11.21.05.57.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Nov 2020 05:57:45 -0800 (PST) From: Alejandro Colomar To: Alexander Viro , linux-fsdevel@vger.kernel.org Cc: Alejandro Colomar , linux-kernel@vger.kernel.org Subject: [PATCH 3/4] fs/attr.c, fs/bad_inode.c, fs/binfmt_aout.c, fs/binfmt_elf.c: Cosmetic Date: Sat, 21 Nov 2020 14:57:35 +0100 Message-Id: <20201121135736.295705-4-alx.manpages@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201121135736.295705-1-alx.manpages@gmail.com> References: <20201121135736.295705-1-alx.manpages@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Slightly non-trivial changes: - Move declarations to the top of function definitions. - Split multiple assignments in a single line to multiple lines with a signle assignment each. Signed-off-by: Alejandro Colomar --- fs/attr.c | 5 ++--- fs/bad_inode.c | 5 +++-- fs/binfmt_aout.c | 3 ++- fs/binfmt_elf.c | 26 ++++++++++++++++---------- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/fs/attr.c b/fs/attr.c index b32ad8c678a5..61f7a75ac330 100644 --- a/fs/attr.c +++ b/fs/attr.c @@ -62,13 +62,14 @@ int setattr_prepare(struct dentry *dentry, struct iattr *attr) { struct inode *inode = d_inode(dentry); unsigned int ia_valid = attr->ia_valid; + int error; /* * First check size constraints. These can't be overridden using * ATTR_FORCE. */ if (ia_valid & ATTR_SIZE) { - int error = inode_newsize_ok(inode, attr->ia_size); + error = inode_newsize_ok(inode, attr->ia_size); if (error) return error; } @@ -105,8 +106,6 @@ int setattr_prepare(struct dentry *dentry, struct iattr *attr) kill_priv: /* User has permission for the change */ if (ia_valid & ATTR_KILL_PRIV) { - int error; - error = security_inode_killpriv(dentry); if (error) return error; diff --git a/fs/bad_inode.c b/fs/bad_inode.c index f0457b6c17dc..4c5e677ec423 100644 --- a/fs/bad_inode.c +++ b/fs/bad_inode.c @@ -200,8 +200,9 @@ void make_bad_inode(struct inode *inode) remove_inode_hash(inode); inode->i_mode = S_IFREG; - inode->i_atime = inode->i_mtime = inode->i_ctime = - current_time(inode); + inode->i_ctime = current_time(inode); + inode->i_mtime = inode->i_ctime; + inode->i_atime = inode->i_ctime; inode->i_op = &bad_inode_ops; inode->i_opflags &= ~IOP_XATTR; inode->i_fop = &bad_file_ops; diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c index 92d6b70ddab0..976d5f1565e1 100644 --- a/fs/binfmt_aout.c +++ b/fs/binfmt_aout.c @@ -97,7 +97,8 @@ static unsigned long __user *create_aout_tables(char __user *p, struct linux_bin } while (c); } put_user(NULL, argv); - current->mm->arg_end = current->mm->env_start = (unsigned long)p; + current->mm->env_start = (unsigned long)p; + current->mm->arg_end = (unsigned long)p; while (envc-- > 0) { char c; diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 955927ac2b80..b5e1e0a0917a 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1035,13 +1035,12 @@ static int load_elf_binary(struct linux_binprm *bprm) unsigned long k, vaddr; unsigned long total_size = 0; unsigned long alignment; + unsigned long nbyte; if (elf_ppnt->p_type != PT_LOAD) continue; if (unlikely(elf_brk > elf_bss)) { - unsigned long nbyte; - /* * There was a PT_LOAD segment with p_memsz > p_filesz * before this one. Map anonymous pages, if needed, @@ -1277,10 +1276,12 @@ static int load_elf_binary(struct linux_binprm *bprm) */ if (IS_ENABLED(CONFIG_ARCH_HAS_ELF_RANDOMIZE) && elf_ex->e_type == ET_DYN && !interpreter) { - mm->brk = mm->start_brk = ELF_ET_DYN_BASE; + mm->start_brk = ELF_ET_DYN_BASE; + mm->brk = ELF_ET_DYN_BASE; } - mm->brk = mm->start_brk = arch_randomize_brk(mm); + mm->start_brk = arch_randomize_brk(mm); + mm->brk = mm->start_brk; #ifdef compat_brk_randomized current->brk_randomized = 1; #endif @@ -1506,7 +1507,8 @@ static void fill_note(struct memelfnote *note, const char *name, int type, static void fill_prstatus(struct elf_prstatus *prstatus, struct task_struct *p, long signr) { - prstatus->pr_info.si_signo = prstatus->pr_cursig = signr; + prstatus->pr_cursig = signr; + prstatus->pr_info.si_signo = signr; prstatus->pr_sigpend = p->pending.signal.sig[0]; prstatus->pr_sighold = p->blocked.sig[0]; rcu_read_lock(); @@ -1618,6 +1620,7 @@ static int fill_files_note(struct memelfnote *note) user_long_t *data; user_long_t *start_end_ofs; char *name_base, *name_curpos; + unsigned int shift_bytes; /* *Estimated* file count and total data size needed */ count = mm->map_count; @@ -1639,7 +1642,8 @@ static int fill_files_note(struct memelfnote *note) return -ENOMEM; start_end_ofs = data + 2; - name_base = name_curpos = ((char *)data) + names_ofs; + name_curpos = ((char *)data) + names_ofs; + name_base = name_curpos; remaining = size - names_ofs; count = 0; for (vma = mm->mmap; vma; vma = vma->vm_next) { @@ -1681,7 +1685,7 @@ static int fill_files_note(struct memelfnote *note) */ n = mm->map_count - count; if (n != 0) { - unsigned shift_bytes = n * 3 * sizeof(data[0]); + shift_bytes = n * 3 * sizeof(data[0]); memmove(name_base - shift_bytes, name_base, name_curpos - name_base); name_curpos -= shift_bytes; @@ -1922,11 +1926,12 @@ static int write_note_info(struct elf_note_info *info, static void free_note_info(struct elf_note_info *info) { + struct elf_thread_core_info *t; struct elf_thread_core_info *threads = info->thread; + unsigned int i; while (threads) { - unsigned int i; - struct elf_thread_core_info *t = threads; + t = threads; threads = t->next; WARN_ON(t->notes[0].data && t->notes[0].data != &t->prstatus); for (i = 1; i < info->thread_notes; ++i) @@ -2209,7 +2214,8 @@ static int elf_core_dump(struct coredump_params *cprm) offset += sz; } - dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE); + offset = roundup(offset, ELF_EXEC_PAGESIZE); + dataoff = offset; offset += vma_data_size; offset += elf_core_extra_data_size(); From patchwork Sat Nov 21 13:57:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Colomar X-Patchwork-Id: 11923397 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4EF2C56202 for ; Sat, 21 Nov 2020 13:58:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D6812245F for ; Sat, 21 Nov 2020 13:58:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XYXgafoU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727925AbgKUN5z (ORCPT ); Sat, 21 Nov 2020 08:57:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727912AbgKUN5t (ORCPT ); Sat, 21 Nov 2020 08:57:49 -0500 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D088C061A4B; Sat, 21 Nov 2020 05:57:48 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id p19so10129841wmg.0; Sat, 21 Nov 2020 05:57:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oQxhkMEdQnyYr8WsxFvRrEHJSPLBuk0HpQQMWna+wtU=; b=XYXgafoUb29o52G8xh9L2ZFZ+KugeI8XofyMumqdgSFpurfLAV9cs05Ipy2VLHou8d BdAPAZMSIZk38Xn5U2WOI3u+CniV4QnPfPYRqPNa2A9usI21W9xjjF4OAk1IGYE1jS2b sDjXcZb7yJwSh+p/XvMFpK1eUum2gwOjVtfgaBglebricVWISyyss71YWYhjRzBGKq96 PDD0qfJxqLFhvpFbnjB7+/ASV8pg+AtK9E2cXZpK4LeVMjuS2dPNZJQi1telxtCy0DyC nRDBrxHudjMAlOiDbsrFw+ztKawvTAVjKusWXV8e64/BmReWdhh2tIUGHPqYy1nq+P6b Q7pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oQxhkMEdQnyYr8WsxFvRrEHJSPLBuk0HpQQMWna+wtU=; b=rsUsqcoEdL9oeQRfBqsE+tnv37k+5n1WjkD2C1qbpFycirW1fMDQEWRDJEJevUaLOa 2jc0O9hfcgkpjBDVlfbjTEHgTH2PEQzKj4kXJY1W+y4KUxUrQ2GRLhG2DE0V+Xb52Xmk hSoA+Q48lJuGwHm6cnrb0bj8UH5lK1Eanl1UtpgblU3q7YYhYKS7zcG6No7CJ0xBUf0n QqYdJRKS+pr/GkzOq2XEBo17UBgG6/FpML7O7ougPY7RTRQdtn5BYzaWGnS5Zb6IYJFw /DUQ67B0VY50tehk1xw0Dhp6cwpTBDAUul4TNyMJNgxBHkxocCH27SOaQMGw9QlV0ajz w3pg== X-Gm-Message-State: AOAM532k6SN64k9WjAQwn3cK7dQ/liIJoH1ieoIjTTknunl1YysLMhOK xOCMARGUYzqoXLPh2/cI7mk= X-Google-Smtp-Source: ABdhPJzUz8zNVI0vBTw4F/OEqz5uTbnj627pFyoEmSr7Ic0cIKL1Ag/O0tzIe5z+xeZQiBNVONZlTA== X-Received: by 2002:a1c:bbc4:: with SMTP id l187mr15763634wmf.133.1605967067308; Sat, 21 Nov 2020 05:57:47 -0800 (PST) Received: from localhost.localdomain ([170.253.49.0]) by smtp.googlemail.com with ESMTPSA id 17sm41689951wma.3.2020.11.21.05.57.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Nov 2020 05:57:46 -0800 (PST) From: Alejandro Colomar To: Alexander Viro , linux-fsdevel@vger.kernel.org Cc: Alejandro Colomar , linux-kernel@vger.kernel.org Subject: [PATCH 4/4] fs/binfmt_elf.c: Cosmetic Date: Sat, 21 Nov 2020 14:57:36 +0100 Message-Id: <20201121135736.295705-5-alx.manpages@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201121135736.295705-1-alx.manpages@gmail.com> References: <20201121135736.295705-1-alx.manpages@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Non-trivial changes: Invert 'if's to simplify logic. Use 'goto' in conjunction with the above, when appropriate. Signed-off-by: Alejandro Colomar --- fs/binfmt_elf.c | 115 +++++++++++++++++++++++++----------------------- 1 file changed, 59 insertions(+), 56 deletions(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index b5e1e0a0917a..dbd50b5bf238 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1079,65 +1079,68 @@ static int load_elf_binary(struct linux_binprm *bprm) */ if (elf_ex->e_type == ET_EXEC || load_addr_set) { elf_flags |= MAP_FIXED; - } else if (elf_ex->e_type == ET_DYN) { - /* - * This logic is run once for the first LOAD Program - * Header for ET_DYN binaries to calculate the - * randomization (load_bias) for all the LOAD - * Program Headers, and to calculate the entire - * size of the ELF mapping (total_size). (Note that - * load_addr_set is set to true later once the - * initial mapping is performed.) - * - * There are effectively two types of ET_DYN - * binaries: programs (i.e. PIE: ET_DYN with INTERP) - * and loaders (ET_DYN without INTERP, since they - * _are_ the ELF interpreter). The loaders must - * be loaded away from programs since the program - * may otherwise collide with the loader (especially - * for ET_EXEC which does not have a randomized - * position). For example to handle invocations of - * "./ld.so someprog" to test out a new version of - * the loader, the subsequent program that the - * loader loads must avoid the loader itself, so - * they cannot share the same load range. Sufficient - * room for the brk must be allocated with the - * loader as well, since brk must be available with - * the loader. - * - * Therefore, programs are loaded offset from - * ELF_ET_DYN_BASE and loaders are loaded into the - * independently randomized mmap region (0 load_bias - * without MAP_FIXED). - */ - if (interpreter) { - load_bias = ELF_ET_DYN_BASE; - if (current->flags & PF_RANDOMIZE) - load_bias += arch_mmap_rnd(); - alignment = maximum_alignment(elf_phdata, elf_ex->e_phnum); - if (alignment) - load_bias &= ~(alignment - 1); - elf_flags |= MAP_FIXED; - } else - load_bias = 0; + goto proceed_normally; + } + if (elf_ex->e_type != ET_DYN) + goto proceed_normally; + /* + * This logic is run once for the first LOAD Program + * Header for ET_DYN binaries to calculate the + * randomization (load_bias) for all the LOAD + * Program Headers, and to calculate the entire + * size of the ELF mapping (total_size). (Note that + * load_addr_set is set to true later once the + * initial mapping is performed.) + * + * There are effectively two types of ET_DYN + * binaries: programs (i.e. PIE: ET_DYN with INTERP) + * and loaders (ET_DYN without INTERP, since they + * _are_ the ELF interpreter). The loaders must + * be loaded away from programs since the program + * may otherwise collide with the loader (especially + * for ET_EXEC which does not have a randomized + * position). For example to handle invocations of + * "./ld.so someprog" to test out a new version of + * the loader, the subsequent program that the + * loader loads must avoid the loader itself, so + * they cannot share the same load range. Sufficient + * room for the brk must be allocated with the + * loader as well, since brk must be available with + * the loader. + * + * Therefore, programs are loaded offset from + * ELF_ET_DYN_BASE and loaders are loaded into the + * independently randomized mmap region (0 load_bias + * without MAP_FIXED). + */ + if (interpreter) { + load_bias = ELF_ET_DYN_BASE; + if (current->flags & PF_RANDOMIZE) + load_bias += arch_mmap_rnd(); + alignment = maximum_alignment(elf_phdata, elf_ex->e_phnum); + if (alignment) + load_bias &= ~(alignment - 1); + elf_flags |= MAP_FIXED; + } else { + load_bias = 0; + } - /* - * Since load_bias is used for all subsequent loading - * calculations, we must lower it by the first vaddr - * so that the remaining calculations based on the - * ELF vaddrs will be correctly offset. The result - * is then page aligned. - */ - load_bias = ELF_PAGESTART(load_bias - vaddr); + /* + * Since load_bias is used for all subsequent loading + * calculations, we must lower it by the first vaddr + * so that the remaining calculations based on the + * ELF vaddrs will be correctly offset. The result + * is then page aligned. + */ + load_bias = ELF_PAGESTART(load_bias - vaddr); - total_size = total_mapping_size(elf_phdata, - elf_ex->e_phnum); - if (!total_size) { - retval = -EINVAL; - goto out_free_dentry; - } + total_size = total_mapping_size(elf_phdata, + elf_ex->e_phnum); + if (!total_size) { + retval = -EINVAL; + goto out_free_dentry; } - +proceed_normally: /* FIXME: a better label name? */ error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt, elf_prot, elf_flags, total_size); if (BAD_ADDR(error)) {