All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sunrpc: Use current_real_cred() when looking up rpc credentials
@ 2016-12-15 17:13 Seth Forshee
  2016-12-15 23:01 ` Trond Myklebust
  0 siblings, 1 reply; 19+ messages in thread
From: Seth Forshee @ 2016-12-15 17:13 UTC (permalink / raw)
  To: Trond Myklebust, Anna Schumaker, J. Bruce Fields
  Cc: Eric W . Biederman, linux-nfs

Since 4.8 follow_automount() overrides the credentials with
&init_cred before calling d_automount(). When
rpcauth_lookupcred() is called in this context it is now using
fs[ug]id from the override creds instead of from the user's
creds, which can cause authentication to fail. To fix this, take
the ids from current_real_cred() instead.

Cc: stable@vger.kernel.org # v4.8+
CC: Eric W. Biederman <ebiederm@xmission.com>
Fixes: aeaa4a79ff6a ("fs: Call d_automount with the filesystems creds")
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
---
 net/sunrpc/auth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
index 2bff63a73cf8..e6197b2bda86 100644
--- a/net/sunrpc/auth.c
+++ b/net/sunrpc/auth.c
@@ -622,7 +622,7 @@ rpcauth_lookupcred(struct rpc_auth *auth, int flags)
 {
 	struct auth_cred acred;
 	struct rpc_cred *ret;
-	const struct cred *cred = current_cred();
+	const struct cred *cred = current_real_cred();
 
 	dprintk("RPC:       looking up %s cred\n",
 		auth->au_ops->au_name);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH] sunrpc: Use current_real_cred() when looking up rpc credentials
  2016-12-15 17:13 [PATCH] sunrpc: Use current_real_cred() when looking up rpc credentials Seth Forshee
@ 2016-12-15 23:01 ` Trond Myklebust
  2016-12-16 13:06   ` Seth Forshee
  0 siblings, 1 reply; 19+ messages in thread
From: Trond Myklebust @ 2016-12-15 23:01 UTC (permalink / raw)
  To: bfields, anna.schumaker, seth.forshee; +Cc: ebiederm, linux-nfs

T24gVGh1LCAyMDE2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mY2
M2E3M2NmOC4uZTYxOTdiMmJkYTg2IDEwMDY0NA0KPiAtLS0gYS9uZXQvc3VucnBjL2F1dGguYw0K
PiArKysgYi9uZXQvc3VucnBjL2F1dGguYw0KPiBAQCAtNjIyLDcgKzYyMiw3IEBAIHJwY2F1dGhf
bG9va3VwY3JlZChzdHJ1Y3QgcnBjX2F1dGggKmF1dGgsIGludA0KPiBmbGFncykNCj4gwqB7DQo+
IMKgCXN0cnVjdCBhdXRoX2NyZWQgYWNyZWQ7DQo+IMKgCXN0cnVjdCBycGNfY3JlZCAqcmV0Ow0K
PiAtCWNvbnN0IHN0cnVjdCBjcmVkICpjcmVkID0gY3VycmVudF9jcmVkKCk7DQo+ICsJY29uc3Qg
c3RydWN0IGNyZWQgKmNyZWQgPSBjdXJyZW50X3JlYWxfY3JlZCgpOw0KPiDCoA0KPiDCoAlkcHJp
bnRrKCJSUEM6wqDCoMKgwqDCoMKgwqBsb29raW5nIHVwICVzIGNyZWRcbiIsDQo+IMKgCQlhdXRo
LT5hdV9vcHMtPmF1X25hbWUpOw0KDQpBbW9uZyBvdGhlciB0aGluZ3MsIHRoaXMgd2lsbCBicmVh
ayB0aGUgYWNjZXNzKCkgc3lzY2FsbC4gSXQncw0KY29tcGxldGVseSB0aGUgd3JvbmcgbGV2ZWwg
aW4gd2hpY2ggdG8gb3ZlcnJpZGUgY3JlZGVudGlhbHMuDQoNCi0tIA0KVHJvbmQgTXlrbGVidXN0
DQpMaW51eCBORlMgY2xpZW50IG1haW50YWluZXIsIFByaW1hcnlEYXRhDQp0cm9uZC5teWtsZWJ1
c3RAcHJpbWFyeWRhdGEuY29tDQo=


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] sunrpc: Use current_real_cred() when looking up rpc credentials
  2016-12-15 23:01 ` Trond Myklebust
@ 2016-12-16 13:06   ` Seth Forshee
  2017-01-10 14:55     ` Seth Forshee
  0 siblings, 1 reply; 19+ messages in thread
From: Seth Forshee @ 2016-12-16 13:06 UTC (permalink / raw)
  To: Trond Myklebust; +Cc: bfields, anna.schumaker, ebiederm, linux-nfs

