From: Richard Guy Briggs <rgb@redhat.com>
To: Paul Moore <pmoore@redhat.com>
Cc: linux-audit@redhat.com, viro@zeniv.linux.org.uk,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 2/5] fs: create proper filename objects using getname_kernel()
Date: Wed, 14 Jan 2015 16:03:24 -0500 [thread overview]
Message-ID: <20150114210324.GN29998@madcap2.tricolour.ca> (raw)
In-Reply-To: <20150108165036.11316.14958.stgit@localhost>
On 15/01/08, Paul Moore wrote:
> 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.
>
> Signed-off-by: Paul Moore <pmoore@redhat.com>
Reviewed-by: Richard Guy Briggs <rgb@redhat.com>
> ---
> fs/exec.c | 11 +++++++++--
> fs/namei.c | 34 ++++++++++++++++++++++++++--------
> fs/open.c | 11 +++++++++--
> 3 files changed, 44 insertions(+), 12 deletions(-)
>
> 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);
>
>
> --
> Linux-audit mailing list
> Linux-audit@redhat.com
> https://www.redhat.com/mailman/listinfo/linux-audit
- RGB
--
Richard Guy Briggs <rbriggs@redhat.com>
Senior Software Engineer, Kernel Security, AMER ENG Base Operating Systems, Red Hat
Remote, Ottawa, Canada
Voice: +1.647.777.2635, Internal: (81) 32635, Alt: +1.613.693.0684x3545
next prev parent reply other threads:[~2015-01-14 21:03 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-08 16:50 [RFC PATCH 0/5] Overhaul the audit filename handling Paul Moore
2015-01-08 16:50 ` [RFC PATCH 1/5] fs: rework getname_kernel to handle up to PATH_MAX sized filenames Paul Moore
2015-01-14 21:02 ` Richard Guy Briggs
2015-01-08 16:50 ` [RFC PATCH 2/5] fs: create proper filename objects using getname_kernel() Paul Moore
2015-01-14 21:03 ` Richard Guy Briggs [this message]
2015-01-08 16:50 ` [RFC PATCH 3/5] audit: enable filename recording via getname_kernel() Paul Moore
2015-01-14 21:09 ` Richard Guy Briggs
2015-01-08 16:50 ` [RFC PATCH 4/5] audit: fix filename matching in __audit_inode() and __audit_inode_child() Paul Moore
2015-01-14 21:21 ` Richard Guy Briggs
2015-01-08 16:50 ` [RFC PATCH 5/5] audit: replace getname()/putname() hacks with reference counters Paul Moore
2015-01-14 21:37 ` Richard Guy Briggs
2015-01-14 21:45 ` Paul Moore
2015-01-12 21:03 ` [RFC PATCH 0/5] Overhaul the audit filename handling Paul Moore
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150114210324.GN29998@madcap2.tricolour.ca \
--to=rgb@redhat.com \
--cc=linux-audit@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmoore@redhat.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®