From: ebiederm@xmission.com (Eric W. Biederman)
To: Jan Kara <jack@suse.cz>
Cc: Seth Forshee <seth.forshee@canonical.com>,
Jann Horn <jannh@google.com>,
Linux API <linux-api@vger.kernel.org>,
Linux Containers <containers@lists.linux-foundation.org>,
Andy Lutomirski <luto@amacapital.net>,
James Bottomley <James.Bottomley@HansenPartnership.com>,
Michael Kerrisk <mtk.manpages@gmail.com>,
linux-fsdevel@vger.kernel.org, Djalal Harouni <tixxdz@gmail.com>
Subject: Re: [PATCH v2 review 09/11] quota: Handle quota data stored in s_user_ns.
Date: Tue, 05 Jul 2016 10:34:49 -0500 [thread overview]
Message-ID: <87d1msumhy.fsf@x220.int.ebiederm.org> (raw)
In-Reply-To: <20160704091100.GD5200@quack2.suse.cz> (Jan Kara's message of "Mon, 4 Jul 2016 11:11:00 +0200")
Jan Kara <jack@suse.cz> writes:
> On Sat 02-07-16 12:33:29, Eric W. Biederman wrote:
>> In Q_XSETQLIMIT use sb->s_user_ns to detect when we are dealing with
>> the filesystems notion of id 0.
>
> Hum, is it really usable? Basically the tool calling Q_XSETQLIMIT would
> have to be aware of the namespace the filesystem is mounted in to be able
> to perform the desired operation (and if it gets is wrong, there's
> possibility it would just silently set the timers for some user instead of
> for all users).
In general yes. Because we are talking about the uid of the root user
in the container that mounted the filesystem. It is the uid that is
stored as 0 on the filesystem. So in the small everything looks normal.
>> For the dquot hashfn translate the qid into sb->s_user_ns to remove
>> extraneous bits before hashing.
>>
>> When dealing with generic quota files in quota_tree.c, quota_v1.c, and
>> quota_v2.c before writing quotas to the file encode them in
>> sb->s_user_ns, and decode ids read from the file from sb->s_user_ns.
>
> And here the sb->s_user_ns becomes part of the on-disk format because the
> numerical ID value is used to compute the position in on-disk data
> structures. This seems to be in conflict with the idea that anything that
> is stored on disk is stored in the initial user namespace.
Up to now it has been the case that all filesystems with a backing store
that the kernel could mount stored their data in the initial user
namespace. This set of changes is all about making it so that a
filesystem with uids and gids stored in s_user_ns can be supported
safely by the kernel.
>> One complication comes up in qtree_get_next_id, as it is possible in
>> principle for id's to be present in the quota file that do not have a
>> mapping in the filesystems user namespace. If that is the case the
>> code is modified to skip the unmapped ids.
>
> So I'm not 100% sure how this is going to work. qtree_get_next_id() is used
> as an interface to report quota information for the whole filesystem. So
> skipping ids without mappings makes sense. However userspace uses the
> interface as:
>
> id = 0;
> while (get_next_quota(id, &result)) {
> do stuff;
> id = result.dq_id + 1;
> }
>
> If sb->s_user_ns is the current namespace of the process, I suppose this is
> going to work as expected. If the namespace of the process is different
> (including the init_user_ns), I expect this breaks, doesn't it?
Possibly. And this is a good question.
Where this will break initially in that scenario is in:
static int quota_getnextquota(struct super_block *sb, int type, qid_t id,
void __user *addr)
{
...
if (!sb->s_qcop->get_nextdqblk)
return -ENOSYS;
qid = make_kqid(current_user_ns(), type, id);
if (!qid_has_mapping(sb->s_user_ns, qid))
return -EINVAL;
ret = sb->s_qcop->get_nextdqblk(sb, &qid, &fdq);
if (ret)
If userspace actually has to perform the increment. The way
I read the code in
Now it has occurred to me that I am probably getting ahead of things
with actually enabling all of this for the quota subsystem as I don't
think we have fileystems that use the vfs quota support on our short
term list. I don't think these patches are wrong except possibily
in handling a quota interface with unmapped ids. Which is sufficiently
weird I don't know if there is something better we can do.
Given that we are not likely to use quotas for a while I am happy
to add a test in vfs_load_quota_inode (the guts of quota_on, and
quota_enable) that tests if s_user_ns != &init_user_ns and just fails.
Then the quota changes can be left until we figure out how to support a
filesystem that uses quota support. That should ensure better testing
coverage if nothing else.
The more I think of it the more I think that sounds like wisdom.
Dropping this patch and replacing it by one that just does:
diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c
index d8fb0fd3ff6f..9c9890fe18b7 100644
--- a/fs/quota/dquot.c
+++ b/fs/quota/dquot.c
@@ -2273,6 +2273,11 @@ static int vfs_load_quota_inode(struct inode *inode, int type, int format_id,
error = -EINVAL;
goto out_fmt;
}
+ /* Filesystems outside of init_user_ns not yet supported */
+ if (sb->s_user_ns != &init_user_ns) {
+ error = -EINVAL;
+ goto out_fmt;
+ }
/* Usage always has to be set... */
if (!(flags & DQUOT_USAGE_ENABLED)) {
error = -EINVAL;
seems a lot more appropriate at this point. That is enough to give a
great big hint there is something that needs to be done but won't
embrittle the code with untested corner cases.
Especially since the code probably needs testing and a very close review
to see what problems a hostile quota file can create. I the quota files
are simple enough we can't get into to much trouble but that is an
important consideration at this point.
So I am going to go respin this patchset replacing this change.
Eric
next prev parent reply other threads:[~2016-07-05 15:34 UTC|newest]
Thread overview: 134+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-02 17:18 [PATCH review 0/11] General unprivileged mount support Eric W. Biederman
2016-07-02 17:18 ` Eric W. Biederman
2016-07-02 17:20 ` [PATCH review 01/11] fs: Refuse uid/gid changes which don't map into s_user_ns Eric W. Biederman
2016-07-02 17:20 ` [PATCH review 03/11] vfs: Verify acls are valid within superblock's s_user_ns Eric W. Biederman
[not found] ` <20160702172035.19568-1-ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2016-07-02 17:20 ` [PATCH review 02/11] userns: Handle -1 in k[ug]id_has_mapping when !CONFIG_USER_NS Eric W. Biederman
2016-07-02 17:20 ` Eric W. Biederman
2016-07-02 17:20 ` [PATCH review 03/11] vfs: Verify acls are valid within superblock's s_user_ns Eric W. Biederman
2016-07-02 17:20 ` [PATCH review 04/11] fs: Check for invalid i_uid in may_follow_link() Eric W. Biederman
2016-07-02 17:20 ` Eric W. Biederman
2016-07-02 17:20 ` Eric W. Biederman
2016-07-02 17:20 ` [PATCH review 05/11] cred: Reject inodes with invalid ids in set_create_file_as() Eric W. Biederman
2016-07-02 17:20 ` [PATCH review 06/11] vfs: Don't modify inodes with a uid or gid unknown to the vfs Eric W. Biederman
2016-07-02 17:20 ` Eric W. Biederman
2016-07-02 17:20 ` Eric W. Biederman
2016-07-02 17:20 ` [PATCH review 07/11] vfs: Don't create " Eric W. Biederman
2016-07-02 17:20 ` [PATCH review 08/11] quota: Ensure qids map to the filesystem Eric W. Biederman
2016-07-02 17:20 ` [PATCH review 09/11] quota: Handle quota data stored in s_user_ns Eric W. Biederman
2016-07-02 17:20 ` Eric W. Biederman
2016-07-02 17:20 ` Eric W. Biederman
[not found] ` <20160702172035.19568-9-ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2016-07-02 17:33 ` [PATCH v2 " Eric W. Biederman
2016-07-02 17:33 ` Eric W. Biederman
[not found] ` <87mvm03pxy.fsf_-_-JOvCrm2gF+uungPnsOpG7nhyD016LWXt@public.gmane.org>
2016-07-04 9:11 ` Jan Kara
2016-07-04 9:11 ` Jan Kara
[not found] ` <20160704091100.GD5200-4I4JzKEfoa/jFM9bn6wA6Q@public.gmane.org>
2016-07-05 14:48 ` Seth Forshee
2016-07-05 15:34 ` Eric W. Biederman
2016-07-05 14:48 ` Seth Forshee
2016-07-05 15:34 ` Eric W. Biederman [this message]
[not found] ` <87d1msumhy.fsf-JOvCrm2gF+uungPnsOpG7nhyD016LWXt@public.gmane.org>
2016-07-05 20:57 ` Dave Chinner
2016-07-05 20:57 ` Dave Chinner
2016-07-05 21:28 ` Eric W. Biederman
2016-07-05 21:28 ` Eric W. Biederman
2016-07-05 21:28 ` Eric W. Biederman
[not found] ` <8737nnrcyy.fsf-JOvCrm2gF+uungPnsOpG7nhyD016LWXt@public.gmane.org>
2016-07-06 6:35 ` Dave Chinner
2016-07-06 6:35 ` Dave Chinner
2016-07-06 8:25 ` Jan Kara
2016-07-06 8:25 ` Jan Kara
2016-07-06 17:51 ` Eric W. Biederman
[not found] ` <20160706082545.GC14067-4I4JzKEfoa/jFM9bn6wA6Q@public.gmane.org>
2016-07-06 17:51 ` Eric W. Biederman
2016-07-05 20:57 ` Dave Chinner
2016-07-04 9:11 ` Jan Kara
2016-07-02 17:33 ` Eric W. Biederman
2016-07-02 17:20 ` [PATCH review 10/11] evm: Translate user/group ids relative to s_user_ns when computing HMAC Eric W. Biederman
2016-07-02 17:20 ` [PATCH review 11/11] fs: Update i_[ug]id_(read|write) to translate relative to s_user_ns Eric W. Biederman
2016-07-02 17:20 ` Eric W. Biederman
2016-07-02 17:20 ` [PATCH review 05/11] cred: Reject inodes with invalid ids in set_create_file_as() Eric W. Biederman
2016-07-02 17:20 ` [PATCH review 07/11] vfs: Don't create inodes with a uid or gid unknown to the vfs Eric W. Biederman
[not found] ` <20160702172035.19568-7-ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2016-07-04 7:59 ` Jan Kara
2016-07-04 7:59 ` Jan Kara
2016-07-04 7:59 ` Jan Kara
[not found] ` <20160704075919.GA5200-4I4JzKEfoa/jFM9bn6wA6Q@public.gmane.org>
2016-07-05 14:55 ` Eric W. Biederman
2016-07-05 14:55 ` Eric W. Biederman
[not found] ` <87zipwxhgp.fsf-JOvCrm2gF+uungPnsOpG7nhyD016LWXt@public.gmane.org>
2016-07-06 9:07 ` Jan Kara
2016-07-06 9:07 ` Jan Kara
[not found] ` <20160706090705.GE14067-4I4JzKEfoa/jFM9bn6wA6Q@public.gmane.org>
2016-07-06 15:37 ` Eric W. Biederman
2016-07-06 15:37 ` Eric W. Biederman
2016-07-06 15:37 ` Eric W. Biederman
2016-07-02 17:20 ` [PATCH review 08/11] quota: Ensure qids map to the filesystem Eric W. Biederman
2016-07-02 17:20 ` [PATCH review 10/11] evm: Translate user/group ids relative to s_user_ns when computing HMAC Eric W. Biederman
2016-07-04 8:52 ` [PATCH review 0/11] General unprivileged mount support Jan Kara
[not found] ` <20160704085220.GC5200-4I4JzKEfoa/jFM9bn6wA6Q@public.gmane.org>
2016-07-04 16:27 ` Eric W. Biederman
2016-07-04 16:27 ` Eric W. Biederman
[not found] ` <87h9c52wsd.fsf-JOvCrm2gF+uungPnsOpG7nhyD016LWXt@public.gmane.org>
2016-07-06 8:54 ` Jan Kara
2016-07-06 8:54 ` Jan Kara
[not found] ` <20160706085440.GD14067-4I4JzKEfoa/jFM9bn6wA6Q@public.gmane.org>
2016-07-06 13:54 ` Seth Forshee
2016-07-06 13:54 ` Seth Forshee
2016-07-06 14:22 ` Jan Kara
2016-07-06 14:22 ` Jan Kara
2016-07-06 14:22 ` Jan Kara
2016-07-06 14:46 ` Seth Forshee
[not found] ` <20160706142255.GB21164-4I4JzKEfoa/jFM9bn6wA6Q@public.gmane.org>
2016-07-06 14:46 ` Seth Forshee
2016-07-06 15:01 ` Eric W. Biederman
2016-07-06 15:23 ` James Bottomley
2016-07-06 15:01 ` Eric W. Biederman
2016-07-06 15:23 ` James Bottomley
[not found] ` <1467818630.2369.21.camel-d9PhHud1JfjCXq6kfMZ53/egYHeGw8Jk@public.gmane.org>
2016-07-06 16:35 ` Eric W. Biederman
2016-07-06 16:35 ` Eric W. Biederman
2016-07-04 16:27 ` Eric W. Biederman
[not found] ` <87ziq03qnj.fsf-JOvCrm2gF+uungPnsOpG7nhyD016LWXt@public.gmane.org>
2016-07-02 17:20 ` [PATCH review 01/11] fs: Refuse uid/gid changes which don't map into s_user_ns Eric W. Biederman
2016-07-04 8:52 ` [PATCH review 0/11] General unprivileged mount support Jan Kara
2016-07-06 13:44 ` Andy Lutomirski
2016-07-06 13:44 ` Andy Lutomirski
2016-07-06 13:44 ` Andy Lutomirski
[not found] ` <CALCETrVof174gPCZnD2Z-RMjR-P=NcA0mYCU9ki6=o9hpFL-BA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-07-06 15:21 ` Eric W. Biederman
2016-07-06 15:21 ` Eric W. Biederman
2016-07-06 14:01 ` Andy Lutomirski
2016-07-06 14:01 ` Andy Lutomirski
2016-07-06 14:01 ` Andy Lutomirski
2016-07-06 15:19 ` Eric W. Biederman
2016-07-06 15:19 ` Eric W. Biederman
2016-07-06 18:10 ` [PATCH review 0/12] General unprivileged mount support v2 Eric W. Biederman
2016-07-06 18:10 ` Eric W. Biederman
[not found] ` <874m82bptc.fsf-JOvCrm2gF+uungPnsOpG7nhyD016LWXt@public.gmane.org>
2016-07-06 18:12 ` [PATCH review 01/12] fs: Refuse uid/gid changes which don't map into s_user_ns Eric W. Biederman
2016-07-06 18:12 ` Eric W. Biederman
[not found] ` <20160706181212.16267-1-ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2016-07-06 18:12 ` [PATCH review 02/12] userns: Handle -1 in k[ug]id_has_mapping when !CONFIG_USER_NS Eric W. Biederman
2016-07-06 18:12 ` [PATCH review 03/12] vfs: Verify acls are valid within superblock's s_user_ns Eric W. Biederman
2016-07-06 18:12 ` [PATCH review 04/12] fs: Check for invalid i_uid in may_follow_link() Eric W. Biederman
2016-07-06 18:12 ` [PATCH review 05/12] cred: Reject inodes with invalid ids in set_create_file_as() Eric W. Biederman
2016-07-06 18:12 ` [PATCH review 06/12] vfs: Don't modify inodes with a uid or gid unknown to the vfs Eric W. Biederman
2016-07-06 18:12 ` Eric W. Biederman
2016-07-06 18:12 ` Eric W. Biederman
2016-07-06 18:12 ` [PATCH review 07/12] vfs: Don't create " Eric W. Biederman
2016-07-06 18:12 ` Eric W. Biederman
2016-07-06 18:12 ` Eric W. Biederman
2016-07-06 18:12 ` [PATCH review 08/12] quota: Ensure qids map to the filesystem Eric W. Biederman
2016-07-06 18:12 ` [PATCH review 09/12] quota: Handle quota data stored in s_user_ns in quota_setxquota Eric W. Biederman
2016-07-06 18:12 ` [PATCH review 10/12] dquot: For now explicitly don't support filesystems outside of init_user_ns Eric W. Biederman
2016-07-06 18:12 ` Eric W. Biederman
2016-07-06 18:12 ` Eric W. Biederman
[not found] ` <20160706181212.16267-10-ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2016-07-11 10:09 ` Jan Kara
2016-07-11 10:09 ` Jan Kara
2016-07-06 18:12 ` [PATCH review 11/12] evm: Translate user/group ids relative to s_user_ns when computing HMAC Eric W. Biederman
2016-07-06 18:12 ` Eric W. Biederman
2016-07-06 18:12 ` Eric W. Biederman
2016-07-06 18:12 ` [PATCH review 12/12] fs: Update i_[ug]id_(read|write) to translate relative to s_user_ns Eric W. Biederman
2016-07-06 18:12 ` [PATCH review 02/12] userns: Handle -1 in k[ug]id_has_mapping when !CONFIG_USER_NS Eric W. Biederman
2016-07-06 18:12 ` [PATCH review 03/12] vfs: Verify acls are valid within superblock's s_user_ns Eric W. Biederman
2016-07-06 18:12 ` [PATCH review 04/12] fs: Check for invalid i_uid in may_follow_link() Eric W. Biederman
2016-07-06 18:12 ` [PATCH review 05/12] cred: Reject inodes with invalid ids in set_create_file_as() Eric W. Biederman
2016-07-06 18:12 ` [PATCH review 08/12] quota: Ensure qids map to the filesystem Eric W. Biederman
[not found] ` <20160706181212.16267-8-ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2016-07-11 10:14 ` Jan Kara
2016-07-11 10:14 ` Jan Kara
[not found] ` <20160711101424.GH12410-4I4JzKEfoa/jFM9bn6wA6Q@public.gmane.org>
2016-07-11 18:12 ` Eric W. Biederman
2016-07-11 18:12 ` Eric W. Biederman
2016-07-11 18:12 ` Eric W. Biederman
[not found] ` <878tx8dowu.fsf-JOvCrm2gF+uungPnsOpG7nhyD016LWXt@public.gmane.org>
2016-07-13 1:34 ` Dave Chinner
2016-07-13 1:34 ` Dave Chinner
2016-07-13 3:45 ` Dave Chinner
2016-07-13 3:45 ` Dave Chinner
2016-07-13 5:43 ` Jann Horn
2016-07-13 5:43 ` Jann Horn
[not found] ` <20160713054358.GB28635-J1fxOzX/cBvk1uMJSBkQmQ@public.gmane.org>
2016-07-14 17:03 ` Eric W. Biederman
2016-07-14 17:03 ` Eric W. Biederman
2016-07-06 18:12 ` [PATCH review 09/12] quota: Handle quota data stored in s_user_ns in quota_setxquota Eric W. Biederman
2016-07-06 18:12 ` [PATCH review 12/12] fs: Update i_[ug]id_(read|write) to translate relative to s_user_ns Eric W. Biederman
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=87d1msumhy.fsf@x220.int.ebiederm.org \
--to=ebiederm@xmission.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=containers@lists.linux-foundation.org \
--cc=jack@suse.cz \
--cc=jannh@google.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mtk.manpages@gmail.com \
--cc=seth.forshee@canonical.com \
--cc=tixxdz@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.