On Thu, Dec 15, 2016 at 11:01:41PM +0000, Trond Myklebust wrote:
> On Thu, 2016-12-15 at 11:13 -0600, Seth Forshee wrote:
> > Since 4.8 follow_automount() overrides the credentials with
> > &init_cred before calling d_automount(). When
> > rpcauth_lookupcred() is called in this context it is now using
> > fs[ug]id from the override creds instead of from the user's
> > creds, which can cause authentication to fail. To fix this, take
> > the ids from current_real_cred() instead.
> > 
> > Cc: stable@vger.kernel.org # v4.8+
> > CC: Eric W. Biederman <ebiederm@xmission.com>
> > Fixes: aeaa4a79ff6a ("fs: Call d_automount with the filesystems
> > creds")
> > Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
> > ---
> >  net/sunrpc/auth.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
> > index 2bff63a73cf8..e6197b2bda86 100644
> > --- a/net/sunrpc/auth.c
> > +++ b/net/sunrpc/auth.c
> > @@ -622,7 +622,7 @@ rpcauth_lookupcred(struct rpc_auth *auth, int
> > flags)
> >  {
> >  	struct auth_cred acred;
> >  	struct rpc_cred *ret;
> > -	const struct cred *cred = current_cred();
> > +	const struct cred *cred = current_real_cred();
> >  
> >  	dprintk("RPC:       looking up %s cred\n",
> >  		auth->au_ops->au_name);
> 
> Among other things, this will break the access() syscall.

Okay, I see that now.

> It's completely the wrong level in which to override credentials.

The reason for it is that sget() now has a capability check which will
fail on automount if current doesn't have CAP_SYS_ADMIN. So what are the
alternatives? A few ideas:

 - Instead of using a completely differnet set of creds, we could copy
   the current creds and raise CAP_SYS_ADMIN. This won't work if
   curreent is in a different user ns however.

 - Filesystems could get around the capability check by using
   sget_userns() during automount.

 - We could add a mount flag, say MS_AUTOMOUNT, and skip the capability
   check if that is set.

Any opinions or other ideas?

Thanks,
Seth

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] sunrpc: Use current_real_cred() when looking up rpc credentials
  2016-12-16 13:06   ` Seth Forshee
@ 2017-01-10 14:55     ` Seth Forshee
  2017-01-11  0:21       ` Eric W. Biederman
  0 siblings, 1 reply; 19+ messages in thread
From: Seth Forshee @ 2017-01-10 14:55 UTC (permalink / raw)
  To: Trond Myklebust, ebiederm; +Cc: bfields, anna.schumaker, linux-nfs

On Fri, Dec 16, 2016 at 07:06:09AM -0600, Seth Forshee wrote:
> On Thu, Dec 15, 2016 at 11:01:41PM +0000, Trond Myklebust wrote:
> > On Thu, 2016-12-15 at 11:13 -0600, Seth Forshee wrote:
> > > Since 4.8 follow_automount() overrides the credentials with
> > > &init_cred before calling d_automount(). When
> > > rpcauth_lookupcred() is called in this context it is now using
> > > fs[ug]id from the override creds instead of from the user's
> > > creds, which can cause authentication to fail. To fix this, take
> > > the ids from current_real_cred() instead.
> > > 
> > > Cc: stable@vger.kernel.org # v4.8+
> > > CC: Eric W. Biederman <ebiederm@xmission.com>
> > > Fixes: aeaa4a79ff6a ("fs: Call d_automount with the filesystems
> > > creds")
> > > Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
> > > ---
> > >  net/sunrpc/auth.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
> > > index 2bff63a73cf8..e6197b2bda86 100644
> > > --- a/net/sunrpc/auth.c
> > > +++ b/net/sunrpc/auth.c
> > > @@ -622,7 +622,7 @@ rpcauth_lookupcred(struct rpc_auth *auth, int
> > > flags)
> > >  {
> > >  	struct auth_cred acred;
> > >  	struct rpc_cred *ret;
> > > -	const struct cred *cred = current_cred();
> > > +	const struct cred *cred = current_real_cred();
> > >  
> > >  	dprintk("RPC:       looking up %s cred\n",
> > >  		auth->au_ops->au_name);
> > 
> > Among other things, this will break the access() syscall.
> 
> Okay, I see that now.
> 
> > It's completely the wrong level in which to override credentials.
> 
> The reason for it is that sget() now has a capability check which will
> fail on automount if current doesn't have CAP_SYS_ADMIN. So what are the
> alternatives? A few ideas:
> 
>  - Instead of using a completely differnet set of creds, we could copy
>    the current creds and raise CAP_SYS_ADMIN. This won't work if
>    curreent is in a different user ns however.
> 
>  - Filesystems could get around the capability check by using
>    sget_userns() during automount.
> 
>  - We could add a mount flag, say MS_AUTOMOUNT, and skip the capability
>    check if that is set.
> 
> Any opinions or other ideas?

I haven't seen any responses, possibly just got lost in the shuffle
during the holidays (I know it slipped my mind for a while).

Eric, what do you think about the last option above? From what I can see
looking up rpc credentials just isn't going to work with current_cred
overridden as we're doing for automount.

Thanks,
Seth

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] sunrpc: Use current_real_cred() when looking up rpc credentials
  2017-01-10 14:55     ` Seth Forshee
@ 2017-01-11  0:21       ` Eric W. Biederman
  2017-01-24 15:17         ` Seth Forshee
  0 siblings, 1 reply; 19+ messages in thread
From: Eric W. Biederman @ 2017-01-11  0:21 UTC (permalink / raw)
  To: Seth Forshee; +Cc: Trond Myklebust, bfields, anna.schumaker, linux-nfs

Seth Forshee <seth.forshee@canonical.com> writes:

> On Fri, Dec 16, 2016 at 07:06:09AM -0600, Seth Forshee wrote:
>> On Thu, Dec 15, 2016 at 11:01:41PM +0000, Trond Myklebust wrote:
>> > On Thu, 2016-12-15 at 11:13 -0600, Seth Forshee wrote:
>> > > Since 4.8 follow_automount() overrides the credentials with
>> > > &init_cred before calling d_automount(). When
>> > > rpcauth_lookupcred() is called in this context it is now using
>> > > fs[ug]id from the override creds instead of from the user's
>> > > creds, which can cause authentication to fail. To fix this, take
>> > > the ids from current_real_cred() instead.
>> > > 
>> > > Cc: stable@vger.kernel.org # v4.8+
>> > > CC: Eric W. Biederman <ebiederm@xmission.com>
>> > > Fixes: aeaa4a79ff6a ("fs: Call d_automount with the filesystems
>> > > creds")
>> > > Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
>> > > ---
>> > >  net/sunrpc/auth.c | 2 +-
>> > >  1 file changed, 1 insertion(+), 1 deletion(-)
>> > > 
>> > > diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
>> > > index 2bff63a73cf8..e6197b2bda86 100644
>> > > --- a/net/sunrpc/auth.c
>> > > +++ b/net/sunrpc/auth.c
>> > > @@ -622,7 +622,7 @@ rpcauth_lookupcred(struct rpc_auth *auth, int
>> > > flags)
>> > >  {
>> > >  	struct auth_cred acred;
>> > >  	struct rpc_cred *ret;
>> > > -	const struct cred *cred = current_cred();
>> > > +	const struct cred *cred = current_real_cred();
>> > >  
>> > >  	dprintk("RPC:       looking up %s cred\n",
>> > >  		auth->au_ops->au_name);
>> > 
>> > Among other things, this will break the access() syscall.
>> 
>> Okay, I see that now.
>> 
>> > It's completely the wrong level in which to override credentials.
>> 
>> The reason for it is that sget() now has a capability check which will
>> fail on automount if current doesn't have CAP_SYS_ADMIN. So what are the
>> alternatives? A few ideas:
>> 
>>  - Instead of using a completely differnet set of creds, we could copy
>>    the current creds and raise CAP_SYS_ADMIN. This won't work if
>>    curreent is in a different user ns however.
>> 
>>  - Filesystems could get around the capability check by using
>>    sget_userns() during automount.
>> 
>>  - We could add a mount flag, say MS_AUTOMOUNT, and skip the capability
>>    check if that is set.
>> 
>> Any opinions or other ideas?
>
> I haven't seen any responses, possibly just got lost in the shuffle
> during the holidays (I know it slipped my mind for a while).
>
> Eric, what do you think about the last option above? From what I can see
> looking up rpc credentials just isn't going to work with current_cred
> overridden as we're doing for automount.

I got as far as there wasn't a correct thing to apply, and I have been
bogged down in enough other things that I haven't gotten back to this
one.

My gut feel is that we propbably want to do a little more reworking on
the autmount path.  But I don't exactly have a concrete proposal for
you at the moment.  I just found another 10 year old bug in the mount
code...

Eric


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] sunrpc: Use current_real_cred() when looking up rpc credentials
  2017-01-11  0:21       ` Eric W. Biederman
@ 2017-01-24 15:17         ` Seth Forshee
  2017-01-24 22:55           ` Eric W. Biederman
  0 siblings, 1 reply; 19+ messages in thread
From: Seth Forshee @ 2017-01-24 15:17 UTC (permalink / raw)
  To: Eric W. Biederman; +Cc: Trond Myklebust, bfields, anna.schumaker, linux-nfs

On Wed, Jan 11, 2017 at 01:21:57PM +1300, Eric W. Biederman wrote:
> Seth Forshee <seth.forshee@canonical.com> writes:
> 
> > On Fri, Dec 16, 2016 at 07:06:09AM -0600, Seth Forshee wrote:
> >> On Thu, Dec 15, 2016 at 11:01:41PM +0000, Trond Myklebust wrote:
> >> > On Thu, 2016-12-15 at 11:13 -0600, Seth Forshee wrote:
> >> > > Since 4.8 follow_automount() overrides the credentials with
> >> > > &init_cred before calling d_automount(). When
> >> > > rpcauth_lookupcred() is called in this context it is now using
> >> > > fs[ug]id from the override creds instead of from the user's
> >> > > creds, which can cause authentication to fail. To fix this, take
> >> > > the ids from current_real_cred() instead.
> >> > > 
> >> > > Cc: stable@vger.kernel.org # v4.8+
> >> > > CC: Eric W. Biederman <ebiederm@xmission.com>
> >> > > Fixes: aeaa4a79ff6a ("fs: Call d_automount with the filesystems
> >> > > creds")
> >> > > Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
> >> > > ---
> >> > >  net/sunrpc/auth.c | 2 +-
> >> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> >> > > 
> >> > > diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
> >> > > index 2bff63a73cf8..e6197b2bda86 100644
> >> > > --- a/net/sunrpc/auth.c
> >> > > +++ b/net/sunrpc/auth.c
> >> > > @@ -622,7 +622,7 @@ rpcauth_lookupcred(struct rpc_auth *auth, int
> >> > > flags)
> >> > >  {
> >> > >  	struct auth_cred acred;
> >> > >  	struct rpc_cred *ret;
> >> > > -	const struct cred *cred = current_cred();
> >> > > +	const struct cred *cred = current_real_cred();
> >> > >  
> >> > >  	dprintk("RPC:       looking up %s cred\n",
> >> > >  		auth->au_ops->au_name);
> >> > 
> >> > Among other things, this will break the access() syscall.
> >> 
> >> Okay, I see that now.
> >> 
> >> > It's completely the wrong level in which to override credentials.
> >> 
> >> The reason for it is that sget() now has a capability check which will
> >> fail on automount if current doesn't have CAP_SYS_ADMIN. So what are the
> >> alternatives? A few ideas:
> >> 
> >>  - Instead of using a completely differnet set of creds, we could copy
> >>    the current creds and raise CAP_SYS_ADMIN. This won't work if
> >>    curreent is in a different user ns however.
> >> 
> >>  - Filesystems could get around the capability check by using
> >>    sget_userns() during automount.
> >> 
> >>  - We could add a mount flag, say MS_AUTOMOUNT, and skip the capability
> >>    check if that is set.
> >> 
> >> Any opinions or other ideas?
> >
> > I haven't seen any responses, possibly just got lost in the shuffle
> > during the holidays (I know it slipped my mind for a while).
> >
> > Eric, what do you think about the last option above? From what I can see
> > looking up rpc credentials just isn't going to work with current_cred
> > overridden as we're doing for automount.
> 
> I got as far as there wasn't a correct thing to apply, and I have been
> bogged down in enough other things that I haven't gotten back to this
> one.
> 
> My gut feel is that we propbably want to do a little more reworking on
> the autmount path.  But I don't exactly have a concrete proposal for
> you at the moment.  I just found another 10 year old bug in the mount
> code...

With automounts we're mounting based on the credentials used when
mounting the parent. That's what your patch "fs: Call d_automount with
the filesystems creds" did, but it's overriding the credentials too
early in the call stack and causing these rpcauth problems.

But I think we should also be setting the submount's s_user_ns to be the
same as the parent's, not to current_user_ns. At that point we'd be
using the same credentials and user ns as when mounting the parent super
block, so we know the capability check would pass (since it passed for
the original mount) and don't really need to do it.

So if we could pass down through the call stack that a given mount
request is an automount from super block s (or at dentry d) then the fix
would be trivial. I don't see any way of passing that information
through currently though, without doing something undesirable like
adding arguments to the mount filesystem op.

Seth

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] sunrpc: Use current_real_cred() when looking up rpc credentials
  2017-01-24 15:17         ` Seth Forshee
@ 2017-01-24 22:55           ` Eric W. Biederman
  2017-01-24 23:28             ` Eric W. Biederman
  0 siblings, 1 reply; 19+ messages in thread
From: Eric W. Biederman @ 2017-01-24 22:55 UTC (permalink / raw)
  To: Seth Forshee; +Cc: Trond Myklebust, bfields, anna.schumaker, linux-nfs

Seth Forshee <seth.forshee@canonical.com> writes:

> On Wed, Jan 11, 2017 at 01:21:57PM +1300, Eric W. Biederman wrote:
>> Seth Forshee <seth.forshee@canonical.com> writes:
>> 
>> > On Fri, Dec 16, 2016 at 07:06:09AM -0600, Seth Forshee wrote:
>> >> On Thu, Dec 15, 2016 at 11:01:41PM +0000, Trond Myklebust wrote:
>> >> > On Thu, 2016-12-15 at 11:13 -0600, Seth Forshee wrote:
>> >> > > Since 4.8 follow_automount() overrides the credentials with
>> >> > > &init_cred before calling d_automount(). When
>> >> > > rpcauth_lookupcred() is called in this context it is now using
>> >> > > fs[ug]id from the override creds instead of from the user's
>> >> > > creds, which can cause authentication to fail. To fix this, take
>> >> > > the ids from current_real_cred() instead.
>> >> > > 
>> >> > > Cc: stable@vger.kernel.org # v4.8+
>> >> > > CC: Eric W. Biederman <ebiederm@xmission.com>
>> >> > > Fixes: aeaa4a79ff6a ("fs: Call d_automount with the filesystems
>> >> > > creds")
>> >> > > Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
>> >> > > ---
>> >> > >  net/sunrpc/auth.c | 2 +-
>> >> > >  1 file changed, 1 insertion(+), 1 deletion(-)
>> >> > > 
>> >> > > diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
>> >> > > index 2bff63a73cf8..e6197b2bda86 100644
>> >> > > --- a/net/sunrpc/auth.c
>> >> > > +++ b/net/sunrpc/auth.c
>> >> > > @@ -622,7 +622,7 @@ rpcauth_lookupcred(struct rpc_auth *auth, int
>> >> > > flags)
>> >> > >  {
>> >> > >  	struct auth_cred acred;
>> >> > >  	struct rpc_cred *ret;
>> >> > > -	const struct cred *cred = current_cred();
>> >> > > +	const struct cred *cred = current_real_cred();
>> >> > >  
>> >> > >  	dprintk("RPC:       looking up %s cred\n",
>> >> > >  		auth->au_ops->au_name);
>> >> > 
>> >> > Among other things, this will break the access() syscall.
>> >> 
>> >> Okay, I see that now.
>> >> 
>> >> > It's completely the wrong level in which to override credentials.
>> >> 
>> >> The reason for it is that sget() now has a capability check which will
>> >> fail on automount if current doesn't have CAP_SYS_ADMIN. So what are the
>> >> alternatives? A few ideas:
>> >> 
>> >>  - Instead of using a completely differnet set of creds, we could copy
>> >>    the current creds and raise CAP_SYS_ADMIN. This won't work if
>> >>    curreent is in a different user ns however.
>> >> 
>> >>  - Filesystems could get around the capability check by using
>> >>    sget_userns() during automount.
>> >> 
>> >>  - We could add a mount flag, say MS_AUTOMOUNT, and skip the capability
>> >>    check if that is set.
>> >> 
>> >> Any opinions or other ideas?
>> >
>> > I haven't seen any responses, possibly just got lost in the shuffle
>> > during the holidays (I know it slipped my mind for a while).
>> >
>> > Eric, what do you think about the last option above? From what I can see
>> > looking up rpc credentials just isn't going to work with current_cred
>> > overridden as we're doing for automount.
>> 
>> I got as far as there wasn't a correct thing to apply, and I have been
>> bogged down in enough other things that I haven't gotten back to this
>> one.
>> 
>> My gut feel is that we propbably want to do a little more reworking on
>> the autmount path.  But I don't exactly have a concrete proposal for
>> you at the moment.  I just found another 10 year old bug in the mount
>> code...
>
> With automounts we're mounting based on the credentials used when
> mounting the parent. That's what your patch "fs: Call d_automount with
> the filesystems creds" did, but it's overriding the credentials too
> early in the call stack and causing these rpcauth problems.
>
> But I think we should also be setting the submount's s_user_ns to be the
> same as the parent's, not to current_user_ns. At that point we'd be
> using the same credentials and user ns as when mounting the parent super
> block, so we know the capability check would pass (since it passed for
> the original mount) and don't really need to do it.

If we special case the submount code that would be fine.  Normal sget
needs to continue to use current_user_ns.

> So if we could pass down through the call stack that a given mount
> request is an automount from super block s (or at dentry d) then the fix
> would be trivial. I don't see any way of passing that information
> through currently though, without doing something undesirable like
> adding arguments to the mount filesystem op.

So here are the pieces I have in my thinking about this.
1) We need to capture the cred of the mounter of the filesystem
   like overlayfs does but in general.  Call it s_cred or possibly
   s_mounter_cred.

   That would allow us to remove the hard coded cred in the automount
   path, and would allow unprivileged mounts to eventually use this
   functionality.

2) Al Viro mentioned to me that it would be very nice if the automount
   could coud run in a separate stack because this is one place where
   the stack can get very deep in the vfs.

My gut feel is that solving for those two constraints: the code running
in a separate thread, and the capturing not just s_user_ns but the cred
of the mounter should give us enough constraints to figure out how to
structure the code for long term maintenance.

I especially think the part about using the mounters creds will likely
solve the sunrpc problem.  I could of course be wrong but using the
creds of the process that happened to walk across the mount point seems
completely the wrong thing.  In general it feels wrong to expose which
user triggered the automount to me.  As that means the semantics can
very per user.

Now when we looked at autofs the semantics were in fact varying per
user (ugh).  So NFS may have the same legacy requirements.

But as a general maintainability principle I don't like vfs state that
varies depending upon the user.

Eric


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] sunrpc: Use current_real_cred() when looking up rpc credentials
  2017-01-24 22:55           ` Eric W. Biederman
@ 2017-01-24 23:28             ` Eric W. Biederman
  2017-01-24 23:46               ` Trond Myklebust
  0 siblings, 1 reply; 19+ messages in thread
From: Eric W. Biederman @ 2017-01-24 23:28 UTC (permalink / raw)
  To: Seth Forshee; +Cc: Trond Myklebust, bfields, anna.schumaker, linux-nfs


With respect to nfs and automounts.

Does NFS have different automount behavior based on the user
performing the automount?

If NFS does not have different automount behavior depending on the user
we just use the creds of the original mounter of NFS?

If NFS does have different automount behavior depending on the user
(ouch!) we need to go through the call path and see where it makes
sense to over ride things and where it does not.



Seth the fundamental problem with your patch was that you were patching
a location that is used for more just mounts.

I am strongly wishing that we could just change follow_automount from:


	old_cred = override_creds(&init_cred);
	mnt = path->dentry->d_op->d_automount(path);
	revert_creds(old_cred);

to:

	old_cred = override_creds(path->mnt->mnt_sb->s_cred);
	mnt = path->dentry->d_op->d_automount(path);
	revert_creds(old_cred);

And all will be well with nfs.  That does remain possible.

But looking at the code path you touched it seems to lookup the cred
based purely on the local uid, gid, and groups.  Which suggests to
me that even the original mounters creds may not be enough :(

At which point I am not certain of the solution.  But I fear that like
autofs NFS actually cares which user is transition the magic mountpoint,
and may return different data depending on who transitions the
mountpoint first.  Ick!  Nasty Nasty Ick!

Eric

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] sunrpc: Use current_real_cred() when looking up rpc credentials
  2017-01-24 23:28             ` Eric W. Biederman
@ 2017-01-24 23:46               ` Trond Myklebust
  2017-01-24 23:56                 ` Eric W. Biederman
  0 siblings, 1 reply; 19+ messages in thread
From: Trond Myklebust @ 2017-01-24 23:46 UTC (permalink / raw)
  To: ebiederm, seth.forshee; +Cc: bfields, anna.schumaker, linux-nfs

T24gV2VkLCAyMDE3LTAxLTI1IGF0IDEyOjI4ICsxMzAwLCBFcmljIFcuIEJpZWRlcm1hbiB3cm90
ZToNCj4gV2l0aCByZXNwZWN0IHRvIG5mcyBhbmQgYXV0b21vdW50cy4NCj4gDQo+IERvZXMgTkZT
IGhhdmUgZGlmZmVyZW50IGF1dG9tb3VudCBiZWhhdmlvciBiYXNlZCBvbiB0aGUgdXNlcg0KPiBw
ZXJmb3JtaW5nIHRoZSBhdXRvbW91bnQ/DQo+IA0KPiBJZiBORlMgZG9lcyBub3QgaGF2ZSBkaWZm
ZXJlbnQgYXV0b21vdW50IGJlaGF2aW9yIGRlcGVuZGluZyBvbiB0aGUNCj4gdXNlcg0KPiB3ZSBq
dXN0IHVzZSB0aGUgY3JlZHMgb2YgdGhlIG9yaWdpbmFsIG1vdW50ZXIgb2YgTkZTPw0KPiANCj4g
SWYgTkZTIGRvZXMgaGF2ZSBkaWZmZXJlbnQgYXV0b21vdW50IGJlaGF2aW9yIGRlcGVuZGluZyBv
biB0aGUgdXNlcg0KPiAob3VjaCEpIHdlIG5lZWQgdG8gZ28gdGhyb3VnaCB0aGUgY2FsbCBwYXRo
IGFuZCBzZWUgd2hlcmUgaXQgbWFrZXMNCj4gc2Vuc2UgdG8gb3ZlciByaWRlIHRoaW5ncyBhbmQg
d2hlcmUgaXQgZG9lcyBub3QuDQoNClRoZSByZWFzb24gd2h5IHRoZSBORlMgY2xpZW50IGNyZWF0
ZXMgYSBtb3VudHBvaW50IGlzIGJlY2F1c2Ugb24NCm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lcmVudCBkYXRhIGRl
cGVuZGluZyBvbiB3aG8gdHJhbnNpdGlvbnMgdGhlDQo+IG1vdW50cG9pbnQgZmlyc3QuwqDCoElj
ayHCoMKgTmFzdHkgTmFzdHkgSWNrIQ0KPiANCg0KVGhlIHNlY3VyaXR5IG1vZGVsIGlzIHRoZSBz
YW1lIGFzIHRoYXQgb2YgYW4gb3JkaW5hcnkgZGlyZWN0b3J5LiBUaGUNCm9ubHkgZGlmZmVyZW5j
ZSBpcyB0aGF0IHdlIGNyZWF0ZSBhIG5ldyBzdXBlcmJsb2NrLiBXaHkgaXMgdGhhdCAiSWNrIj8N
Cg0KLS0gDQpUcm9uZCBNeWtsZWJ1c3QNCkxpbnV4IE5GUyBjbGllbnQgbWFpbnRhaW5lciwgUHJp
bWFyeURhdGENCnRyb25kLm15a2xlYnVzdEBwcmltYXJ5ZGF0YS5jb20NCg==


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] sunrpc: Use current_real_cred() when looking up rpc credentials
  2017-01-24 23:46               ` Trond Myklebust
@ 2017-01-24 23:56                 ` Eric W. Biederman
  2017-01-25  0:14                   ` Trond Myklebust
  0 siblings, 1 reply; 19+ messages in thread
From: Eric W. Biederman @ 2017-01-24 23:56 UTC (permalink / raw)
  To: Trond Myklebust; +Cc: seth.forshee, bfields, anna.schumaker, linux-nfs

Trond Myklebust <trondmy@primarydata.com> writes:

> On Wed, 2017-01-25 at 12:28 +1300, Eric W. Biederman wrote:
>> With respect to nfs and automounts.
>> 
>> Does NFS have different automount behavior based on the user
>> performing the automount?
>> 
>> If NFS does not have different automount behavior depending on the
>> user
>> we just use the creds of the original mounter of NFS?
>> 
>> If NFS does have different automount behavior depending on the user
>> (ouch!) we need to go through the call path and see where it makes
>> sense to over ride things and where it does not.
>
> The reason why the NFS client creates a mountpoint is because on
> entering a directory, it detects that there is either a similar
> mountpoint on the server, or there is a referral (which acts sort of
> like a symlink, except it points to a path on one or more different NFS
> servers).
> Without that mountpoint, most things would work, but the user would end
> up seeing nasty non-posix features like duplicate inode numbers.
>
> We do not want to use any creds other than user creds here, because as
> far as the security model is concerned, the process is just crossing
> into an existing directory.

But sget needs different creds.

Because the user who authorizes the mounting of the filesystem is
different than the user who is crossing into the new filesystem.

The local system now cares about that distinction even if the nfs server
does not.

>> Seth the fundamental problem with your patch was that you were
>> patching
>> a location that is used for more just mounts.
>> 
>> I am strongly wishing that we could just change follow_automount
>> from:
>> 
>> 
>> 	old_cred = override_creds(&init_cred);
>> 	mnt = path->dentry->d_op->d_automount(path);
>> 	revert_creds(old_cred);
>> 
>> to:
>> 
>> 	old_cred = override_creds(path->mnt->mnt_sb->s_cred);
>> 	mnt = path->dentry->d_op->d_automount(path);
>> 	revert_creds(old_cred);
>> 
>> And all will be well with nfs.  That does remain possible.
>
> No. That would break permissions checking. See above.

Then we need to look much harder at the permission checking
model of d_automount because we need to permission check against
both sets of creds.

>> But looking at the code path you touched it seems to lookup the cred
>> based purely on the local uid, gid, and groups.  Which suggests to
>> me that even the original mounters creds may not be enough :(
>> 
>> At which point I am not certain of the solution.  But I fear that
>> like
>> autofs NFS actually cares which user is transition the magic
>> mountpoint,
>> and may return different data depending on who transitions the
>> mountpoint first.  Ick!  Nasty Nasty Ick!
>> 
>
> The security model is the same as that of an ordinary directory. The
> only difference is that we create a new superblock. Why is that "Ick"?

The Ick is if the superblock that is created depends on the user
crossing the mountpoint.

AKA Do we get a different mountpoint if user A triggers the automount
vs user B triggering the automount?

If the problem is just root squash and not letting root trigger the
automount it is much less ick.  Weird but not ick.

Eric


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] sunrpc: Use current_real_cred() when looking up rpc credentials
  2017-01-24 23:56                 ` Eric W. Biederman
