sunrpc: Use current_real_cred() when looking up rpc credentials
Subsystems (7)
PATCH 1/1 sunrpc: Use current_real_cred() when looking up rpc credentials
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.
--- net/sunrpc/auth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sunrpc/auth.c +1 -1
@@ -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);
Signature · 1 line
2.7.4
T24gVGh1LCAyMDE2LTEyLTE1IGF0IDExOjEzIC0wNjAwLCBTZXRoIEZvcnNoZWUgd3JvdGU6DQo+ IFNpbmNlIDQuOCBmb2xsb3dfYXV0b21vdW50KCkgb3ZlcnJpZGVzIHRoZSBjcmVkZW50aWFscyB3 aXRoDQo+ICZpbml0X2NyZWQgYmVmb3JlIGNhbGxpbmcgZF9hdXRvbW91bnQoKS4gV2hlbg0KPiBy cGNhdXRoX2xvb2t1cGNyZWQoKSBpcyBjYWxsZWQgaW4gdGhpcyBjb250ZXh0IGl0IGlzIG5vdyB1 c2luZw0KPiBmc1t1Z11pZCBmcm9tIHRoZSBvdmVycmlkZSBjcmVkcyBpbnN0ZWFkIG9mIGZyb20g dGhlIHVzZXIncw0KPiBjcmVkcywgd2hpY2ggY2FuIGNhdXNlIGF1dGhlbnRpY2F0aW9uIHRvIGZh aWwuIFRvIGZpeCB0aGlzLCB0YWtlDQo+IHRoZSBpZHMgZnJvbSBjdXJyZW50X3JlYWxfY3JlZCgp IGluc3RlYWQuDQo+IA0KPiBDYzogc3RhYmxlQHZnZXIua2VybmVsLm9yZyAjIHY0LjgrDQo+IEND OiBFcmljIFcuIEJpZWRlcm1hbiA8ZWJpZWRl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XQncw0KY29tcGxldGVseSB0aGUgd3JvbmcgbGV2ZWwg aW4gd2hpY2ggdG8gb3ZlcnJpZGUgY3JlZGVudGlhbHMuDQoNCi0tIA0KVHJvbmQgTXlrbGVidXN0 DQpMaW51eCBORlMgY2xpZW50IG1haW50YWluZXIsIFByaW1hcnlEYXRhDQp0cm9uZC5teWtsZWJ1 c3RAcHJpbWFyeWRhdGEuY29tDQo=
Quoted 17 lines · Trond Myklebust
Quoted 16 lines · Seth Forshee
Since 4.8
follow_automount()overrides the credentials with&init_credbefore callingd_automount(). Whenrpcauth_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 fromcurrent_real_cred()instead.Cc [email protected] # v4.8+CC Eric W. Biederman <[email protected]>Fixes aeaa4a79ff6a ("fs: Call d_automount with the filesystemscreds")
Signed-off-by Seth Forshee <[email protected]>---
net/sunrpc/auth.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
Quoted 11 lines
net/sunrpc/auth.c +1
-1@@ -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 ();Quoted 3 lines
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.
Quoted 1 line
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
Quoted 47 lines · Seth Forshee
Quoted 17 lines · Trond Myklebust
Quoted 16 lines · Seth Forshee
Since 4.8
follow_automount()overrides the credentials with&init_credbefore callingd_automount(). Whenrpcauth_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 fromcurrent_real_cred()instead.Cc [email protected] # v4.8+CC Eric W. Biederman <[email protected]>Fixes aeaa4a79ff6a ("fs: Call d_automount with the filesystemscreds")
Signed-off-by Seth Forshee <[email protected]>---
net/sunrpc/auth.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)Quoted 16 lines
Quoted 11 lines
net/sunrpc/auth.c +1
-1@@ -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 ();Quoted 3 lines
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.
Quoted 1 line
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 haveCAP_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.
Quoted 7 lines
- 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
Quoted 54 lines · Seth Forshee
Quoted 53 lines · Seth Forshee
Quoted 17 lines · Trond Myklebust
Quoted 16 lines · Seth Forshee
Since 4.8
follow_automount()overrides the credentials with&init_credbefore callingd_automount(). Whenrpcauth_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 fromcurrent_real_cred()instead.Cc [email protected] # v4.8+CC Eric W. Biederman <[email protected]>Fixes aeaa4a79ff6a ("fs: Call d_automount with the filesystemscreds")
Signed-off-by Seth Forshee <[email protected]>---
net/sunrpc/auth.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)Quoted 16 lines
Quoted 11 lines
net/sunrpc/auth.c +1
-1@@ -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 ();Quoted 3 lines
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.
Quoted 1 line
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 haveCAP_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.
Quoted 8 lines
Quoted 1 line
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_credoverridden 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
Quoted 65 lines · Eric W. Biederman
Quoted 54 lines · Seth Forshee
Quoted 53 lines · Seth Forshee
Quoted 17 lines · Trond Myklebust
Quoted 16 lines · Seth Forshee
Since 4.8
follow_automount()overrides the credentials with&init_credbefore callingd_automount(). Whenrpcauth_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 fromcurrent_real_cred()instead.Cc [email protected] # v4.8+CC Eric W. Biederman <[email protected]>Fixes aeaa4a79ff6a ("fs: Call d_automount with the filesystemscreds")
Signed-off-by Seth Forshee <[email protected]>---
net/sunrpc/auth.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)Quoted 16 lines
Quoted 11 lines
net/sunrpc/auth.c +1
-1@@ -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 ();Quoted 3 lines
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.
Quoted 1 line
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 haveCAP_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.Quoted 8 lines
Quoted 1 line
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_credoverridden as we're doing for automount.
Quoted 8 lines
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
Quoted 80 lines · Seth Forshee
Quoted 65 lines · Eric W. Biederman
Quoted 54 lines · Seth Forshee
Quoted 53 lines · Seth Forshee
Quoted 17 lines · Trond Myklebust
Quoted 16 lines · Seth Forshee
Since 4.8
follow_automount()overrides the credentials with&init_credbefore callingd_automount(). Whenrpcauth_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 fromcurrent_real_cred()instead.Cc [email protected] # v4.8+CC Eric W. Biederman <[email protected]>Fixes aeaa4a79ff6a ("fs: Call d_automount with the filesystemscreds")
Signed-off-by Seth Forshee <[email protected]>---
net/sunrpc/auth.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)Quoted 16 lines
Quoted 11 lines
net/sunrpc/auth.c +1
-1@@ -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 ();Quoted 3 lines
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.
Quoted 1 line
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 haveCAP_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.Quoted 8 lines
Quoted 1 line
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_credoverridden as we're doing for automount.Quoted 8 lines
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_automountwith the filesystems creds" did, but it's overriding the credentials too early in the call stack and causing these rpcauth problems.
Quoted 5 lines
But I think we should also be setting the submount's
s_user_nsto be the same as the parent's, not tocurrent_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.
Quoted 5 lines
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
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
T24gV2VkLCAyMDE3LTAxLTI1IGF0IDEyOjI4ICsxMzAwLCBFcmljIFcuIEJpZWRlcm1hbiB3cm90 ZToNCj4gV2l0aCByZXNwZWN0IHRvIG5mcyBhbmQgYXV0b21vdW50cy4NCj4gDQo+IERvZXMgTkZT IGhhdmUgZGlmZmVyZW50IGF1dG9tb3VudCBiZWhhdmlvciBiYXNlZCBvbiB0aGUgdXNlcg0KPiBw ZXJmb3JtaW5nIHRoZSBhdXRvbW91bnQ/DQo+IA0KPiBJZiBORlMgZG9lcyBub3QgaGF2ZSBkaWZm ZXJlbnQgYXV0b21vdW50IGJlaGF2aW9yIGRlcGVuZGluZyBvbiB0aGUNCj4gdXNlcg0KPiB3ZSBq dXN0IHVzZSB0aGUgY3JlZHMgb2YgdGhlIG9yaWdpbmFsIG1vdW50ZXIgb2YgTkZTPw0KPiANCj4g SWYgTkZTIGRvZXMgaGF2ZSBkaWZmZXJlbnQgYXV0b21vdW50IGJlaGF2aW9yIGRlcGVuZGluZyBv biB0aGUgdXNlcg0KPiAob3VjaCEpIHdlIG5lZWQgdG8gZ28gdGhyb3VnaCB0aGUgY2FsbCBwYXRo IGFuZCBzZWUgd2hlcmUgaXQgbWFrZXMNCj4gc2Vuc2UgdG8gb3ZlciByaWRlIHRoaW5ncyBhbmQg d2hlcmUgaXQgZG9lcyBub3QuDQoNClRoZSByZWFzb24gd2h5IHRoZSBORlMgY2xpZW50IGNyZWF0 ZXMgYSBtb3VudHBvaW50IGlzIGJlY2F1c2Ugb24NCmVudGVyaW5nIGEgZGlyZWN0b3J5LCBpdCBk ZXRlY3RzIHRoYXQgdGhlcmUgaXMgZWl0aGVyIGEgc2ltaWxhcg0KbW91bnRwb2ludCBvbiB0aG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KVGhlIHNlY3VyaXR5IG1vZGVsIGlzIHRoZSBz YW1lIGFzIHRoYXQgb2YgYW4gb3JkaW5hcnkgZGlyZWN0b3J5LiBUaGUNCm9ubHkgZGlmZmVyZW5j ZSBpcyB0aGF0IHdlIGNyZWF0ZSBhIG5ldyBzdXBlcmJsb2NrLiBXaHkgaXMgdGhhdCAiSWNrIj8N Cg0KLS0gDQpUcm9uZCBNeWtsZWJ1c3QNCkxpbnV4IE5GUyBjbGllbnQgbWFpbnRhaW5lciwgUHJp bWFyeURhdGENCnRyb25kLm15a2xlYnVzdEBwcmltYXJ5ZGF0YS5jb20NCg==
Quoted 22 lines · Trond Myklebust
Quoted 5 lines · Eric W. Biederman
With respect to nfs and automounts.
Does NFS have different automount behavior based on the user performing the automount?
Quoted 7 lines
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.
Quoted 3 lines
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.
Quoted 14 lines
Quoted 14 lines
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_automountfrom:old_cred = override_creds(&init_cred); mnt = path->dentry->d_op->d_automount(path); revert_creds(old_cred);to:
Quoted 7 lines
Quoted 5 lines
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.
Quoted 12 lines
Quoted 11 lines
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!
Quoted 2 lines
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
QWRkaW5nIERhdmlkIEhvd2VsbHMgYW5kIFN0ZXZlIEZyZW5jaCBhcyBJIGJlbGlldmUgYm90aCBB RlMgYW5kIENJRlMNCmhhdmUgdGhlIGV4YWN0IHNhbWUgcmVxdWlyZW1lbnRzIGFuZCBORlMgaGVy ZS4NCg0KT24gV2VkLCAyMDE3LTAxLTI1IGF0IDEyOjU2ICsxMzAwLCBFcmljIFcuIEJpZWRlcm1h biB3cm90ZToNCj4gVHJvbmQgTXlrbGVidXN0IDx0cm9uZG15QHByaW1hcnlkYXRhLmNvbT4gd3Jp dGVzOg0KPiANCj4gPiBPbiBXZWQsIDIwMTctMDEtMjUgYXQgMTI6MjggKzEzMDAsIEVyaWMgVy4g QmllZGVybWFuIHdyb3RlOg0KPiA+ID4gV2l0aCByZXNwZWN0IHRvIG5mcyBhbmQgYXV0b21vdW50 cy4NCj4gPiA+IA0KPiA+ID4gRG9lcyBORlMgaGF2ZSBkaWZmZXJlbnQgYXV0b21vdW50IGJlaGF2 aW9yIGJhc2VkIG9uIHRoZSB1c2VyDQo+ID4gPiBwZXJmb3JtaW5nIHRoZSBhdXRvbW91bnQ/DQo+ ID4gPiANCj4gPiA+IElmIE5GUyBkb2VzIG5vdCBoYXZlIGRpZmZlcmVudCBhdXRvbW91bnQgYmVo YXZpb3IgZGVwZW5kaW5nIG9uDQo+ID4gPiB0aGUNCj4gPi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bW91bnRwb2ludC4NCj4gDQo+IEFLQSBEbyB3ZSBnZXQg YSBkaWZmZXJlbnQgbW91bnRwb2ludCBpZiB1c2VyIEEgdHJpZ2dlcnMgdGhlIGF1dG9tb3VudA0K PiB2cyB1c2VyIEIgdHJpZ2dlcmluZyB0aGUgYXV0b21vdW50Pw0KDQpZb3UgbWF5IGdldCBhbiBF QUNDRVMuIE90aGVyd2lzZSB0aGUgbW91bnRwb2ludHMgc2hvdWxkIGJlIHRoZSBzYW1lLg0KDQo+ IElmIHRoZSBwcm9ibGVtIGlzIGp1c3Qgcm9vdCBzcXVhc2ggYW5kIG5vdCBsZXR0aW5nIHJvb3Qg dHJpZ2dlciB0aGUNCj4gYXV0b21vdW50IGl0IGlzIG11Y2ggbGVzcyBpY2suwqDCoFdlaXJkIGJ1 dCBub3QgaWNrLg0KDQpOb3QganVzdCByb290IHNxdWFzaCwgYnV0IGdlbmVyYWwgcGVybWlzc2lv bnMgY2hlY2tpbmcuIFdlIGRvbid0IHdhbnQNCnRvIGdpdmUgdXNlciBCIHJvb3QgcHJpdmlsZWdl cyBhbGxvd2luZyBjcm9zc2luZyBpbnRvIGEgZGlyZWN0b3J5IHRvDQp3aGljaCBzL2hlIHdvdWxk IG9yZGluYXJpbHkgaGF2ZSBubyByaWdodHMgZWl0aGVyLg0KDQotLSANClRyb25kIE15a2xlYnVz dA0KTGludXggTkZTIGNsaWVudCBtYWludGFpbmVyLCBQcmltYXJ5RGF0YQ0KdHJvbmQubXlrbGVi dXN0QHByaW1hcnlkYXRhLmNvbQ0K
Quoted 45 lines · Trond Myklebust
Adding David Howells and Steve French as I believe both AFS and CIFS have the exact same requirements and NFS here.
Quoted 41 lines · Eric W. Biederman
Quoted 28 lines · Trond Myklebust
Quoted 10 lines · Eric W. Biederman
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?Quoted 5 lines
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.Quoted 5 lines
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.
Quoted 35 lines
Quoted 3 lines
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.
Quoted 26 lines
Quoted 15 lines
Quoted 15 lines
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_automountfrom:old_cred = override_creds(&init_cred); mnt = path->dentry->d_op->d_automount(path); revert_creds(old_cred);to:
Quoted 7 lines
Quoted 5 lines
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_automountbecause 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.
fs/afs/mntpt.c +1 -1
@@ -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);
fs/cifs/cifs_dfs_ref.c +4 -3
@@ -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);
fs/debugfs/inode.c +4 -4
@@ -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);
fs/namespace.c +15 -0
@@ -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) {
fs/nfs/namespace.c +3 -3
@@ -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:
fs/super.c +2 -0
@@ -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;
include/linux/debugfs.h +2 -2
@@ -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 );
include/linux/fs.h +3 -0
@@ -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.
include/linux/mount.h +3 -0
@@ -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);
kernel/trace/trace.c +2 -2
@@ -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 ;
T24gV2VkLCAyMDE3LTAxLTI1IGF0IDA4OjUyIC0wNjAwLCBTZXRoIEZvcnNoZWUgd3JvdGU6DQo+ IE9uIFdlZCwgSmFuIDI1LCAyMDE3IGF0IDEyOjE0OjI2QU0gKzAwMDAsIFRyb25kIE15a2xlYnVz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VudCk7DQo+IMKgDQo+ICtzdHJ1Y3Qg dmZzbW91bnQgKg0KPiArdmZzX2tlcm5fYXV0b21vdW50KHN0cnVjdCBkZW50cnkgKmRlbnRyeSwg c3RydWN0IGZpbGVfc3lzdGVtX3R5cGUNCj4gKnR5cGUsDQo+ICsJCcKgwqDCoGludCBmbGFncywg Y29uc3QgY2hhciAqbmFtZSwgdm9pZCAqZGF0YSkNCj4gK3sNCj4gKwljb25zdCBzdHJ1Y3QgY3Jl ZCAqb2xkX2NyZWQ7DQo+ICsJc3RydWN0IHZmc21vdW50ICptbnQ7DQo+ICsNCj4gKwlvbGRfY3Jl ZCA9IG92ZXJyaWRlX2NyZWRzKGRlbnRyeS0+ZF9zYi0+c19jcmVkKTsNCj4gKwltbnQgPSB2ZnNf a2Vybl9tb3VudCh0eXBlLCBmbGFncywgbmFtZSwgZGF0YSk7DQo+ICsJcmV2ZXJ0X2NyZWRzKG9s ZF9jcmVkKTsNCj4gKw0KPiArCXJldHVybiBtbnQ7DQo+ICt9DQo+ICtFWFBPUlRfU1lNQk9MX0dQ TCh2ZnNfa2Vybl9hdXRvbW91bnQpOw0KPiArDQoNCk5vcGUuIEFzIEkgc2FpZCwgdGhlIGNhbGwg aW50byB0aGUgZmlsZXN5c3RlbSBuZWVkcyB0aGUgX3VzZXJfIGNyZWRzLg0KDQotLSA=
Quoted 122 lines · Trond Myklebust
Quoted 121 lines · Seth Forshee
Quoted 58 lines · Trond Myklebust
Adding David Howells and Steve French as I believe both AFS and CIFS
have the exact same requirements and NFS here.Quoted 44 lines · Eric W. Biederman
Quoted 35 lines · Trond Myklebust
Quoted 11 lines · Eric W. Biederman
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?Quoted 6 lines
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.Quoted 6 lines
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.Quoted 8 lines
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.Quoted 34 lines
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.Quoted 28 lines
Quoted 17 lines
Quoted 17 lines
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:
Quoted 7 lines
Quoted 5 lines
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_automountbecause 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 callsvfs_kern_mount().Only compile tested so far, and probably it should be split up into several patches.
fs/namespace.c +0
-0@@ -989,6 +989,21 @@ vfs_kern_mount(struct file_system_type *type,int flags, const char *name, void
}
EXPORT_SYMBOL_GPL(vfs_kern_mount);fs/namespace.c +2
-0+struct vfsmount * +vfs_kern_automount(struct dentry *dentry, struct file_system_type*type,
fs/namespace.c +7
-0+ 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);
Quoted 8 lines
fs/namespace.c vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void · line 1006
Quoted 6 lines
fs/namespace.c +6
-0+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
Quoted 132 lines · Seth Forshee
Quoted 122 lines · Trond Myklebust
Quoted 121 lines · Seth Forshee
Quoted 58 lines · Trond Myklebust
Adding David Howells and Steve French as I believe both AFS and CIFS
have the exact same requirements and NFS here.Quoted 44 lines · Eric W. Biederman
Quoted 35 lines · Trond Myklebust
Quoted 11 lines · Eric W. Biederman
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?Quoted 6 lines
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.Quoted 6 lines
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.Quoted 8 lines
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.Quoted 34 lines
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.Quoted 28 lines
Quoted 17 lines
Quoted 17 lines
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:
Quoted 7 lines
Quoted 5 lines
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_automountbecause 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 callsvfs_kern_mount().Only compile tested so far, and probably it should be split up into several patches.
fs/namespace.c +0
-0@@ -989,6 +989,21 @@ vfs_kern_mount(struct file_system_type *type,int flags, const char *name, void
}
EXPORT_SYMBOL_GPL(vfs_kern_mount);fs/namespace.c +2
-0+struct vfsmount * +vfs_kern_automount(struct dentry *dentry, struct file_system_type*type,
fs/namespace.c +7
-0+ 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);Quoted 8 lines
fs/namespace.c vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void · line 1006
Quoted 6 lines
fs/namespace.c +6
-0+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.
Quoted 3 lines
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
PATCH 1/1 fs: Better permission checking for submounts
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.
--- 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(-)
fs/afs/mntpt.c +1 -1
@@ -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);
fs/autofs4/waitq.c +2 -2
@@ -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 */
fs/cifs/cifs_dfs_ref.c +4 -3
@@ -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);
fs/debugfs/inode.c +4 -4
@@ -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);
fs/namei.c +0 -3
@@ -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
fs/namespace.c +16 -1
@@ -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,
fs/nfs/namespace.c +1 -1
@@ -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); }/**
fs/nfs/nfs4namespace.c +1 -1
@@ -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 ; }
fs/super.c +10 -3
@@ -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);
include/linux/debugfs.h +2 -1
@@ -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);
include/linux/mount.h +3 -0
@@ -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);
include/uapi/linux/fs.h +1 -0
@@ -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)
kernel/trace/trace.c +2 -2
@@ -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 ;
Signature · 1 line
2.10.1
Re: [REVIEW][PATCH] fs: Better permission checking for submounts
Quoted 391 lines · Eric W. Biederman
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_credsalmost works. It preserves the idea that permission to mount the original filesystem is permission to mount the sub-filesystem. Unfortunately usingoverride_credsmesses 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_submountuses a new mount internal mount flagsMS_SUBMOUNT, to let
sget and friends know that a mount is a submount so they can take appropriate
action.sget and
sget_usernsare modified to not perform any permission checks
on submounts.
follow_automountis modified to stop usingoverride_credsas that has proven problemantic.
do_mountis modified to always remove the newMS_SUBMOUNTflag so that we know userspace will never by able to specify it.autofs4 is modified to stop using
current_real_credthat 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_automountby adding a new parameter. To make this change easier
a new typedefdebugfs_automount_tis introduced to capture the type of
the debugfs automount function.Fixes 069d5ac9ae0d ("autofs: Fix automounts by usingcurrent_real_cred()->uid")
Fixes aeaa4a79ff6a ("fs: Call d_automount with the filesystemscreds")
Signed-off-by "Eric W. Biederman" <[email protected]>---
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(-)fs/afs/mntpt.c +0
-0@@ -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);fs/afs/mntpt.c +1
-1- 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);fs/autofs4/waitq.c +2
-2@@ -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 */fs/cifs/cifs_dfs_ref.c +2
-1@@ -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;fs/cifs/cifs_dfs_ref.c +0
-0@@ -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;fs/cifs/cifs_dfs_ref.c +1
-1- 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;fs/cifs/cifs_dfs_ref.c +1
-1@@ -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);fs/debugfs/inode.c +0
-0@@ -187,9 +187,9 @@ static const struct super_operations debugfs_super_operations = {
static struct vfsmount *debugfs_automount(struct path *path) {fs/debugfs/inode.c +3
-3-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 structdentry_operationsdebugfs_dops= {fs/debugfs/inode.c +1
-1@@ -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);fs/namei.c +0
-1@@ -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)fs/namei.c +0
-0@@ -1129,9 +1128,7 @@ static int follow_automount(struct path *path, struct nameidata *nd, if (nd->total_link_count >= 40) return -ELOOP;fs/namei.c +0
-1- old_cred =override_creds (&init_cred);mnt =
path->dentry->d_op->d_automount(path);fs/namei.c +0
-1-revert_creds (old_cred);if (
IS_ERR(mnt)) {
/*
* The filesystem is allowed to return-EISDIRhere to indicatefs/namespace.c +0
-0@@ -989,6 +989,21 @@ vfs_kern_mount(struct file_system_type *type,int flags, const char *name, void
}
EXPORT_SYMBOL_GPL(vfs_kern_mount);fs/namespace.c +2
-0+struct vfsmount * +vfs_submount(const struct dentry *mountpoint, struct
file_system_type*type,fs/namespace.c +4
-0+ 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
fs/namespace.c +9
-0+* 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)
{fs/namespace.c +0
-0@@ -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|fs/namespace.c +1
-1- MS_STRICTATIME | MS_NOREMOTELOCK); + MS_STRICTATIME | MS_NOREMOTELOCK | MS_SUBMOUNT);
if (flags &MS_REMOUNT)
retval = do_remount(&path, flags & ~MS_REMOUNT,mnt_flags,fs/nfs/namespace.c +0
-0@@ -226,7 +226,7 @@ static struct vfsmount *nfs_do_clone_mount(structnfs_server *server, const char *devname,struct
nfs_clone_mount*mountdata)
{fs/nfs/namespace.c +0
-1- return vfs_kern_mount(&nfs_xdev_fs_type, 0, devname,mountdata);
fs/nfs/namespace.c +1
-0+ return vfs_submount(mountdata->dentry, &nfs_xdev_fs_type,devname, mountdata);
}
/**fs/nfs/nfs4namespace.c +0
-0@@ -279,7 +279,7 @@ static struct vfsmount *try_location(structnfs_clone_mount *mountdata, mountdata->hostname, mountdata->mnt_path);fs/nfs/nfs4namespace.c +0
-1- mnt = vfs_kern_mount(&nfs4_referral_fs_type, 0,page, mountdata);
fs/nfs/nfs4namespace.c +1
-0+ mnt = vfs_submount(mountdata->dentry,
&nfs4_referral_fs_type, page, mountdata);
if (!IS_ERR(mnt))
break;
}fs/super.c +0
-0@@ -469,7 +469,7 @@ struct super_block *sget_userns(struct file_system_type *type, struct super_block *old; int err;fs/super.c +1
-1- if (!(flags & MS_KERNMOUNT) && + if (!(flags & (MS_KERNMOUNT|MS_SUBMOUNT)) &&!(type->fs_flags &
FS_USERNS_MOUNT) && !capable(CAP_SYS_ADMIN)) returnERR_PTR(-EPERM);fs/super.c +1
-1@@ -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;fs/super.c +0
-0@@ -540,8 +540,15 @@ struct super_block *sget(struct file_system_type *type, { struct user_namespace *user_ns = current_user_ns();fs/super.c +7
-0+/* 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 */
fs/super.c +0
-1- if (!(flags & MS_KERNMOUNT) && !ns_capable(user_ns,
CAP_SYS_ADMIN))fs/super.c +1
-0+ if (!(flags & (MS_KERNMOUNT|MS_SUBMOUNT)) &&!ns_capable(user_ns,
CAP_SYS_ADMIN))
returnERR_PTR(-EPERM);
returnsget_userns(type, test, set, flags, user_ns, data);include/linux/debugfs.h +0
-0@@ -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,include/linux/debugfs.h +0
-1- struct vfsmount *(*f)(void*),
include/linux/debugfs.h +1
-0+ debugfs_automount_t f,void *data);
voiddebugfs_remove(struct dentry *dentry);include/linux/mount.h +0
-0@@ -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,include/linux/mount.h +2
-0+ struct file_system_type *type, + const char *name, void *data);
extern voidmnt_set_expiry(struct vfsmount *mnt, struct list_head *expiry_list);
extern voidmark_mounts_for_expiry(struct list_head *mounts);include/uapi/linux/fs.h +0
-0@@ -132,6 +132,7 @@ struct inodes_stat_t { #define MS_LAZYTIME (1<<25) /* Update the on-disk [acm]timeslazily */
/* These sb flags are internal to the kernel */
+#define MS_SUBMOUNT (1<<26)
#defineMS_NOREMOTELOCK(1<<27)
#defineMS_NOSEC(1<<28)
#defineMS_BORN(1<<29)kernel/trace/trace.c +0
-0@@ -7503,7 +7503,7 @@ init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer) ftrace_init_tracefs(tr, d_tracer); }kernel/trace/trace.c +1
-1-static struct vfsmount *trace_automount (void *ingore) +static struct vfsmount *trace_automount(struct dentry *mntpt, void*ingore)
{
struct vfsmount *mnt;
structfile_system_type*type;kernel/trace/trace.c +1
-1@@ -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))
Quoted 1 line
return NULL;
Yes. That looks like it might be workable.
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, PrimaryData [email protected]
Re: [REVIEW][PATCH] fs: Better permission checking for submounts
In reply to Eric W. BiedermanQuoted 43 lines · Eric W. Biederman
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_credsalmost works. It preserves the idea that permission to mount the original filesystem is permission to mount the sub-filesystem. Unfortunately usingoverride_credsmesses 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_submountuses a new mount internal mount flagsMS_SUBMOUNT, to let sget and friends know that a mount is a submount so they can take appropriate action.sget and
sget_usernsare modified to not perform any permission checks on submounts.
follow_automountis modified to stop usingoverride_credsas that has proven problemantic.
do_mountis modified to always remove the newMS_SUBMOUNTflag so that we know userspace will never by able to specify it.autofs4 is modified to stop using
current_real_credthat 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_automountby adding a new parameter. To make this change easier a new typedefdebugfs_automount_tis introduced to capture the type of the debugfs automount function.
Quoted 4 lines
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" <[email protected]>
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.