From: ebiederm@xmission.com (Eric W. Biederman)
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>,
Al Viro <viro@zeniv.linux.org.uk>,
lkml <linux-kernel@vger.kernel.org>,
netdev <netdev@vger.kernel.org>
Subject: Re: [PATCH] net: make net namespace sysctls belong to container's owner
Date: Mon, 08 Aug 2016 16:48:40 -0500 [thread overview]
Message-ID: <87eg5zlyo7.fsf@x220.int.ebiederm.org> (raw)
In-Reply-To: <CAKdAkRRq8dRR5=H+R2HWhwFfgXuVxiu_mbekZuGPkaJzHPYLuw@mail.gmail.com> (Dmitry Torokhov's message of "Mon, 8 Aug 2016 14:54:45 -0700")
Dmitry Torokhov <dmitry.torokhov@gmail.com> writes:
> On Mon, Aug 8, 2016 at 2:08 PM, Eric W. Biederman <ebiederm@xmission.com> wrote:
>> Dmitry Torokhov <dmitry.torokhov@gmail.com> writes:
>>
>>> If net namespace is attached to a user namespace let's make container's
>>> root owner of sysctls affecting said network namespace instead of global
>>> root.
>>>
>>> This also allows us to clean up net_ctl_permissions() because we do not
>>> need to fudge permissions anymore for the container's owner since it now
>>> owns the objects in question.
>>
>> Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>
>>
>> Overall this seems reasonable. However I am not a fan of your error
>> handling.
>>
>>> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
>>> ---
>>>
>>> This helps when running Android CTS in a container, but I think it makes
>>> sense regardless.
>>
>>> +static void net_ctl_set_ownership(struct ctl_table_header *head,
>>> + struct ctl_table *table,
>>> + kuid_t *uid, kgid_t *gid)
>>> +{
>>> + struct net *net = container_of(head->set, struct net, sysctls);
>>> +
>>> + *uid = make_kuid(net->user_ns, 0);
>>> + if (!uid_valid(*uid))
>>> + *uid = GLOBAL_ROOT_UID;
>>> +
>>> + *gid = make_kgid(net->user_ns, 0);
>>> + if (!gid_valid(*gid))
>>> + *gid = GLOBAL_ROOT_GID;
>>
>> This code should eiter be:
>> *uid = make_kuid(net->user_ns, 0);
>> *gid = make_kgid(net->user_ns, 0);
>>
>> Or it should be:
>> tmp_uid = make_kuid(net->user_ns, 0);
>> if (uid_valid(tmp_uid))
>> *uid = tmp_uid;
>>
>> tmp_gid = make_kgid(net->user_ns, 0);
>> if (gid_valid(tmp_gid))
>> *gid = tmp_gid;
>>
>> It is just very fragile to assume to know what uid and gid
>> would be if this code fails.
>>
>> As of v4.8-rc1 INVALID_UID and INVALID_GID can be set in inode->i_uid
>> and inode->i_gid without causing horrible vfs confusion (making the
>> first option viable), but I expect with the mention of Android you want
>> to backport this so I will ask that you ask to implement the error
>> handling that doesn't assume you know better than the generic code.
>>
>> If you don't have a better value to set something to it really should be
>> left alone.
>
> OK, fair enough. I will adopt the 2nd option and will resubmit. I need
> to also test without net namespaces support (my other change blows up
> because we are getting half-initialized init_net structure when
> namespaces are disabled).
No rush. I will be out on vacation for the next couple of weeks.
Eric
prev parent reply other threads:[~2016-08-08 22:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-02 23:19 [PATCH] net: make net namespace sysctls belong to container's owner Dmitry Torokhov
2016-08-08 21:08 ` Eric W. Biederman
2016-08-08 21:54 ` Dmitry Torokhov
2016-08-08 21:48 ` Eric W. Biederman [this message]
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=87eg5zlyo7.fsf@x220.int.ebiederm.org \
--to=ebiederm@xmission.com \
--cc=davem@davemloft.net \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--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