@ 2017-01-25  0:14                   ` Trond Myklebust
  2017-01-25 14:52                     ` Seth Forshee
  0 siblings, 1 reply; 19+ messages in thread
From: Trond Myklebust @ 2017-01-25  0:14 UTC (permalink / raw)
  To: Steve French, ebiederm, dhowells
  Cc: bfields, an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kIGJlIHRoZSBzYW1lLg0KDQo+
IElmIHRoZSBwcm9ibGVtIGlzIGp1c3Qgcm9vdCBzcXVhc2ggYW5kIG5vdCBsZXR0aW5nIHJvb3Qg
dHJpZ2dlciB0aGUNCj4gYXV0b21vdW50IGl0IGlzIG11Y2ggbGVzcyBpY2suwqDCoFdlaXJkIGJ1
dCBub3QgaWNrLg0KDQpOb3QganVzdCByb290IHNxdWFzaCwgYnV0IGdlbmVyYWwgcGVybWlzc2lv
bnMgY2hlY2tpbmcuIFdlIGRvbid0IHdhbnQNCnRvIGdpdmUgdXNlciBCIHJvb3QgcHJpdmlsZWdl
cyBhbGxvd2luZyBjcm9zc2luZyBpbnRvIGEgZGlyZWN0b3J5IHRvDQp3aGljaCBzL2hlIHdvdWxk
IG9yZGluYXJpbHkgaGF2ZSBubyByaWdodHMgZWl0aGVyLg0KDQotLSANClRyb25kIE15a2xlYnVz
dA0KTGludXggTkZTIGNsaWVudCBtYWludGFpbmVyLCBQcmltYXJ5RGF0YQ0KdHJvbmQubXlrbGVi
dXN0QHByaW1hcnlkYXRhLmNvbQ0K


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] sunrpc: Use current_real_cred() when looking up rpc credentials
  2017-01-25  0:14                   ` Trond Myklebust
@ 2017-01-25 14:52                     ` Seth Forshee
  2017-01-25 15:51                       ` Trond Myklebust
  0 siblings, 1 reply; 19+ messages in thread
From: Seth Forshee @ 2017-01-25 14:52 UTC (permalink / raw)
  To: Trond Myklebust, ebiederm
  Cc: Steve French, dhowells, bfields, anna.schumaker, linux-nfs

On Wed, Jan 25, 2017 at 12:14:26AM +0000, Trond Myklebust wrote:
> Adding David Howells and Steve French as I believe both AFS and CIFS
> have the exact same requirements and NFS here.
> 
> On Wed, 2017-01-25 at 12:56 +1300, Eric W. Biederman wrote:
> > Trond Myklebust <trondmy@primarydata.com> writes:
> > 
> > > On Wed, 2017-01-25 at 12:28 +1300, Eric W. Biederman wrote:
> > > > With respect to nfs and automounts.
> > > > 
> > > > Does NFS have different automount behavior based on the user
> > > > performing the automount?
> > > > 
> > > > If NFS does not have different automount behavior depending on
> > > > the
> > > > user
> > > > we just use the creds of the original mounter of NFS?
> > > > 
> > > > If NFS does have different automount behavior depending on the
> > > > user
> > > > (ouch!) we need to go through the call path and see where it
> > > > makes
> > > > sense to over ride things and where it does not.
> > > 
> > > The reason why the NFS client creates a mountpoint is because on
> > > entering a directory, it detects that there is either a similar
> > > mountpoint on the server, or there is a referral (which acts sort
> > > of
> > > like a symlink, except it points to a path on one or more different
> > > NFS
> > > servers).
> > > Without that mountpoint, most things would work, but the user would
> > > end
> > > up seeing nasty non-posix features like duplicate inode numbers.
> > > 
> > > We do not want to use any creds other than user creds here, because
> > > as
> > > far as the security model is concerned, the process is just
> > > crossing
> > > into an existing directory.
> > 
> > But sget needs different creds.
> > 
> > Because the user who authorizes the mounting of the filesystem is
> > different than the user who is crossing into the new filesystem.
> > 
> > The local system now cares about that distinction even if the nfs
> > server
> > does not.
> 
> Why? The filesystem is already mounted. We're creating a new
> mountpoint, but we could equally well just say 'sod that' and create an
> ordinary directory. The penalty would be aforementioned non-posix
> weirdness.
> 
> > 
> > > > Seth the fundamental problem with your patch was that you were
> > > > patching
> > > > a location that is used for more just mounts.
> > > > 
> > > > I am strongly wishing that we could just change follow_automount
> > > > from:
> > > > 
> > > > 
> > > > 	old_cred = override_creds(&init_cred);
> > > > 	mnt = path->dentry->d_op->d_automount(path);
> > > > 	revert_creds(old_cred);
> > > > 
> > > > to:
> > > > 
> > > > 	old_cred = override_creds(path->mnt->mnt_sb->s_cred);
> > > > 	mnt = path->dentry->d_op->d_automount(path);
> > > > 	revert_creds(old_cred);
> > > > 
> > > > And all will be well with nfs.  That does remain possible.
> > > 
> > > No. That would break permissions checking. See above.
> > 
> > Then we need to look much harder at the permission checking
> > model of d_automount because we need to permission check against
> > both sets of creds.

How about something like this? Essentially, stash the creds used at
mount time in the super block, then create a vfs_kern_automount()
function which overrides the currend creds then calls vfs_kern_mount().

Only compile tested so far, and probably it should be split up into
several patches.

diff --git a/fs/afs/mntpt.c b/fs/afs/mntpt.c
index 81dd075356b9..4455e64610d3 100644
--- a/fs/afs/mntpt.c
+++ b/fs/afs/mntpt.c
@@ -202,7 +202,7 @@ static struct vfsmount *afs_mntpt_do_automount(struct dentry *mntpt)
 
 	/* try and do the mount */
 	_debug("--- attempting mount %s -o %s ---", devname, options);
-	mnt = vfs_kern_mount(&afs_fs_type, 0, devname, options);
+	mnt = vfs_kern_automount(mntpt, &afs_fs_type, 0, devname, options);
 	_debug("--- mount result %p ---", mnt);
 
 	free_page((unsigned long) devname);
diff --git a/fs/cifs/cifs_dfs_ref.c b/fs/cifs/cifs_dfs_ref.c
index ec9dbbcca3b9..d378f88e8630 100644
--- a/fs/cifs/cifs_dfs_ref.c
+++ b/fs/cifs/cifs_dfs_ref.c
@@ -245,9 +245,10 @@ char *cifs_compose_mount_options(const char *sb_mountdata,
  * @fullpath:		full path in UNC format
  * @ref:		server's referral
  */
-static struct vfsmount *cifs_dfs_do_refmount(struct cifs_sb_info *cifs_sb,
+static struct vfsmount *cifs_dfs_do_refmount(struct dentry *mntpt,
 		const char *fullpath, const struct dfs_info3_param *ref)
 {
+	struct cifs_sb_info *cifs_sb = CIFS_SB(mntpt->d_sb);
 	struct vfsmount *mnt;
 	char *mountdata;
 	char *devname = NULL;
@@ -259,7 +260,7 @@ static struct vfsmount *cifs_dfs_do_refmount(struct cifs_sb_info *cifs_sb,
 	if (IS_ERR(mountdata))
 		return (struct vfsmount *)mountdata;
 
-	mnt = vfs_kern_mount(&cifs_fs_type, 0, devname, mountdata);
+	mnt = vfs_kern_automount(mntpt, &cifs_fs_type, 0, devname, mountdata);
 	kfree(mountdata);
 	kfree(devname);
 	return mnt;
@@ -334,7 +335,7 @@ static struct vfsmount *cifs_dfs_do_automount(struct dentry *mntpt)
 			mnt = ERR_PTR(-EINVAL);
 			break;
 		}
-		mnt = cifs_dfs_do_refmount(cifs_sb,
+		mnt = cifs_dfs_do_refmount(mntpt,
 				full_path, referrals + i);
 		cifs_dbg(FYI, "%s: cifs_dfs_do_refmount:%s , mnt:%p\n",
 			 __func__, referrals[i].node_name, mnt);
diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index f17fcf89e18e..d45f131af869 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -187,9 +187,9 @@ static const struct super_operations debugfs_super_operations = {
 
 static struct vfsmount *debugfs_automount(struct path *path)
 {
-	struct vfsmount *(*f)(void *);
-	f = (struct vfsmount *(*)(void *))path->dentry->d_fsdata;
-	return f(d_inode(path->dentry)->i_private);
+	struct vfsmount *(*f)(struct dentry *, void *);
+	f = (struct vfsmount *(*)(struct dentry *, void *))path->dentry->d_fsdata;
+	return f(path->dentry, d_inode(path->dentry)->i_private);
 }
 
 static const struct dentry_operations debugfs_dops = {
@@ -504,7 +504,7 @@ EXPORT_SYMBOL_GPL(debugfs_create_dir);
  */
 struct dentry *debugfs_create_automount(const char *name,
 					struct dentry *parent,
-					struct vfsmount *(*f)(void *),
+					struct vfsmount *(*f)(struct dentry *, void *),
 					void *data)
 {
 	struct dentry *dentry = start_creating(name, parent);
diff --git a/fs/namespace.c b/fs/namespace.c
index 487ba30bb5c6..da7e6dfa56cb 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -989,6 +989,21 @@ vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void
 }
 EXPORT_SYMBOL_GPL(vfs_kern_mount);
 
+struct vfsmount *
+vfs_kern_automount(struct dentry *dentry, struct file_system_type *type,
+		   int flags, const char *name, void *data)
+{
+	const struct cred *old_cred;
+	struct vfsmount *mnt;
+
+	old_cred = override_creds(dentry->d_sb->s_cred);
+	mnt = vfs_kern_mount(type, flags, name, data);
+	revert_creds(old_cred);
+
+	return mnt;
+}
+EXPORT_SYMBOL_GPL(vfs_kern_automount);
+
 static struct mount *clone_mnt(struct mount *old, struct dentry *root,
 					int flag)
 {
diff --git a/fs/nfs/namespace.c b/fs/nfs/namespace.c
index 5551e8ef67fd..dce529c50cbd 100644
--- a/fs/nfs/namespace.c
+++ b/fs/nfs/namespace.c
@@ -222,11 +222,11 @@ void nfs_release_automount_timer(void)
 /*
  * Clone a mountpoint of the appropriate type
  */
-static struct vfsmount *nfs_do_clone_mount(struct nfs_server *server,
+static struct vfsmount *nfs_do_clone_mount(struct dentry *dentry,
 					   const char *devname,
 					   struct nfs_clone_mount *mountdata)
 {
-	return vfs_kern_mount(&nfs_xdev_fs_type, 0, devname, mountdata);
+	return vfs_kern_automount(dentry, &nfs_xdev_fs_type, 0, devname, mountdata);
 }
 
 /**
@@ -261,7 +261,7 @@ struct vfsmount *nfs_do_submount(struct dentry *dentry, struct nfs_fh *fh,
 	mnt = (struct vfsmount *)devname;
 	if (IS_ERR(devname))
 		goto free_page;
-	mnt = nfs_do_clone_mount(NFS_SB(dentry->d_sb), devname, &mountdata);
+	mnt = nfs_do_clone_mount(dentry, devname, &mountdata);
 free_page:
 	free_page((unsigned long)page);
 out:
diff --git a/fs/super.c b/fs/super.c
index 1709ed029a2c..b33b7d606aec 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -166,6 +166,7 @@ static void destroy_super(struct super_block *s)
 	list_lru_destroy(&s->s_inode_lru);
 	security_sb_free(s);
 	WARN_ON(!list_empty(&s->s_mounts));
+	put_cred(s->s_cred);
 	put_user_ns(s->s_user_ns);
 	kfree(s->s_subtype);
 	kfree(s->s_options);
@@ -193,6 +194,7 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags,
 
 	INIT_LIST_HEAD(&s->s_mounts);
 	s->s_user_ns = get_user_ns(user_ns);
+	s->s_cred = get_current_cred();
 
 	if (security_sb_alloc(s))
 		goto fail;
diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h
index 014cc564d1c4..67ac9f10e7b7 100644
--- a/include/linux/debugfs.h
+++ b/include/linux/debugfs.h
@@ -99,7 +99,7 @@ struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
 
 struct dentry *debugfs_create_automount(const char *name,
 					struct dentry *parent,
-					struct vfsmount *(*f)(void *),
+					struct vfsmount *(*f)(struct dentry *, void *),
 					void *data);
 
 void debugfs_remove(struct dentry *dentry);
@@ -211,7 +211,7 @@ static inline struct dentry *debugfs_create_symlink(const char *name,
 
 static inline struct dentry *debugfs_create_automount(const char *name,
 					struct dentry *parent,
-					struct vfsmount *(*f)(void *),
+					struct vfsmount *(*f)(struct dentry *, void *),
 					void *data)
 {
 	return ERR_PTR(-ENODEV);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 2ba074328894..cae845944d1d 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1374,6 +1374,9 @@ struct super_block {
 	 */
 	struct user_namespace *s_user_ns;
 
+	/* Credentials of the user who mounted the filesystem */
+	const struct cred *s_cred;
+
 	/*
 	 * Keep the lru lists last in the structure so they always sit on their
 	 * own individual cachelines.
diff --git a/include/linux/mount.h b/include/linux/mount.h
index c6f55158d5e5..b9cdca0c6b1a 100644
--- a/include/linux/mount.h
+++ b/include/linux/mount.h
@@ -90,6 +90,9 @@ struct file_system_type;
 extern struct vfsmount *vfs_kern_mount(struct file_system_type *type,
 				      int flags, const char *name,
 				      void *data);
+struct vfsmount *vfs_kern_automount(struct dentry *dentry,
+				    struct file_system_type *type,
+				    int flags, const char *name, void *data);
 
 extern void mnt_set_expiry(struct vfsmount *mnt, struct list_head *expiry_list);
 extern void mark_mounts_for_expiry(struct list_head *mounts);
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index d7449783987a..7bb959abd5f1 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -7503,7 +7503,7 @@ init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer)
 	ftrace_init_tracefs(tr, d_tracer);
 }
 
-static struct vfsmount *trace_automount(void *ingore)
+static struct vfsmount *trace_automount(struct dentry *dentry, void *ingore)
 {
 	struct vfsmount *mnt;
 	struct file_system_type *type;
@@ -7516,7 +7516,7 @@ static struct vfsmount *trace_automount(void *ingore)
 	type = get_fs_type("tracefs");
 	if (!type)
 		return NULL;
-	mnt = vfs_kern_mount(type, 0, "tracefs", NULL);
+	mnt = vfs_kern_automount(dentry, type, 0, "tracefs", NULL);
 	put_filesystem(type);
 	if (IS_ERR(mnt))
 		return NULL;

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH] sunrpc: Use current_real_cred() when looking up rpc credentials
  2017-01-25 14:52                     ` Seth Forshee
