[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6599ac61289e3316bff53602a0bc5970133251aa.camel@linux.ibm.com>
Date: Wed, 01 Dec 2021 12:56:27 -0500
From: James Bottomley <jejb@...ux.ibm.com>
To: Stefan Berger <stefanb@...ux.ibm.com>,
linux-integrity@...r.kernel.org
Cc: zohar@...ux.ibm.com, serge@...lyn.com,
christian.brauner@...ntu.com, containers@...ts.linux.dev,
dmitry.kasatkin@...il.com, ebiederm@...ssion.com,
krzysztof.struczynski@...wei.com, roberto.sassu@...wei.com,
mpeters@...hat.com, lhinds@...hat.com, lsturman@...hat.com,
puiterwi@...hat.com, jamjoom@...ibm.com,
linux-kernel@...r.kernel.org, paul@...l-moore.com, rgb@...hat.com,
linux-security-module@...r.kernel.org, jmorris@...ei.org
Subject: Re: [RFC 20/20] ima: Setup securityfs_ns for IMA namespace
On Tue, 2021-11-30 at 11:06 -0500, Stefan Berger wrote:
[...]
> +
> +/*
> + * Fix the ownership (uid/gid) of the dentry's that couldn't be set
> at the
> + * time of their creation because the user namespace wasn't
> configured, yet.
> + */
> +static void ima_fs_ns_fixup_uid_gid(struct ima_namespace *ns)
> +{
> + struct inode *inode;
> + size_t i;
> +
> + if (ns->file_ownership_fixes_done ||
> + ns->user_ns->uid_map.nr_extents == 0)
> + return;
> +
> + ns->file_ownership_fixes_done = true;
> + for (i = 0; i < IMAFS_DENTRY_LAST; i++) {
> + if (!ns->dentry[i])
> + continue;
> + inode = ns->dentry[i]->d_inode;
> + inode->i_uid = make_kuid(ns->user_ns, 0);
> + inode->i_gid = make_kgid(ns->user_ns, 0);
> + }
> +}
> +
> +/* Fix the permissions when a file is opened */
> +int ima_fs_ns_permission(struct user_namespace *mnt_userns, struct
> inode *inode,
> + int mask)
> +{
> + ima_fs_ns_fixup_uid_gid(get_current_ns());
> + return generic_permission(mnt_userns, inode, mask);
> +}
> +
> +const struct inode_operations ima_fs_ns_inode_operations = {
> + .lookup = simple_lookup,
> + .permission = ima_fs_ns_permission,
> +};
> +
In theory this uid/gid shifting should have already been done for you
and all of the above code should be unnecessary. What is supposed to
happen is that the mount of securityfs_ns in the new user namespace
should pick up a superblock s_user_ns for that new user namespace. Now
inode_alloc() uses i_uid_write(inode, 0) which maps back through the
s_user_ns to obtain the owner of the user namespace.
What can happen is that if you do the inode allocation before (or even
without) writing to the uid_map file, it maps back through an empty map
and ends up with -1 for i_uid ... is this what you're seeing?
James
Powered by blists - more mailing lists