From patchwork Tue Feb 16 22:49:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 8333021 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 95C20C02AA for ; Tue, 16 Feb 2016 22:49:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8E7D7202E5 for ; Tue, 16 Feb 2016 22:49:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8F95B202B8 for ; Tue, 16 Feb 2016 22:49:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933194AbcBPWty (ORCPT ); Tue, 16 Feb 2016 17:49:54 -0500 Received: from mail-wm0-f52.google.com ([74.125.82.52]:33965 "EHLO mail-wm0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932647AbcBPWtl (ORCPT ); Tue, 16 Feb 2016 17:49:41 -0500 Received: by mail-wm0-f52.google.com with SMTP id b205so131229115wmb.1 for ; Tue, 16 Feb 2016 14:49:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YyzL3xVI/QyD6HwMEmXiFo8Xg2CJQI2MoZrYptFZtZo=; b=bi262Zx4hL95w1aD1k2EOoANk52Wk5av/JMgZwOPyE+OIlGDyuPsMlxqu4jlrmkcdS H1HCgKw3IxC6D988tWKm0WQuLuQKc8Xw52x6+2FDpqQVceb0Go6UAl8y6LwGif06cHed SaGwOjqyjMnBmf7EMNYDPyUxF8Och6pbevTjU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YyzL3xVI/QyD6HwMEmXiFo8Xg2CJQI2MoZrYptFZtZo=; b=gTZfQEgFH4QGm0RiLK1LKID7aFn26ukZx2FjKliXEG8rH3uJGP9srSoenKexz3AKiV zTDXu1/TWi6K52OcB949wHQXRH3zuArvPx2jgDZppx83lQcyWjQBjQvKoT3uotkM/z7H zADUZ46e/caAw8rixUp8rEGg6VNmt0cIJzqs27eRmkzU2sc7tx7k8zChewLJQnCuVj0u OdNQySrXFSVrXKDZYEM6gxSIYynnr/egiZVAHROUYh3EIX4FF4rBrr0sJm6Npei8H5V+ xQpAA0PStSNBxc4Mj+zK7kmpC6qbiSLIwA6lbZUF6gIHlLSJg8dJ5iXj3+UwWDwgNd1e pj2w== X-Gm-Message-State: AG10YOTxVtBAEXWGfxaCcEEsAR2YV+nv54O8UlPV7RQyhiJrR0bB9lcqtesInLfALUl0kA== X-Received: by 10.194.22.68 with SMTP id b4mr16631594wjf.158.1455662980719; Tue, 16 Feb 2016 14:49:40 -0800 (PST) Received: from wildmoose.dk (lvps87-230-87-209.dedicated.hosteurope.de. [87.230.87.209]) by smtp.gmail.com with ESMTPSA id ka4sm32251893wjc.47.2016.02.16.14.49.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Feb 2016 14:49:40 -0800 (PST) From: Rasmus Villemoes To: Alexander Viro , Paul Moore , Eric Paris , Jeff Layton , "J. Bruce Fields" Cc: Rasmus Villemoes , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-audit@redhat.com Subject: [PATCH 2/2] vfs: don't always include audit-specific members of struct filename Date: Tue, 16 Feb 2016 23:49:25 +0100 Message-Id: <1455662966-7977-2-git-send-email-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1455662966-7977-1-git-send-email-linux@rasmusvillemoes.dk> References: <1455662966-7977-1-git-send-email-linux@rasmusvillemoes.dk> 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_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham 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 The three members uptr, aname and refcnt are only used when CONFIG_AUDITSYSCALL, a fact which is not obvious from the header file or namei.c alone. So aside from eliminating a few useless instructions in getname_flags and making EMBEDDED_NAME_MAX a little larger, this patch also serves to document whoe the actual user of these members is. Signed-off-by: Rasmus Villemoes --- fs/namei.c | 10 ++++------ include/linux/audit.h | 9 +++++++++ include/linux/fs.h | 2 ++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index bd150fa799a2..21410db25814 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -185,7 +185,6 @@ getname_flags(const char __user *filename, int flags, int *empty) } } - result->refcnt = 1; /* The empty path is special. */ if (unlikely(!len)) { if (empty) @@ -196,8 +195,7 @@ getname_flags(const char __user *filename, int flags, int *empty) } } - result->uptr = filename; - result->aname = NULL; + audit_init_filename(result, filename); audit_getname(result); return result; } @@ -235,9 +233,7 @@ getname_kernel(const char * filename) return ERR_PTR(-ENAMETOOLONG); } memcpy((char *)result->name, filename, len); - result->uptr = NULL; - result->aname = NULL; - result->refcnt = 1; + audit_init_filename(result, NULL); audit_getname(result); return result; @@ -245,10 +241,12 @@ getname_kernel(const char * filename) void putname(struct filename *name) { +#ifdef CONFIG_AUDITSYSCALL BUG_ON(name->refcnt <= 0); if (--name->refcnt > 0) return; +#endif if (name->name != name->iname) { __putname(name->name); diff --git a/include/linux/audit.h b/include/linux/audit.h index b40ed5df5542..7d7143674d85 100644 --- a/include/linux/audit.h +++ b/include/linux/audit.h @@ -232,6 +232,12 @@ extern void __audit_syscall_entry(int major, unsigned long a0, unsigned long a1, extern void __audit_syscall_exit(int ret_success, long ret_value); extern struct filename *__audit_reusename(const __user char *uptr); extern void __audit_getname(struct filename *name); +static inline void audit_init_filename(struct filename *name, const __user char *uptr) +{ + name->refcnt = 1; + name->aname = NULL; + name->uptr = uptr; +} #define AUDIT_INODE_PARENT 1 /* dentry represents the parent */ #define AUDIT_INODE_HIDDEN 2 /* audit record should be hidden */ @@ -459,6 +465,9 @@ static inline struct filename *audit_reusename(const __user char *name) } static inline void audit_getname(struct filename *name) { } +static inline void audit_init_filename(struct filename *name, const __user char *uptr) +{ } + static inline void __audit_inode(struct filename *name, const struct dentry *dentry, unsigned int flags) diff --git a/include/linux/fs.h b/include/linux/fs.h index d522e6391855..df769f738695 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2243,12 +2243,14 @@ static inline int break_layout(struct inode *inode, bool wait) struct audit_names; struct filename { const char *name; /* pointer to actual string */ +#ifdef CONFIG_AUDITSYSCALL const __user char *uptr; /* original userland pointer */ struct audit_names *aname; union { int refcnt; long __padding; }; +#endif const char iname[]; };