@ 2017-01-25 15:51                       ` Trond Myklebust
  2017-01-25 16:28                         ` Seth Forshee
  0 siblings, 1 reply; 19+ messages in thread
From: Trond Myklebust @ 2017-01-25 15:51 UTC (permalink / raw)
  To: seth.forshee, ebiederm
  Cc: bfields, anna.schumaker, Steve French, linux-nfs, dhowells

T24gV2VkLCAyMDE3LTAxLTI1IGF0IDA4OjUyIC0wNjAwLCBTZXRoIEZvcnNoZWUgd3JvdGU6DQo+
IE9uIFdlZCwgSmFuIDI1LCAyMDE3IGF0IDEyOjE0OjI2QU0gKzAwMDAsIFRyb25kIE15a2xlYnVz
dCB3cm90ZToNCj4gPiBBZGRpbmcgRGF2aWQgSG93ZWxscyBhbmQgU3RldmUgRnJlbmNoIGFzIEkg
YmVsaWV2ZSBib3RoIEFGUyBhbmQNCj4gPiBDSUZTDQo+ID4gaGF2ZSB0aGUgZXhhY3Qgc2FtZSBy
ZXF1aXJlbWVudHMgYW5kIE5GUyBoZXJlLg0KPiA+IA0KPiA+IE9uIFdlZCwgMjAxNy0wMS0yNSBh
dCAxMjo1NiArMTMwMCwgRXJpYyBXLiBCaWVkZXJtYW4gd3JvdGU6DQo+ID4gPiBUcm9uZCBNeWts
ZWJ1c3QgPHRyb25kbXlAcHJpbWFyeWRhdGEuY29tPiB3cml0ZXM6DQo+ID4gPiANCj4gPiA+ID4g
T24gV2VkLCAyMDE3LTAxLTI1IGF0IDEyOjI4ICsxMzAwLCBFcmljIFcuIEJpZWRlcm1hbiB3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nQgPSB2ZnNf
a2Vybl9tb3VudCh0eXBlLCBmbGFncywgbmFtZSwgZGF0YSk7DQo+ICsJcmV2ZXJ0X2NyZWRzKG9s
ZF9jcmVkKTsNCj4gKw0KPiArCXJldHVybiBtbnQ7DQo+ICt9DQo+ICtFWFBPUlRfU1lNQk9MX0dQ
TCh2ZnNfa2Vybl9hdXRvbW91bnQpOw0KPiArDQoNCk5vcGUuIEFzIEkgc2FpZCwgdGhlIGNhbGwg
aW50byB0aGUgZmlsZXN5c3RlbSBuZWVkcyB0aGUgX3VzZXJfIGNyZWRzLg0KDQotLSA=


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] sunrpc: Use current_real_cred() when looking up rpc credentials
  2017-01-25 15:51                       ` Trond Myklebust
@ 2017-01-25 16:28                         ` Seth Forshee
  2017-02-01  6:36                           ` Eric W. Biederman
  0 siblings, 1 reply; 19+ messages in thread
From: Seth Forshee @ 2017-01-25 16:28 UTC (permalink / raw)
  To: Trond Myklebust
  Cc: ebiederm, bfields, anna.schumaker, Steve French, linux-nfs, dhowells

On Wed, Jan 25, 2017 at 03:51:30PM +0000, Trond Myklebust wrote:
> On Wed, 2017-01-25 at 08:52 -0600, Seth Forshee wrote:
> > On Wed, Jan 25, 2017 at 12:14:26AM +0000, Trond Myklebust wrote:
> > > Adding David Howells and Steve French as I believe both AFS and
> > > CIFS
> > > have the exact same requirements and NFS here.
> > > 
> > > On Wed, 2017-01-25 at 12:56 +1300, Eric W. Biederman wrote:
> > > > Trond Myklebust <trondmy@primarydata.com> writes:
> > > > 
> > > > > On Wed, 2017-01-25 at 12:28 +1300, Eric W. Biederman wrote:
> > > > > > With respect to nfs and automounts.
> > > > > > 
> > > > > > Does NFS have different automount behavior based on the user
> > > > > > performing the automount?
> > > > > > 
> > > > > > If NFS does not have different automount behavior depending
> > > > > > on
> > > > > > the
> > > > > > user
> > > > > > we just use the creds of the original mounter of NFS?
> > > > > > 
> > > > > > If NFS does have different automount behavior depending on
> > > > > > the
> > > > > > user
> > > > > > (ouch!) we need to go through the call path and see where it
> > > > > > makes
> > > > > > sense to over ride things and where it does not.
> > > > > 
> > > > > The reason why the NFS client creates a mountpoint is because
> > > > > on
> > > > > entering a directory, it detects that there is either a similar
> > > > > mountpoint on the server, or there is a referral (which acts
> > > > > sort
> > > > > of
> > > > > like a symlink, except it points to a path on one or more
> > > > > different
> > > > > NFS
> > > > > servers).
> > > > > Without that mountpoint, most things would work, but the user
> > > > > would
> > > > > end
> > > > > up seeing nasty non-posix features like duplicate inode
> > > > > numbers.
> > > > > 
> > > > > We do not want to use any creds other than user creds here,
> > > > > because
> > > > > as
> > > > > far as the security model is concerned, the process is just
> > > > > crossing
> > > > > into an existing directory.
> > > > 
> > > > But sget needs different creds.
> > > > 
> > > > Because the user who authorizes the mounting of the filesystem is
> > > > different than the user who is crossing into the new filesystem.
> > > > 
> > > > The local system now cares about that distinction even if the nfs
> > > > server
> > > > does not.
> > > 
> > > Why? The filesystem is already mounted. We're creating a new
> > > mountpoint, but we could equally well just say 'sod that' and
> > > create an
> > > ordinary directory. The penalty would be aforementioned non-posix
> > > weirdness.
> > > 
> > > > 
> > > > > > Seth the fundamental problem with your patch was that you
> > > > > > were
> > > > > > patching
> > > > > > a location that is used for more just mounts.
> > > > > > 
> > > > > > I am strongly wishing that we could just change
> > > > > > follow_automount
> > > > > > from:
> > > > > > 
> > > > > > 
> > > > > > 	old_cred = override_creds(&init_cred);
> > > > > > 	mnt = path->dentry->d_op->d_automount(path);
> > > > > > 	revert_creds(old_cred);
> > > > > > 
> > > > > > to:
> > > > > > 
> > > > > > 	old_cred = override_creds(path->mnt->mnt_sb->s_cred);
> > > > > > 	mnt = path->dentry->d_op->d_automount(path);
> > > > > > 	revert_creds(old_cred);
> > > > > > 
> > > > > > And all will be well with nfs.  That does remain possible.
> > > > > 
> > > > > No. That would break permissions checking. See above.
> > > > 
> > > > Then we need to look much harder at the permission checking
> > > > model of d_automount because we need to permission check against
> > > > both sets of creds.
> > 
> > How about something like this? Essentially, stash the creds used at
> > mount time in the super block, then create a vfs_kern_automount()
> > function which overrides the currend creds then calls
> > vfs_kern_mount().
> > 
> > Only compile tested so far, and probably it should be split up into
> > several patches.
> 
> > diff --git a/fs/namespace.c b/fs/namespace.c
> > index 487ba30bb5c6..da7e6dfa56cb 100644
> > --- a/fs/namespace.c
> > +++ b/fs/namespace.c
> > @@ -989,6 +989,21 @@ vfs_kern_mount(struct file_system_type *type,
> > int flags, const char *name, void
> >  }
> >  EXPORT_SYMBOL_GPL(vfs_kern_mount);
> >  
> > +struct vfsmount *
> > +vfs_kern_automount(struct dentry *dentry, struct file_system_type
> > *type,
> > +		   int flags, const char *name, void *data)
> > +{
> > +	const struct cred *old_cred;
> > +	struct vfsmount *mnt;
> > +
> > +	old_cred = override_creds(dentry->d_sb->s_cred);
> > +	mnt = vfs_kern_mount(type, flags, name, data);
> > +	revert_creds(old_cred);
> > +
> > +	return mnt;
> > +}
> > +EXPORT_SYMBOL_GPL(vfs_kern_automount);
> > +
> 
> Nope. As I said, the call into the filesystem needs the _user_ creds.

Okay. I thought that perhaps the user's creds were only needed when
looking up the mountpoint, and that after that it might be okay to
switch the creds. I guess not.

Thanks,
Seth

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] sunrpc: Use current_real_cred() when looking up rpc credentials
  2017-01-25 16:28                         ` Seth Forshee
