From patchwork Mon Jan 19 20:08:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Moore X-Patchwork-Id: 5660911 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4AF749F357 for ; Mon, 19 Jan 2015 20:09:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 55EF3201BB for ; Mon, 19 Jan 2015 20:09:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4822B20172 for ; Mon, 19 Jan 2015 20:09:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752144AbbASUIM (ORCPT ); Mon, 19 Jan 2015 15:08:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55909 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751844AbbASUIK (ORCPT ); Mon, 19 Jan 2015 15:08:10 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t0JK893V013217 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 19 Jan 2015 15:08:09 -0500 Received: from [127.0.0.1] (vpn-57-59.rdu2.redhat.com [10.10.57.59]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t0JK886T011086; Mon, 19 Jan 2015 15:08:08 -0500 Subject: [PATCH 2/5] fs: create proper filename objects using getname_kernel() From: Paul Moore To: linux-fsdevel@vger.kernel.org, linux-audit@redhat.com Cc: viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org Date: Mon, 19 Jan 2015 15:08:08 -0500 Message-ID: <20150119200808.29706.73419.stgit@localhost> In-Reply-To: <20150119200408.29706.24386.stgit@localhost> References: <20150119200408.29706.24386.stgit@localhost> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 There are several areas in the kernel that create temporary filename objects using the following pattern: int func(const char *name) { struct filename *file = { .name = name }; ... return 0; } ... which for the most part works okay, but it causes havoc within the audit subsystem as the filename object does not persist beyond the lifetime of the function. This patch converts all of these temporary filename objects into proper filename objects using getname_kernel() and putname() which ensure that the filename object persists until the audit subsystem is finished with it. CC: viro@zeniv.linux.org.uk CC: linux-fsdevel@vger.kernel.org Signed-off-by: Paul Moore Reviewed-by: Richard Guy Briggs --- fs/exec.c | 11 +++++++++-- fs/namei.c | 34 ++++++++++++++++++++++++++-------- fs/open.c | 11 +++++++++-- 3 files changed, 44 insertions(+), 12 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/exec.c b/fs/exec.c index a3d33fe..d067771 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -789,8 +789,15 @@ exit: struct file *open_exec(const char *name) { - struct filename tmp = { .name = name }; - return do_open_exec(&tmp); + struct file *file; + struct filename *tmp; + + tmp = getname_kernel(name); + if (unlikely(IS_ERR(tmp))) + return (void *)tmp; + file = do_open_exec(tmp); + putname(tmp); + return file; } EXPORT_SYMBOL(open_exec); diff --git a/fs/namei.c b/fs/namei.c index eeb3b83..c3d21b7 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -2001,9 +2001,15 @@ static int filename_lookup(int dfd, struct filename *name, static int do_path_lookup(int dfd, const char *name, unsigned int flags, struct nameidata *nd) { - struct filename filename = { .name = name }; + int retval; + struct filename *filename; - return filename_lookup(dfd, &filename, flags, nd); + filename = getname_kernel(name); + if (unlikely(IS_ERR(filename))) + return PTR_ERR(filename); + retval = filename_lookup(dfd, filename, flags, nd); + putname(filename); + return retval; } /* does lookup, returns the object with parent locked */ @@ -2368,8 +2374,15 @@ int kern_path_mountpoint(int dfd, const char *name, struct path *path, unsigned int flags) { - struct filename s = {.name = name}; - return filename_mountpoint(dfd, &s, path, flags); + int retval; + struct filename *s; + + s = getname_kernel(name); + if (unlikely(IS_ERR(s))) + return PTR_ERR(s); + retval = filename_mountpoint(dfd, s, path, flags); + putname(s); + return retval; } EXPORT_SYMBOL(kern_path_mountpoint); @@ -3259,7 +3272,7 @@ struct file *do_file_open_root(struct dentry *dentry, struct vfsmount *mnt, { struct nameidata nd; struct file *file; - struct filename filename = { .name = name }; + struct filename *filename; int flags = op->lookup_flags | LOOKUP_ROOT; nd.root.mnt = mnt; @@ -3268,11 +3281,16 @@ struct file *do_file_open_root(struct dentry *dentry, struct vfsmount *mnt, if (d_is_symlink(dentry) && op->intent & LOOKUP_OPEN) return ERR_PTR(-ELOOP); - file = path_openat(-1, &filename, &nd, op, flags | LOOKUP_RCU); + filename = getname_kernel(name); + if (unlikely(IS_ERR(filename))) + return (void *)filename; + + file = path_openat(-1, filename, &nd, op, flags | LOOKUP_RCU); if (unlikely(file == ERR_PTR(-ECHILD))) - file = path_openat(-1, &filename, &nd, op, flags); + file = path_openat(-1, filename, &nd, op, flags); if (unlikely(file == ERR_PTR(-ESTALE))) - file = path_openat(-1, &filename, &nd, op, flags | LOOKUP_REVAL); + file = path_openat(-1, filename, &nd, op, flags | LOOKUP_REVAL); + putname(filename); return file; } diff --git a/fs/open.c b/fs/open.c index d6fd3ac..666982b 100644 --- a/fs/open.c +++ b/fs/open.c @@ -940,8 +940,15 @@ struct file *file_open_name(struct filename *name, int flags, umode_t mode) */ struct file *filp_open(const char *filename, int flags, umode_t mode) { - struct filename name = {.name = filename}; - return file_open_name(&name, flags, mode); + struct file *file; + struct filename *name; + + name = getname_kernel(filename); + if (unlikely(IS_ERR(name))) + return (void *)name; + file = file_open_name(name, flags, mode); + putname(name); + return file; } EXPORT_SYMBOL(filp_open);