public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Eric W. Biederman" <ebiederm@xmission.com>
To: David Laight <David.Laight@ACULAB.COM>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Al Viro <viro@zeniv.linux.org.uk>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"Serge E. Hallyn" <serge@hallyn.com>
Subject: Re: [CFT][PATCH] proc: Update /proc/net to point at the accessing threads network namespace
Date: Fri, 30 Sep 2022 11:17:29 -0500	[thread overview]
Message-ID: <87a66g25wm.fsf@email.froward.int.ebiederm.org> (raw)
In-Reply-To: <ea14288676b045c29960651a649d66b9@AcuMS.aculab.com> (David Laight's message of "Fri, 30 Sep 2022 09:30:41 +0000")

David Laight <David.Laight@ACULAB.COM> writes:

> From: Eric W. Biederman
>> Sent: 29 September 2022 23:48
>> 
>> Since common apparmor policies don't allow access /proc/tgid/task/tid/net
>> point the code at /proc/tid/net instead.
>> 
>> Link: https://lkml.kernel.org/r/dacfc18d6667421d97127451eafe4f29@AcuMS.aculab.com
>> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
>> ---
>> 
>> I have only compile tested this.  All of the boiler plate is a copy of
>> /proc/self and /proc/thread-self, so it should work.
>> 
>> Can David or someone who cares and has access to the limited apparmor
>> configurations could test this to make certain this works?
>
> It works with a minor 'cut & paste' fixup.
> (Not nested inside a program that changes namespaces.)

Were there any apparmor problems?  I just want to confirm that is what
you tested.

Assuming not this patch looks like it reveals a solution to this
issue.

> Although if it is reasonable for /proc/net -> /proc/tid/net
> why not just make /proc/thread-self -> /proc/tid
> Then /proc/net can just be thread-self/net

There are minor differences between the process directories that
tend to report process wide information and task directories that
only report some of the same information per-task.  So in general
thread-self makes much more sense pointing to a per-task directory.

The hidden /proc/tid/ directories use the per process code to generate
themselves.  The difference is that they assume the tid is the leading
thread instead of the other process.  Those directories are all a bit of
a scrambled mess.  I was suspecting the other day we might be able to
fix gdb and make them go away entirely in a decade or so.

So I don't think it makes sense in general to point /proc/thread-self at
the hidden per /proc/tid/ directories.

> I have wondered if the namespace lookup could be done as a 'special'
> directory lookup for "net" rather that changing everything when the
> namespace is changed.
> I can imagine scenarios where a thread needs to keep changing
> between two namespaces, at the moment I suspect that is rather
> more expensive than a lookup and changing the reference counts.

You can always open the net directories once, and then change as
an open directory will not change between namespaces.

> Notwithstanding the apparmor issues, /proc/net could actuall be
> a symlink to (say) /proc/net_namespaces/namespace_name with
> readlink returning the name based on the threads actual namespace.

There really aren't good names for namespaces at the kernel level.  As
one of their use cases is to make process migration possible between
machines.  So any kernel level name would need to be migrated as well.
So those kernel level names would need a name in another namespace,
or an extra namespace would have to be created for those names.

> I've also had problems with accessing /sys/class/net for multiple
> namespaces within the same thread (think of a system monitor process).
> The simplest solution is to start the program with:
> 	ip netne exec namespace program 3</sys/class/net
> and the use openat(3, ...) to read items in the 'init' namespace.
>
> FWIW I'm pretty sure there a sequence involving unshare() that
> can get you out of a chroot - but I've not found it yet.

Out of a chroot is essentially just:
	chdir("/");
        chroot("/somedir");
        chdir("../../../../../../../../../../../../../../../..");
Out of most namespaces except the pid and user namespace is
just chns.

You can't get out of the pid namespace as you can't change your pid.

Not being able to escape a user namespace is what makes it impossible to
confuse a process and gain privileges through a privilege gaining exec.

Eric

  reply	other threads:[~2022-09-30 16:18 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-29 15:22 [PATCH 3/4] proc: Point /proc/net at /proc/thread-self/net instead of /proc/self/net David Laight
2022-09-29 18:21 ` Linus Torvalds
2022-09-29 18:50   ` Al Viro
2022-09-29 19:00     ` Al Viro
2022-09-29 19:05       ` Linus Torvalds
2022-09-29 19:34         ` Al Viro
2022-09-29 21:13           ` Linus Torvalds
2022-09-29 21:21             ` Al Viro
2022-09-29 21:27               ` Al Viro
2022-09-29 21:31                 ` Linus Torvalds
2022-09-29 21:15           ` Al Viro
2022-09-29 21:29             ` Linus Torvalds
2022-09-29 22:14               ` Eric W. Biederman
2022-09-29 22:48                 ` [CFT][PATCH] proc: Update /proc/net to point at the accessing threads network namespace Eric W. Biederman
2022-09-29 23:38                   ` Al Viro
2022-09-30  3:19                   ` kernel test robot
2022-09-30  6:07                   ` kernel test robot
2022-09-30  9:30                   ` David Laight
2022-09-30 16:17                     ` Eric W. Biederman [this message]
2022-09-30 21:28                       ` David Laight
2022-10-01 23:11                         ` Al Viro
2022-10-03  9:36                           ` David Laight
2022-10-03 14:03                             ` Al Viro
2022-10-03 17:07                         ` Eric W. Biederman
2022-10-03 18:49                           ` Al Viro
2022-10-04  8:53                           ` David Laight
2022-10-05 13:10                   ` [proc] 5336f1902b: BUG:KASAN:global-out-of-bounds_in_memchr kernel test robot
2022-09-29 19:00     ` [PATCH 3/4] proc: Point /proc/net at /proc/thread-self/net instead of /proc/self/net Linus Torvalds
  -- strict thread matches above, loose matches on Subject: below --
2022-09-30 14:01 [CFT][PATCH] proc: Update /proc/net to point at the accessing threads network namespace Alexey Dobriyan

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=87a66g25wm.fsf@email.froward.int.ebiederm.org \
    --to=ebiederm@xmission.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=serge@hallyn.com \
    --cc=torvalds@linux-foundation.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