@ 2017-02-01  6:36                           ` Eric W. Biederman
  2017-02-01  6:38                             ` [REVIEW][PATCH] fs: Better permission checking for submounts Eric W. Biederman
  0 siblings, 1 reply; 19+ messages in thread
From: Eric W. Biederman @ 2017-02-01  6:36 UTC (permalink / raw)
  To: Seth Forshee
  Cc: Trond Myklebust, bfields, anna.schumaker, Steve French,
	linux-nfs, dhowells

Seth Forshee <seth.forshee@canonical.com> writes:

> On Wed, Jan 25, 2017 at 03:51:30PM +0000, Trond Myklebust wrote:
>> On Wed, 2017-01-25 at 08:52 -0600, Seth Forshee wrote:
>> > On Wed, Jan 25, 2017 at 12:14:26AM +0000, Trond Myklebust wrote:
>> > > Adding David Howells and Steve French as I believe both AFS and
>> > > CIFS
>> > > have the exact same requirements and NFS here.
>> > > 
>> > > On Wed, 2017-01-25 at 12:56 +1300, Eric W. Biederman wrote:
>> > > > Trond Myklebust <trondmy@primarydata.com> writes:
>> > > > 
>> > > > > On Wed, 2017-01-25 at 12:28 +1300, Eric W. Biederman wrote:
>> > > > > > With respect to nfs and automounts.
>> > > > > > 
>> > > > > > Does NFS have different automount behavior based on the user
>> > > > > > performing the automount?
>> > > > > > 
>> > > > > > If NFS does not have different automount behavior depending
>> > > > > > on
>> > > > > > the
>> > > > > > user
>> > > > > > we just use the creds of the original mounter of NFS?
>> > > > > > 
>> > > > > > If NFS does have different automount behavior depending on
>> > > > > > the
>> > > > > > user
>> > > > > > (ouch!) we need to go through the call path and see where it
>> > > > > > makes
>> > > > > > sense to over ride things and where it does not.
>> > > > > 
>> > > > > The reason why the NFS client creates a mountpoint is because
>> > > > > on
>> > > > > entering a directory, it detects that there is either a similar
>> > > > > mountpoint on the server, or there is a referral (which acts
>> > > > > sort
>> > > > > of
>> > > > > like a symlink, except it points to a path on one or more
>> > > > > different
>> > > > > NFS
>> > > > > servers).
>> > > > > Without that mountpoint, most things would work, but the user
>> > > > > would
>> > > > > end
>> > > > > up seeing nasty non-posix features like duplicate inode
>> > > > > numbers.
>> > > > > 
>> > > > > We do not want to use any creds other than user creds here,
>> > > > > because
>> > > > > as
>> > > > > far as the security model is concerned, the process is just
>> > > > > crossing
>> > > > > into an existing directory.
>> > > > 
>> > > > But sget needs different creds.
>> > > > 
>> > > > Because the user who authorizes the mounting of the filesystem is
>> > > > different than the user who is crossing into the new filesystem.
>> > > > 
>> > > > The local system now cares about that distinction even if the nfs
>> > > > server
>> > > > does not.
>> > > 
>> > > Why? The filesystem is already mounted. We're creating a new
>> > > mountpoint, but we could equally well just say 'sod that' and
>> > > create an
>> > > ordinary directory. The penalty would be aforementioned non-posix
>> > > weirdness.
>> > > 
>> > > > 
>> > > > > > Seth the fundamental problem with your patch was that you
>> > > > > > were
>> > > > > > patching
>> > > > > > a location that is used for more just mounts.
>> > > > > > 
>> > > > > > I am strongly wishing that we could just change
>> > > > > > follow_automount
>> > > > > > from:
>> > > > > > 
>> > > > > > 
>> > > > > > 	old_cred = override_creds(&init_cred);
>> > > > > > 	mnt = path->dentry->d_op->d_automount(path);
>> > > > > > 	revert_creds(old_cred);
>> > > > > > 
>> > > > > > to:
>> > > > > > 
>> > > > > > 	old_cred = override_creds(path->mnt->mnt_sb->s_cred);
>> > > > > > 	mnt = path->dentry->d_op->d_automount(path);
>> > > > > > 	revert_creds(old_cred);
>> > > > > > 
>> > > > > > And all will be well with nfs.  That does remain possible.
>> > > > > 
>> > > > > No. That would break permissions checking. See above.
>> > > > 
>> > > > Then we need to look much harder at the permission checking
>> > > > model of d_automount because we need to permission check against
>> > > > both sets of creds.
>> > 
>> > How about something like this? Essentially, stash the creds used at
>> > mount time in the super block, then create a vfs_kern_automount()
>> > function which overrides the currend creds then calls
>> > vfs_kern_mount().
>> > 
>> > Only compile tested so far, and probably it should be split up into
>> > several patches.
>> 
>> > diff --git a/fs/namespace.c b/fs/namespace.c
>> > index 487ba30bb5c6..da7e6dfa56cb 100644
>> > --- a/fs/namespace.c
>> > +++ b/fs/namespace.c
>> > @@ -989,6 +989,21 @@ vfs_kern_mount(struct file_system_type *type,
>> > int flags, const char *name, void
>> >  }
>> >  EXPORT_SYMBOL_GPL(vfs_kern_mount);
>> >  
>> > +struct vfsmount *
>> > +vfs_kern_automount(struct dentry *dentry, struct file_system_type
>> > *type,
>> > +		   int flags, const char *name, void *data)
>> > +{
>> > +	const struct cred *old_cred;
>> > +	struct vfsmount *mnt;
>> > +
>> > +	old_cred = override_creds(dentry->d_sb->s_cred);
>> > +	mnt = vfs_kern_mount(type, flags, name, data);
>> > +	revert_creds(old_cred);
>> > +
>> > +	return mnt;
>> > +}
>> > +EXPORT_SYMBOL_GPL(vfs_kern_automount);
>> > +
>> 
>> Nope. As I said, the call into the filesystem needs the _user_ creds.
>
> Okay. I thought that perhaps the user's creds were only needed when
> looking up the mountpoint, and that after that it might be okay to
> switch the creds. I guess not.

So I agree that for the case of submounts that we don't need an
additional permission check as the initial mount of the filesystem
is that permission check already.

I can see some interesting corner cases where a permission check might
be required at the point when we have unprivileged mounts with submounts
in the mix.  As sget might find a filesystem that was already mounted
elsewhere.  But we don't have to face that case today.

What is needs to be fixed are the permission checks cause problems for
existing filesystems with submounts.

What we need to fix those is knowledge the mount is happening for a
submount/automount.  At which point it is simple to turn off the
permission check.  Knowledge that a mount is a submount and not the
ordinary kind of mount is going to require something like Seth's patch.

So after having gone off to a corner and thought about this I believe
I have come up with a minimal patch that makes things good for everyone.

Eric


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [REVIEW][PATCH] fs: Better permission checking for submounts
  2017-02-01  6:36                           ` Eric W. Biederman
@ 2017-02-01  6:38                             ` Eric W. Biederman
  2017-02-01 13:28                                 ` Trond Myklebust
  2017-02-01 13:38                               ` Seth Forshee
  0 siblings, 2 replies; 19+ messages in thread
From: Eric W. Biederman @ 2017-02-01  6:38 UTC (permalink / raw)
  To: Seth Forshee
  Cc: Trond Myklebust, bfields, anna.schumaker, Steve French,
	linux-nfs, dhowells, linux-fsdevel


To support unprivileged users mounting filesystems two permission
checks have to be performed: a test to see if the user allowed to
create a mount in the mount namespace, and a test to see if
the user is allowed to access the specified filesystem.

The automount case is special in that mounting the original filesystem
grants permission to mount the sub-filesystems, to any user who
happens to stumble across the their mountpoint and satisfies the
ordinary filesystem permission checks.

Attempting to handle the automount case by using override_creds
almost works.  It preserves the idea that permission to mount
the original filesystem is permission to mount the sub-filesystem.
Unfortunately using override_creds messes up the filesystems
ordinary permission checks.

Solve this by being explicit that a mount is a submount by introducing
vfs_submount, and using it where appropriate.

vfs_submount uses a new mount internal mount flags MS_SUBMOUNT, to let
sget and friends know that a mount is a submount so they can take appropriate
action.

sget and sget_userns are modified to not perform any permission checks
on submounts.

follow_automount is modified to stop using override_creds as that
has proven problemantic.

do_mount is modified to always remove the new MS_SUBMOUNT flag so
that we know userspace will never by able to specify it.

autofs4 is modified to stop using current_real_cred that was put in
there to handle the previous version of submount permission checking.

cifs is modified to pass the mountpoint all of the way down to vfs_submount.

debugfs is modified to pass the mountpoint all of the way down to
trace_automount by adding a new parameter.  To make this change easier
a new typedef debugfs_automount_t is introduced to capture the type of
the debugfs automount function.

Cc: stable@vger.kernel.org
Fixes: 069d5ac9ae0d ("autofs:  Fix automounts by using current_real_cred()->uid")
Fixes: aeaa4a79ff6a ("fs: Call d_automount with the filesystems creds")
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
 fs/afs/mntpt.c          |  2 +-
 fs/autofs4/waitq.c      |  4 ++--
 fs/cifs/cifs_dfs_ref.c  |  7 ++++---
 fs/debugfs/inode.c      |  8 ++++----
 fs/namei.c              |  3 ---
 fs/namespace.c          | 17 ++++++++++++++++-
 fs/nfs/namespace.c      |  2 +-
 fs/nfs/nfs4namespace.c  |  2 +-
 fs/super.c              | 13 ++++++++++---
 include/linux/debugfs.h |  3 ++-
 include/linux/mount.h   |  3 +++
 include/uapi/linux/fs.h |  1 +
 kernel/trace/trace.c    |  4 ++--
 13 files changed, 47 insertions(+), 22 deletions(-)

diff --git a/fs/afs/mntpt.c b/fs/afs/mntpt.c
index 81dd075356b9..d4fb0afc0097 100644
--- a/fs/afs/mntpt.c
+++ b/fs/afs/mntpt.c
@@ -202,7 +202,7 @@ static struct vfsmount *afs_mntpt_do_automount(struct dentry *mntpt)
 
 	/* try and do the mount */
 	_debug("--- attempting mount %s -o %s ---", devname, options);
-	mnt = vfs_kern_mount(&afs_fs_type, 0, devname, options);
+	mnt = vfs_submount(mntpt, &afs_fs_type, devname, options);
 	_debug("--- mount result %p ---", mnt);
 
 	free_page((unsigned long) devname);
diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
index 1278335ce366..79fbd85db4ba 100644
--- a/fs/autofs4/waitq.c
+++ b/fs/autofs4/waitq.c
@@ -436,8 +436,8 @@ int autofs4_wait(struct autofs_sb_info *sbi,
 		memcpy(&wq->name, &qstr, sizeof(struct qstr));
 		wq->dev = autofs4_get_dev(sbi);
 		wq->ino = autofs4_get_ino(sbi);
-		wq->uid = current_real_cred()->uid;
-		wq->gid = current_real_cred()->gid;
+		wq->uid = current_cred()->uid;
+		wq->gid = current_cred()->gid;
 		wq->pid = pid;
 		wq->tgid = tgid;
 		wq->status = -EINTR; /* Status return if interrupted */
diff --git a/fs/cifs/cifs_dfs_ref.c b/fs/cifs/cifs_dfs_ref.c
index ec9dbbcca3b9..9156be545b0f 100644
--- a/fs/cifs/cifs_dfs_ref.c
+++ b/fs/cifs/cifs_dfs_ref.c
@@ -245,7 +245,8 @@ char *cifs_compose_mount_options(const char *sb_mountdata,
  * @fullpath:		full path in UNC format
  * @ref:		server's referral
  */
-static struct vfsmount *cifs_dfs_do_refmount(struct cifs_sb_info *cifs_sb,
+static struct vfsmount *cifs_dfs_do_refmount(struct dentry *mntpt,
+		struct cifs_sb_info *cifs_sb,
 		const char *fullpath, const struct dfs_info3_param *ref)
 {
 	struct vfsmount *mnt;
@@ -259,7 +260,7 @@ static struct vfsmount *cifs_dfs_do_refmount(struct cifs_sb_info *cifs_sb,
 	if (IS_ERR(mountdata))
 		return (struct vfsmount *)mountdata;
 
-	mnt = vfs_kern_mount(&cifs_fs_type, 0, devname, mountdata);
+	mnt = vfs_submount(mntpt, &cifs_fs_type, devname, mountdata);
 	kfree(mountdata);
 	kfree(devname);
 	return mnt;
@@ -334,7 +335,7 @@ static struct vfsmount *cifs_dfs_do_automount(struct dentry *mntpt)
 			mnt = ERR_PTR(-EINVAL);
 			break;
 		}
-		mnt = cifs_dfs_do_refmount(cifs_sb,
+		mnt = cifs_dfs_do_refmount(mntpt, cifs_sb,
 				full_path, referrals + i);
 		cifs_dbg(FYI, "%s: cifs_dfs_do_refmount:%s , mnt:%p\n",
 			 __func__, referrals[i].node_name, mnt);
diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index f17fcf89e18e..1e30f74a9527 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -187,9 +187,9 @@ static const struct super_operations debugfs_super_operations = {
 
 static struct vfsmount *debugfs_automount(struct path *path)
 {
-	struct vfsmount *(*f)(void *);
-	f = (struct vfsmount *(*)(void *))path->dentry->d_fsdata;
-	return f(d_inode(path->dentry)->i_private);
+	debugfs_automount_t f;
+	f = (debugfs_automount_t)path->dentry->d_fsdata;
+	return f(path->dentry, d_inode(path->dentry)->i_private);
 }
 
 static const struct dentry_operations debugfs_dops = {
@@ -504,7 +504,7 @@ EXPORT_SYMBOL_GPL(debugfs_create_dir);
  */
 struct dentry *debugfs_create_automount(const char *name,
 					struct dentry *parent,
-					struct vfsmount *(*f)(void *),
+					debugfs_automount_t f,
 					void *data)
 {
 	struct dentry *dentry = start_creating(name, parent);
diff --git a/fs/namei.c b/fs/namei.c
index 6fa3e9138fe4..da689c9c005e 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1100,7 +1100,6 @@ static int follow_automount(struct path *path, struct nameidata *nd,
 			    bool *need_mntput)
 {
 	struct vfsmount *mnt;
-	const struct cred *old_cred;
 	int err;
 
 	if (!path->dentry->d_op || !path->dentry->d_op->d_automount)
@@ -1129,9 +1128,7 @@ static int follow_automount(struct path *path, struct nameidata *nd,
 	if (nd->total_link_count >= 40)
 		return -ELOOP;
 
-	old_cred = override_creds(&init_cred);
 	mnt = path->dentry->d_op->d_automount(path);
-	revert_creds(old_cred);
 	if (IS_ERR(mnt)) {
 		/*
 		 * The filesystem is allowed to return -EISDIR here to indicate
diff --git a/fs/namespace.c b/fs/namespace.c
index 487ba30bb5c6..089a6b23135a 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -989,6 +989,21 @@ vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void
 }
 EXPORT_SYMBOL_GPL(vfs_kern_mount);
 
+struct vfsmount *
+vfs_submount(const struct dentry *mountpoint, struct file_system_type *type,
+	     const char *name, void *data)
+{
+	/* Until it is worked out how to pass the user namespace
+	 * through from the parent mount to the submount don't support
+	 * unprivileged mounts with submounts.
+	 */
+	if (mountpoint->d_sb->s_user_ns != &init_user_ns)
+		return ERR_PTR(-EPERM);
+
+	return vfs_kern_mount(type, MS_SUBMOUNT, name, data);
+}
+EXPORT_SYMBOL_GPL(vfs_submount);
+
 static struct mount *clone_mnt(struct mount *old, struct dentry *root,
 					int flag)
 {
@@ -2794,7 +2809,7 @@ long do_mount(const char *dev_name, const char __user *dir_name,
 
 	flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
 		   MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
-		   MS_STRICTATIME | MS_NOREMOTELOCK);
+		   MS_STRICTATIME | MS_NOREMOTELOCK | MS_SUBMOUNT);
 
 	if (flags & MS_REMOUNT)
 		retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
diff --git a/fs/nfs/namespace.c b/fs/nfs/namespace.c
index 5551e8ef67fd..e49d831c4e85 100644
--- a/fs/nfs/namespace.c
+++ b/fs/nfs/namespace.c
@@ -226,7 +226,7 @@ static struct vfsmount *nfs_do_clone_mount(struct nfs_server *server,
 					   const char *devname,
 					   struct nfs_clone_mount *mountdata)
 {
-	return vfs_kern_mount(&nfs_xdev_fs_type, 0, devname, mountdata);
+	return vfs_submount(mountdata->dentry, &nfs_xdev_fs_type, devname, mountdata);
 }
 
 /**
diff --git a/fs/nfs/nfs4namespace.c b/fs/nfs/nfs4namespace.c
index d21104912676..d8b040bd9814 100644
--- a/fs/nfs/nfs4namespace.c
+++ b/fs/nfs/nfs4namespace.c
@@ -279,7 +279,7 @@ static struct vfsmount *try_location(struct nfs_clone_mount *mountdata,
 				mountdata->hostname,
 				mountdata->mnt_path);
 
-		mnt = vfs_kern_mount(&nfs4_referral_fs_type, 0, page, mountdata);
+		mnt = vfs_submount(mountdata->dentry, &nfs4_referral_fs_type, page, mountdata);
 		if (!IS_ERR(mnt))
 			break;
 	}
diff --git a/fs/super.c b/fs/super.c
index 1709ed029a2c..4185844f7a12 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -469,7 +469,7 @@ struct super_block *sget_userns(struct file_system_type *type,
 	struct super_block *old;
 	int err;
 
-	if (!(flags & MS_KERNMOUNT) &&
+	if (!(flags & (MS_KERNMOUNT|MS_SUBMOUNT)) &&
 	    !(type->fs_flags & FS_USERNS_MOUNT) &&
 	    !capable(CAP_SYS_ADMIN))
 		return ERR_PTR(-EPERM);
@@ -499,7 +499,7 @@ struct super_block *sget_userns(struct file_system_type *type,
 	}
 	if (!s) {
 		spin_unlock(&sb_lock);
-		s = alloc_super(type, flags, user_ns);
+		s = alloc_super(type, (flags & ~MS_SUBMOUNT), user_ns);
 		if (!s)
 			return ERR_PTR(-ENOMEM);
 		goto retry;
@@ -540,8 +540,15 @@ struct super_block *sget(struct file_system_type *type,
 {
 	struct user_namespace *user_ns = current_user_ns();
 
+	/* We don't yet pass the user namespace of the parent
+	 * mount through to here so always use &init_user_ns
+	 * until that changes.
+	 */
+	if (flags & MS_SUBMOUNT)
+		user_ns = &init_user_ns;
+
 	/* Ensure the requestor has permissions over the target filesystem */
-	if (!(flags & MS_KERNMOUNT) && !ns_capable(user_ns, CAP_SYS_ADMIN))
+	if (!(flags & (MS_KERNMOUNT|MS_SUBMOUNT)) && !ns_capable(user_ns, CAP_SYS_ADMIN))
 		return ERR_PTR(-EPERM);
 
 	return sget_userns(type, test, set, flags, user_ns, data);
diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h
index 014cc564d1c4..233006be30aa 100644
--- a/include/linux/debugfs.h
+++ b/include/linux/debugfs.h
@@ -97,9 +97,10 @@ struct dentry *debugfs_create_dir(const char *name, struct dentry *parent);
 struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
 				      const char *dest);
 
+typedef struct vfsmount *(*debugfs_automount_t)(struct dentry *, void *);
 struct dentry *debugfs_create_automount(const char *name,
 					struct dentry *parent,
-					struct vfsmount *(*f)(void *),
+					debugfs_automount_t f,
 					void *data);
 
 void debugfs_remove(struct dentry *dentry);
diff --git a/include/linux/mount.h b/include/linux/mount.h
index c6f55158d5e5..8e0352af06b7 100644
--- a/include/linux/mount.h
+++ b/include/linux/mount.h
@@ -90,6 +90,9 @@ struct file_system_type;
 extern struct vfsmount *vfs_kern_mount(struct file_system_type *type,
 				      int flags, const char *name,
 				      void *data);
+extern struct vfsmount *vfs_submount(const struct dentry *mountpoint,
+				     struct file_system_type *type,
+				     const char *name, void *data);
 
 extern void mnt_set_expiry(struct vfsmount *mnt, struct list_head *expiry_list);
 extern void mark_mounts_for_expiry(struct list_head *mounts);
diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
index 36da93fbf188..048a85e9f017 100644
--- a/include/uapi/linux/fs.h
+++ b/include/uapi/linux/fs.h
@@ -132,6 +132,7 @@ struct inodes_stat_t {
 #define MS_LAZYTIME	(1<<25) /* Update the on-disk [acm]times lazily */
 
 /* These sb flags are internal to the kernel */
+#define MS_SUBMOUNT     (1<<26)
 #define MS_NOREMOTELOCK	(1<<27)
 #define MS_NOSEC	(1<<28)
 #define MS_BORN		(1<<29)
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index d7449783987a..310f0ea0d1a2 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -7503,7 +7503,7 @@ init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer)
 	ftrace_init_tracefs(tr, d_tracer);
 }
 
-static struct vfsmount *trace_automount(void *ingore)
+static struct vfsmount *trace_automount(struct dentry *mntpt, void *ingore)
 {
 	struct vfsmount *mnt;
 	struct file_system_type *type;
@@ -7516,7 +7516,7 @@ static struct vfsmount *trace_automount(void *ingore)
 	type = get_fs_type("tracefs");
 	if (!type)
 		return NULL;
-	mnt = vfs_kern_mount(type, 0, "tracefs", NULL);
+	mnt = vfs_submount(mntpt, type, "tracefs", NULL);
 	put_filesystem(type);
 	if (IS_ERR(mnt))
 		return NULL;
-- 
2.10.1

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [REVIEW][PATCH] fs: Better permission checking for submounts
  2017-02-01  6:38                             ` [REVIEW][PATCH] fs: Better permission checking for submounts Eric W. Biederman
@ 2017-02-01 13:28                                 ` Trond Myklebust
  2017-02-01 13:38                               ` Seth Forshee
  1 sibling, 0 replies; 19+ messages in thread
From: Trond Myklebust @ 2017-02-01 13:28 UTC (permalink / raw)
  To: ebiederm, seth.forshee
  Cc: bfields, anna.schumaker, Steve French, linux-nfs, dhowells,
	linux-fsdevel

On Wed, 2017-02-01 at 19:38 +1300, Eric W. Biederman wrote:
> To support unprivileged users mounting filesystems two permission
> checks have to be performed: a test to see if the user allowed to
> create a mount in the mount namespace, and a test to see if
> the user is allowed to access the specified filesystem.
> 
> The automount case is special in that mounting the original
> filesystem
> grants permission to mount the sub-filesystems, to any user who
> happens to stumble across the their mountpoint and satisfies the
> ordinary filesystem permission checks.
> 
> Attempting to handle the automount case by using override_creds
> almost works.  It preserves the idea that permission to mount
> the original filesystem is permission to mount the sub-filesystem.
> Unfortunately using override_creds messes up the filesystems
> ordinary permission checks.
> 
> Solve this by being explicit that a mount is a submount by
> introducing
> vfs_submount, and using it where appropriate.
> 
> vfs_submount uses a new mount internal mount flags MS_SUBMOUNT, to
> let
> sget and friends know that a mount is a submount so they can take
> appropriate
> action.
> 
> sget and sget_userns are modified to not perform any permission
> checks
> on submounts.
> 
> follow_automount is modified to stop using override_creds as that
> has proven problemantic.
> 
> do_mount is modified to always remove the new MS_SUBMOUNT flag so
> that we know userspace will never by able to specify it.
> 
> autofs4 is modified to stop using current_real_cred that was put in
> there to handle the previous version of submount permission checking.
> 
> cifs is modified to pass the mountpoint all of the way down to
> vfs_submount.
> 
> debugfs is modified to pass the mountpoint all of the way down to
> trace_automount by adding a new parameter.  To make this change
> easier
> a new typedef debugfs_automount_t is introduced to capture the type
> of
> the debugfs automount function.
> 
> Cc: stable@vger.kernel.org
> Fixes: 069d5ac9ae0d ("autofs:  Fix automounts by using
> current_real_cred()->uid")
> Fixes: aeaa4a79ff6a ("fs: Call d_automount with the filesystems
> creds")
> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
> ---
>  fs/afs/mntpt.c          |  2 +-
>  fs/autofs4/waitq.c      |  4 ++--
>  fs/cifs/cifs_dfs_ref.c  |  7 ++++---
>  fs/debugfs/inode.c      |  8 ++++----
>  fs/namei.c              |  3 ---
>  fs/namespace.c          | 17 ++++++++++++++++-
>  fs/nfs/namespace.c      |  2 +-
>  fs/nfs/nfs4namespace.c  |  2 +-
>  fs/super.c              | 13 ++++++++++---
>  include/linux/debugfs.h |  3 ++-
>  include/linux/mount.h   |  3 +++
>  include/uapi/linux/fs.h |  1 +
>  kernel/trace/trace.c    |  4 ++--
>  13 files changed, 47 insertions(+), 22 deletions(-)
> 
> diff --git a/fs/afs/mntpt.c b/fs/afs/mntpt.c
> index 81dd075356b9..d4fb0afc0097 100644
> --- a/fs/afs/mntpt.c
> +++ b/fs/afs/mntpt.c
> @@ -202,7 +202,7 @@ static struct vfsmount
> *afs_mntpt_do_automount(struct dentry *mntpt)
>  
>  	/* try and do the mount */
>  	_debug("--- attempting mount %s -o %s ---", devname,
> options);
> -	mnt = vfs_kern_mount(&afs_fs_type, 0, devname, options);
> +	mnt = vfs_submount(mntpt, &afs_fs_type, devname, options);
>  	_debug("--- mount result %p ---", mnt);
>  
>  	free_page((unsigned long) devname);
> diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
> index 1278335ce366..79fbd85db4ba 100644
> --- a/fs/autofs4/waitq.c
> +++ b/fs/autofs4/waitq.c
> @@ -436,8 +436,8 @@ int autofs4_wait(struct autofs_sb_info *sbi,
>  		memcpy(&wq->name, &qstr, sizeof(struct qstr));
>  		wq->dev = autofs4_get_dev(sbi);
>  		wq->ino = autofs4_get_ino(sbi);
> -		wq->uid = current_real_cred()->uid;
> -		wq->gid = current_real_cred()->gid;
> +		wq->uid = current_cred()->uid;
> +		wq->gid = current_cred()->gid;
>  		wq->pid = pid;
>  		wq->tgid = tgid;
>  		wq->status = -EINTR; /* Status return if interrupted
> */
> diff --git a/fs/cifs/cifs_dfs_ref.c b/fs/cifs/cifs_dfs_ref.c
> index ec9dbbcca3b9..9156be545b0f 100644
> --- a/fs/cifs/cifs_dfs_ref.c
> +++ b/fs/cifs/cifs_dfs_ref.c
> @@ -245,7 +245,8 @@ char *cifs_compose_mount_options(const char
> *sb_mountdata,
>   * @fullpath:		full path in UNC format
>   * @ref:		server's referral
>   */
> -static struct vfsmount *cifs_dfs_do_refmount(struct cifs_sb_info
> *cifs_sb,
> +static struct vfsmount *cifs_dfs_do_refmount(struct dentry *mntpt,
> +		struct cifs_sb_info *cifs_sb,
>  		const char *fullpath, const struct dfs_info3_param
> *ref)
>  {
>  	struct vfsmount *mnt;
> @@ -259,7 +260,7 @@ static struct vfsmount
> *cifs_dfs_do_refmount(struct cifs_sb_info *cifs_sb,
>  	if (IS_ERR(mountdata))
>  		return (struct vfsmount *)mountdata;
>  
> -	mnt = vfs_kern_mount(&cifs_fs_type, 0, devname, mountdata);
> +	mnt = vfs_submount(mntpt, &cifs_fs_type, devname,
> mountdata);
>  	kfree(mountdata);
>  	kfree(devname);
>  	return mnt;
> @@ -334,7 +335,7 @@ static struct vfsmount
> *cifs_dfs_do_automount(struct dentry *mntpt)
>  			mnt = ERR_PTR(-EINVAL);
>  			break;
>  		}
> -		mnt = cifs_dfs_do_refmount(cifs_sb,
> +		mnt = cifs_dfs_do_refmount(mntpt, cifs_sb,
>  				full_path, referrals + i);
>  		cifs_dbg(FYI, "%s: cifs_dfs_do_refmount:%s ,
> mnt:%p\n",
>  			 __func__, referrals[i].node_name, mnt);
> diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
> index f17fcf89e18e..1e30f74a9527 100644
> --- a/fs/debugfs/inode.c
> +++ b/fs/debugfs/inode.c
> @@ -187,9 +187,9 @@ static const struct super_operations
> debugfs_super_operations = {
>  
>  static struct vfsmount *debugfs_automount(struct path *path)
>  {
> -	struct vfsmount *(*f)(void *);
> -	f = (struct vfsmount *(*)(void *))path->dentry->d_fsdata;
> -	return f(d_inode(path->dentry)->i_private);
> +	debugfs_automount_t f;
> +	f = (debugfs_automount_t)path->dentry->d_fsdata;
> +	return f(path->dentry, d_inode(path->dentry)->i_private);
>  }
>  
>  static const struct dentry_operations debugfs_dops = {
> @@ -504,7 +504,7 @@ EXPORT_SYMBOL_GPL(debugfs_create_dir);
>   */
>  struct dentry *debugfs_create_automount(const char *name,
>  					struct dentry *parent,
> -					struct vfsmount *(*f)(void
> *),
> +					debugfs_automount_t f,
>  					void *data)
>  {
>  	struct dentry *dentry = start_creating(name, parent);
> diff --git a/fs/namei.c b/fs/namei.c
> index 6fa3e9138fe4..da689c9c005e 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -1100,7 +1100,6 @@ static int follow_automount(struct path *path,
> struct nameidata *nd,
>  			    bool *need_mntput)
>  {
>  	struct vfsmount *mnt;
> -	const struct cred *old_cred;
>  	int err;
>  
>  	if (!path->dentry->d_op || !path->dentry->d_op->d_automount)
> @@ -1129,9 +1128,7 @@ static int follow_automount(struct path *path,
> struct nameidata *nd,
>  	if (nd->total_link_count >= 40)
>  		return -ELOOP;
>  
> -	old_cred = override_creds(&init_cred);
>  	mnt = path->dentry->d_op->d_automount(path);
> -	revert_creds(old_cred);
>  	if (IS_ERR(mnt)) {
>  		/*
>  		 * The filesystem is allowed to return -EISDIR here
> to indicate
> diff --git a/fs/namespace.c b/fs/namespace.c
> index 487ba30bb5c6..089a6b23135a 100644
> --- a/fs/namespace.c
> +++ b/fs/namespace.c
> @@ -989,6 +989,21 @@ vfs_kern_mount(struct file_system_type *type,
> int flags, const char *name, void
>  }
>  EXPORT_SYMBOL_GPL(vfs_kern_mount);
>  
> +struct vfsmount *
> +vfs_submount(const struct dentry *mountpoint, struct
> file_system_type *type,
> +	     const char *name, void *data)
> +{
> +	/* Until it is worked out how to pass the user namespace
> +	 * through from the parent mount to the submount don't
> support
> +	 * unprivileged mounts with submounts.
> +	 */
> +	if (mountpoint->d_sb->s_user_ns != &init_user_ns)
> +		return ERR_PTR(-EPERM);
> +
> +	return vfs_kern_mount(type, MS_SUBMOUNT, name, data);
> +}
> +EXPORT_SYMBOL_GPL(vfs_submount);
> +
>  static struct mount *clone_mnt(struct mount *old, struct dentry
> *root,
>  					int flag)
>  {
> @@ -2794,7 +2809,7 @@ long do_mount(const char *dev_name, const char
> __user *dir_name,
>  
>  	flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
> MS_BORN |
>  		   MS_NOATIME | MS_NODIRATIME | MS_RELATIME|
> MS_KERNMOUNT |
> -		   MS_STRICTATIME | MS_NOREMOTELOCK);
> +		   MS_STRICTATIME | MS_NOREMOTELOCK | MS_SUBMOUNT);
>  
>  	if (flags & MS_REMOUNT)
>  		retval = do_remount(&path, flags & ~MS_REMOUNT,
> mnt_flags,
> diff --git a/fs/nfs/namespace.c b/fs/nfs/namespace.c
> index 5551e8ef67fd..e49d831c4e85 100644
> --- a/fs/nfs/namespace.c
> +++ b/fs/nfs/namespace.c
> @@ -226,7 +226,7 @@ static struct vfsmount *nfs_do_clone_mount(struct
> nfs_server *server,
>  					   const char *devname,
>  					   struct nfs_clone_mount
> *mountdata)
>  {
> -	return vfs_kern_mount(&nfs_xdev_fs_type, 0, devname,
> mountdata);
> +	return vfs_submount(mountdata->dentry, &nfs_xdev_fs_type,
> devname, mountdata);
>  }
>  
>  /**
> diff --git a/fs/nfs/nfs4namespace.c b/fs/nfs/nfs4namespace.c
> index d21104912676..d8b040bd9814 100644
> --- a/fs/nfs/nfs4namespace.c
> +++ b/fs/nfs/nfs4namespace.c
> @@ -279,7 +279,7 @@ static struct vfsmount *try_location(struct
> nfs_clone_mount *mountdata,
>  				mountdata->hostname,
>  				mountdata->mnt_path);
>  
> -		mnt = vfs_kern_mount(&nfs4_referral_fs_type, 0,
> page, mountdata);
> +		mnt = vfs_submount(mountdata->dentry,
> &nfs4_referral_fs_type, page, mountdata);
>  		if (!IS_ERR(mnt))
>  			break;
>  	}
> diff --git a/fs/super.c b/fs/super.c
> index 1709ed029a2c..4185844f7a12 100644
> --- a/fs/super.c
> +++ b/fs/super.c
> @@ -469,7 +469,7 @@ struct super_block *sget_userns(struct
> file_system_type *type,
>  	struct super_block *old;
>  	int err;
>  
> -	if (!(flags & MS_KERNMOUNT) &&
> +	if (!(flags & (MS_KERNMOUNT|MS_SUBMOUNT)) &&
>  	    !(type->fs_flags & FS_USERNS_MOUNT) &&
>  	    !capable(CAP_SYS_ADMIN))
>  		return ERR_PTR(-EPERM);
> @@ -499,7 +499,7 @@ struct super_block *sget_userns(struct
> file_system_type *type,
>  	}
>  	if (!s) {
>  		spin_unlock(&sb_lock);
> -		s = alloc_super(type, flags, user_ns);
> +		s = alloc_super(type, (flags & ~MS_SUBMOUNT),
> user_ns);
>  		if (!s)
>  			return ERR_PTR(-ENOMEM);
>  		goto retry;
> @@ -540,8 +540,15 @@ struct super_block *sget(struct file_system_type
> *type,
>  {
>  	struct user_namespace *user_ns = current_user_ns();
>  
> +	/* We don't yet pass the user namespace of the parent
> +	 * mount through to here so always use &init_user_ns
> +	 * until that changes.
> +	 */
> +	if (flags & MS_SUBMOUNT)
> +		user_ns = &init_user_ns;
> +
>  	/* Ensure the requestor has permissions over the target
> filesystem */
> -	if (!(flags & MS_KERNMOUNT) && !ns_capable(user_ns,
> CAP_SYS_ADMIN))
> +	if (!(flags & (MS_KERNMOUNT|MS_SUBMOUNT)) &&
> !ns_capable(user_ns, CAP_SYS_ADMIN))
>  		return ERR_PTR(-EPERM);
>  
>  	return sget_userns(type, test, set, flags, user_ns, data);
> diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h
> index 014cc564d1c4..233006be30aa 100644
> --- a/include/linux/debugfs.h
> +++ b/include/linux/debugfs.h
> @@ -97,9 +97,10 @@ struct dentry *debugfs_create_dir(const char
> *name, struct dentry *parent);
>  struct dentry *debugfs_create_symlink(const char *name, struct
> dentry *parent,
>  				      const char *dest);
>  
> +typedef struct vfsmount *(*debugfs_automount_t)(struct dentry *,
> void *);
>  struct dentry *debugfs_create_automount(const char *name,
>  					struct dentry *parent,
> -					struct vfsmount *(*f)(void
> *),
> +					debugfs_automount_t f,
>  					void *data);
>  
>  void debugfs_remove(struct dentry *dentry);
> diff --git a/include/linux/mount.h b/include/linux/mount.h
> index c6f55158d5e5..8e0352af06b7 100644
> --- a/include/linux/mount.h
> +++ b/include/linux/mount.h
> @@ -90,6 +90,9 @@ struct file_system_type;
>  extern struct vfsmount *vfs_kern_mount(struct file_system_type
> *type,
>  				      int flags, const char *name,
>  				      void *data);
> +extern struct vfsmount *vfs_submount(const struct dentry
> *mountpoint,
> +				     struct file_system_type *type,
> +				     const char *name, void *data);
>  
>  extern void mnt_set_expiry(struct vfsmount *mnt, struct list_head
> *expiry_list);
>  extern void mark_mounts_for_expiry(struct list_head *mounts);
> diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
> index 36da93fbf188..048a85e9f017 100644
> --- a/include/uapi/linux/fs.h
> +++ b/include/uapi/linux/fs.h
> @@ -132,6 +132,7 @@ struct inodes_stat_t {
>  #define MS_LAZYTIME	(1<<25) /* Update the on-disk [acm]times
> lazily */
>  
>  /* These sb flags are internal to the kernel */
> +#define MS_SUBMOUNT     (1<<26)
>  #define MS_NOREMOTELOCK	(1<<27)
>  #define MS_NOSEC	(1<<28)
>  #define MS_BORN		(1<<29)
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index d7449783987a..310f0ea0d1a2 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -7503,7 +7503,7 @@ init_tracer_tracefs(struct trace_array *tr,
> struct dentry *d_tracer)
>  	ftrace_init_tracefs(tr, d_tracer);
>  }
>  
> -static struct vfsmount *trace_automount(void *ingore)
> +static struct vfsmount *trace_automount(struct dentry *mntpt, void
> *ingore)
>  {
>  	struct vfsmount *mnt;
>  	struct file_system_type *type;
> @@ -7516,7 +7516,7 @@ static struct vfsmount *trace_automount(void
> *ingore)
>  	type = get_fs_type("tracefs");
>  	if (!type)
>  		return NULL;
> -	mnt = vfs_kern_mount(type, 0, "tracefs", NULL);
> +	mnt = vfs_submount(mntpt, type, "tracefs", NULL);
>  	put_filesystem(type);
>  	if (IS_ERR(mnt))
>  		return NULL;

Yes. That looks like it might be workable.

Reviewed-by: Trond Myklebust <trond.myklebust@primarydata.com>
-- 
Trond Myklebust
Linux NFS client maintainer, PrimaryData
trond.myklebust@primarydata.com

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [REVIEW][PATCH] fs: Better permission checking for submounts
@ 2017-02-01 13:28                                 ` Trond Myklebust
  0 siblings, 0 replies; 19+ messages in thread
From: Trond Myklebust @ 2017-02-01 13:28 UTC (permalink / raw)
  To: ebiederm, seth.forshee
  Cc: bfields, anna.schumaker, Steve French, linux-nfs, dhowells,
	linux-fsdevel

T24gV2VkLCAyMDE3LTAyLTAxIGF0IDE5OjM4ICsxMzAwLCBFcmljIFcuIEJpZWRlcm1hbiB3cm90
ZToNCj4gVG8gc3VwcG9ydCB1bnByaXZpbGVnZWQgdXNlcnMgbW91bnRpbmcgZmlsZXN5c3RlbXMg
dHdvIHBlcm1pc3Npb24NCj4gY2hlY2tzIGhhdmUgdG8gYmUgcGVyZm9ybWVkOiBhIHRlc3QgdG8g
c2VlIGlmIHRoZSB1c2VyIGFsbG93ZWQgdG8NCj4gY3JlYXRlIGEgbW91bnQgaW4gdGhlIG1vdW50
IG5hbWVzcGFjZSwgYW5kIGEgdGVzdCB0byBzZWUgaWYNCj4gdGhlIHVzZXIgaXMgYWxsb3dlZCB0
byBhY2Nlc3MgdGhlIHNwZWNpZmllZCBmaWxlc3lzdGVtLg0KPiANCj4gVGhlIGF1dG9tb3VudCBj
YXNlIGlzIHN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hLmNvbT4NCi0tIA0KVHJvbmQgTXlrbGVidXN0DQpMaW51eCBORlMgY2xp
ZW50IG1haW50YWluZXIsIFByaW1hcnlEYXRhDQp0cm9uZC5teWtsZWJ1c3RAcHJpbWFyeWRhdGEu
Y29tDQo=


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [REVIEW][PATCH] fs: Better permission checking for submounts
  2017-02-01  6:38                             ` [REVIEW][PATCH] fs: Better permission checking for submounts Eric W. Biederman
  2017-02-01 13:28                                 ` Trond Myklebust
@ 2017-02-01 13:38                               ` Seth Forshee
  1 sibling, 0 replies; 19+ messages in thread
From: Seth Forshee @ 2017-02-01 13:38 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: Trond Myklebust, bfields, anna.schumaker, Steve French,
	linux-nfs, dhowells, linux-fsdevel

On Wed, Feb 01, 2017 at 07:38:17PM +1300, Eric W. Biederman wrote:
> 
> To support unprivileged users mounting filesystems two permission
> checks have to be performed: a test to see if the user allowed to
> create a mount in the mount namespace, and a test to see if
> the user is allowed to access the specified filesystem.
> 
> The automount case is special in that mounting the original filesystem
> grants permission to mount the sub-filesystems, to any user who
> happens to stumble across the their mountpoint and satisfies the
> ordinary filesystem permission checks.
> 
> Attempting to handle the automount case by using override_creds
> almost works.  It preserves the idea that permission to mount
> the original filesystem is permission to mount the sub-filesystem.
> Unfortunately using override_creds messes up the filesystems
> ordinary permission checks.
> 
> Solve this by being explicit that a mount is a submount by introducing
> vfs_submount, and using it where appropriate.
> 
> vfs_submount uses a new mount internal mount flags MS_SUBMOUNT, to let
> sget and friends know that a mount is a submount so they can take appropriate
> action.
> 
> sget and sget_userns are modified to not perform any permission checks
> on submounts.
> 
> follow_automount is modified to stop using override_creds as that
> has proven problemantic.
> 
> do_mount is modified to always remove the new MS_SUBMOUNT flag so
> that we know userspace will never by able to specify it.
> 
> autofs4 is modified to stop using current_real_cred that was put in
> there to handle the previous version of submount permission checking.
> 
> cifs is modified to pass the mountpoint all of the way down to vfs_submount.
> 
> debugfs is modified to pass the mountpoint all of the way down to
> trace_automount by adding a new parameter.  To make this change easier
> a new typedef debugfs_automount_t is introduced to capture the type of
> the debugfs automount function.
> 
> Cc: stable@vger.kernel.org
> Fixes: 069d5ac9ae0d ("autofs:  Fix automounts by using current_real_cred()->uid")
> Fixes: aeaa4a79ff6a ("fs: Call d_automount with the filesystems creds")
> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>

Looks good to me. I also got testing from the user who reported the bug
to us, and it does fix his nfs submount problem.

Reviewed-by: Seth Forshee <seth.forshee@canonical.com>

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2017-02-01 13:38 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-15 17:13 [PATCH] sunrpc: Use current_real_cred() when looking up rpc credentials Seth Forshee
2016-12-15 23:01 ` Trond Myklebust
2016-12-16 13:06   ` Seth Forshee
2017-01-10 14:55     ` Seth Forshee
2017-01-11  0:21       ` Eric W. Biederman
2017-01-24 15:17         ` Seth Forshee
2017-01-24 22:55           ` Eric W. Biederman
2017-01-24 23:28             ` Eric W. Biederman
2017-01-24 23:46               ` Trond Myklebust
2017-01-24 23:56                 ` Eric W. Biederman
2017-01-25  0:14                   ` Trond Myklebust
2017-01-25 14:52                     ` Seth Forshee
2017-01-25 15:51                       ` Trond Myklebust
2017-01-25 16:28                         ` Seth Forshee
2017-02-01  6:36                           ` Eric W. Biederman
2017-02-01  6:38                             ` [REVIEW][PATCH] fs: Better permission checking for submounts Eric W. Biederman
2017-02-01 13:28                               ` Trond Myklebust
2017-02-01 13:28                                 ` Trond Myklebust
2017-02-01 13:38                               ` Seth Forshee

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.