2012-05-29 13:32:06

by Steve Dickson

[permalink] [raw]
Subject: [PATCH] Honor the no_root_squash flag on pseudo roots.

If root squashing is turned off on a export that
has multiple directories, the parent directories
of the pseudo exports that's built, also needs to
have root squashing turned off.

Signed-off-by: Steve Dickson <[email protected]>
---
utils/mountd/v4root.c | 9 ++++++++-
1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/utils/mountd/v4root.c b/utils/mountd/v4root.c
index 708eb61..ad8a3e7 100644
--- a/utils/mountd/v4root.c
+++ b/utils/mountd/v4root.c
@@ -92,7 +92,14 @@ v4root_create(char *path, nfs_export *export)
exp = export_create(&eep, 0);
if (exp == NULL)
return NULL;
- xlog(D_CALL, "v4root_create: path '%s'", exp->m_export.e_path);
+ /*
+ * Honor the no_root_squash flag
+ */
+ if ((curexp->e_flags & NFSEXP_ROOTSQUASH) == 0)
+ exp->m_export.e_flags &= ~NFSEXP_ROOTSQUASH;
+ xlog(D_CALL, "v4root_create: path '%s' flags 0x%x",
+ exp->m_export.e_path, exp->m_export.e_flags);
+
return &exp->m_export;
}

--
1.7.7.6



2012-05-29 15:31:50

by Trond Myklebust

[permalink] [raw]
Subject: Re: [PATCH] Honor the no_root_squash flag on pseudo roots.

On Tue, 2012-05-29 at 09:07 -0400, Steve Dickson wrote:
> If root squashing is turned off on a export that
> has multiple directories, the parent directories
> of the pseudo exports that's built, also needs to
> have root squashing turned off.
>
> Signed-off-by: Steve Dickson <[email protected]>
> ---
> utils/mountd/v4root.c | 9 ++++++++-
> 1 files changed, 8 insertions(+), 1 deletions(-)
>
> diff --git a/utils/mountd/v4root.c b/utils/mountd/v4root.c
> index 708eb61..ad8a3e7 100644
> --- a/utils/mountd/v4root.c
> +++ b/utils/mountd/v4root.c
> @@ -92,7 +92,14 @@ v4root_create(char *path, nfs_export *export)
> exp = export_create(&eep, 0);
> if (exp == NULL)
> return NULL;
> - xlog(D_CALL, "v4root_create: path '%s'", exp->m_export.e_path);
> + /*
> + * Honor the no_root_squash flag
> + */
> + if ((curexp->e_flags & NFSEXP_ROOTSQUASH) == 0)
> + exp->m_export.e_flags &= ~NFSEXP_ROOTSQUASH;
> + xlog(D_CALL, "v4root_create: path '%s' flags 0x%x",
> + exp->m_export.e_path, exp->m_export.e_flags);
> +
> return &exp->m_export;
> }


As long as the user is authenticated, why do we care whether or not they
are squashed to user 'nobody' for authorisation purposes? There
shouldn't be any permission checks enforced on the pseudo-root, should
there?

Cheers
Trond


2012-05-29 16:29:41

by Myklebust, Trond

[permalink] [raw]
Subject: Re: [PATCH] Honor the no_root_squash flag on pseudo roots.

T24gVHVlLCAyMDEyLTA1LTI5IGF0IDExOjU1IC0wNDAwLCBTdGV2ZSBEaWNrc29uIHdyb3RlOg0K
PiANCj4gT24gMDUvMjkvMjAxMiAxMTowMCBBTSwgVHJvbmQgTXlrbGVidXN0IHdyb3RlOg0KPiA+
IE9uIFR1ZSwgMjAxMi0wNS0yOSBhdCAwOTowNyAtMDQwMCwgU3RldmUgRGlja3NvbiB3cm90ZToN
Cj4gPj4gSWYgcm9vdCBzcXVhc2hpbmcgaXMgdHVybmVkIG9mZiBvbiBhIGV4cG9ydCB0aGF0DQo+
ID4+IGhhcyBtdWx0aXBsZSBkaXJlY3RvcmllcywgdGhlIHBhcmVudCBkaXJlY3Rvcmllcw0KPiA+
PiBvZiB0aGUgcHNldWRvIGV4cG9ydHMgdGhhdCdzIGJ1aWx0LCBhbHNvIG5lZWRzIHRvDQo+ID4+
IGhhdmUgcm9vdCBzcXVhc2hpbmcgdHVybmVkIG9mZi4NCj4gPj4NCj4gPj4gU2lnbmVkLW9mZi1i
eTogU3RldmUgRGlja3NvbiA8c3RldmVkQHJlZGhhdC5jb20+DQo+ID4+IC0tLQ0KPiA+PiAgdXRp
bHMvbW91bnRkL3Y0cm9vdC5jIHwgICAgOSArKysrKysrKy0NCj4gPj4gIDEgZmlsZXMgY2hhbmdl
ZCwgOCBpbnNlcnRpb25zKCspLCAxIGRlbGV0aW9ucygtKQ0KPiA+Pg0KPi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Zmls
ZXN5c3RlbSB3YXMgdG8ganVzdCBwcm92aWRlIGEgbmFtZXNwYWNlIHRoYXQgYnJpZGdlcyBiZXR3
ZWVuDQphY3R1YWwgZXhwb3J0ZWQgZmlsZXN5c3RlbXMuDQpBcyBsb25nIGFzIEknbSBhdXRoZW50
aWNhdGVkIChpLmUuIG15IFJQQyBjcmVkZW50aWFsIG1hdGNoZXMgdGhlICdzZWM9Jw0KbGluZSBp
biAvZXRjL2V4cG9ydHMpLCB0aGVuIHdoeSBzaG91bGRuJ3QgSSBiZSBhYmxlIHRvICdjZCcNCmlu
dG8gL2hvbWUvc3RldmVkIGFuZCBydW4gYW4gJ2xzJz8NCg0KQ2hlZXJzDQogIFRyb25kDQotLSAN
ClRyb25kIE15a2xlYnVzdA0KTGludXggTkZTIGNsaWVudCBtYWludGFpbmVyDQoNCk5ldEFwcA0K
VHJvbmQuTXlrbGVidXN0QG5ldGFwcC5jb20NCnd3dy5uZXRhcHAuY29tDQoNCg==

2012-05-29 15:56:25

by Steve Dickson

[permalink] [raw]
Subject: Re: [PATCH] Honor the no_root_squash flag on pseudo roots.



On 05/29/2012 11:00 AM, Trond Myklebust wrote:
> On Tue, 2012-05-29 at 09:07 -0400, Steve Dickson wrote:
>> If root squashing is turned off on a export that
>> has multiple directories, the parent directories
>> of the pseudo exports that's built, also needs to
>> have root squashing turned off.
>>
>> Signed-off-by: Steve Dickson <[email protected]>
>> ---
>> utils/mountd/v4root.c | 9 ++++++++-
>> 1 files changed, 8 insertions(+), 1 deletions(-)
>>
>> diff --git a/utils/mountd/v4root.c b/utils/mountd/v4root.c
>> index 708eb61..ad8a3e7 100644
>> --- a/utils/mountd/v4root.c
>> +++ b/utils/mountd/v4root.c
>> @@ -92,7 +92,14 @@ v4root_create(char *path, nfs_export *export)
>> exp = export_create(&eep, 0);
>> if (exp == NULL)
>> return NULL;
>> - xlog(D_CALL, "v4root_create: path '%s'", exp->m_export.e_path);
>> + /*
>> + * Honor the no_root_squash flag
>> + */
>> + if ((curexp->e_flags & NFSEXP_ROOTSQUASH) == 0)
>> + exp->m_export.e_flags &= ~NFSEXP_ROOTSQUASH;
>> + xlog(D_CALL, "v4root_create: path '%s' flags 0x%x",
>> + exp->m_export.e_path, exp->m_export.e_flags);
>> +
>> return &exp->m_export;
>> }
>
>
> As long as the user is authenticated, why do we care whether or not they
> are squashed to user 'nobody' for authorisation purposes? There
> shouldn't be any permission checks enforced on the pseudo-root, should
> there?
>
The access checks come during the lookup of the pseudo-root.

For example
/home/steved/work *(rw,no_root_squash)

This is the export which causes mountd builds the pseudo-roots of
'/', '/home', and '/home/steved'

Now if the no_root_squash is not set on those pseudo-roots the
access bits returned by server will cause the lookup of
/home/steved/work to fail.

steved.


2012-05-29 19:19:06

by Steve Dickson

[permalink] [raw]
Subject: Re: [PATCH] Honor the no_root_squash flag on pseudo roots.



On 05/29/2012 09:07 AM, Steve Dickson wrote:
> If root squashing is turned off on a export that
> has multiple directories, the parent directories
> of the pseudo exports that's built, also needs to
> have root squashing turned off.
>
> Signed-off-by: Steve Dickson <[email protected]>
Committed...

steved.

> ---
> utils/mountd/v4root.c | 9 ++++++++-
> 1 files changed, 8 insertions(+), 1 deletions(-)
>
> diff --git a/utils/mountd/v4root.c b/utils/mountd/v4root.c
> index 708eb61..ad8a3e7 100644
> --- a/utils/mountd/v4root.c
> +++ b/utils/mountd/v4root.c
> @@ -92,7 +92,14 @@ v4root_create(char *path, nfs_export *export)
> exp = export_create(&eep, 0);
> if (exp == NULL)
> return NULL;
> - xlog(D_CALL, "v4root_create: path '%s'", exp->m_export.e_path);
> + /*
> + * Honor the no_root_squash flag
> + */
> + if ((curexp->e_flags & NFSEXP_ROOTSQUASH) == 0)
> + exp->m_export.e_flags &= ~NFSEXP_ROOTSQUASH;
> + xlog(D_CALL, "v4root_create: path '%s' flags 0x%x",
> + exp->m_export.e_path, exp->m_export.e_flags);
> +
> return &exp->m_export;
> }
>

2012-05-29 16:49:50

by Steve Dickson

[permalink] [raw]
Subject: Re: [PATCH] Honor the no_root_squash flag on pseudo roots.



On 05/29/2012 12:29 PM, Myklebust, Trond wrote:
> On Tue, 2012-05-29 at 11:55 -0400, Steve Dickson wrote:
>>
>> On 05/29/2012 11:00 AM, Trond Myklebust wrote:
>>> On Tue, 2012-05-29 at 09:07 -0400, Steve Dickson wrote:
>>>> If root squashing is turned off on a export that
>>>> has multiple directories, the parent directories
>>>> of the pseudo exports that's built, also needs to
>>>> have root squashing turned off.
>>>>
>>>> Signed-off-by: Steve Dickson <[email protected]>
>>>> ---
>>>> utils/mountd/v4root.c | 9 ++++++++-
>>>> 1 files changed, 8 insertions(+), 1 deletions(-)
>>>>
>>>> diff --git a/utils/mountd/v4root.c b/utils/mountd/v4root.c
>>>> index 708eb61..ad8a3e7 100644
>>>> --- a/utils/mountd/v4root.c
>>>> +++ b/utils/mountd/v4root.c
>>>> @@ -92,7 +92,14 @@ v4root_create(char *path, nfs_export *export)
>>>> exp = export_create(&eep, 0);
>>>> if (exp == NULL)
>>>> return NULL;
>>>> - xlog(D_CALL, "v4root_create: path '%s'", exp->m_export.e_path);
>>>> + /*
>>>> + * Honor the no_root_squash flag
>>>> + */
>>>> + if ((curexp->e_flags & NFSEXP_ROOTSQUASH) == 0)
>>>> + exp->m_export.e_flags &= ~NFSEXP_ROOTSQUASH;
>>>> + xlog(D_CALL, "v4root_create: path '%s' flags 0x%x",
>>>> + exp->m_export.e_path, exp->m_export.e_flags);
>>>> +
>>>> return &exp->m_export;
>>>> }
>>>
>>>
>>> As long as the user is authenticated, why do we care whether or not they
>>> are squashed to user 'nobody' for authorisation purposes? There
>>> shouldn't be any permission checks enforced on the pseudo-root, should
>>> there?
>>>
>> The access checks come during the lookup of the pseudo-root.
>>
>> For example
>> /home/steved/work *(rw,no_root_squash)
>>
>> This is the export which causes mountd builds the pseudo-roots of
>> '/', '/home', and '/home/steved'
>>
>> Now if the no_root_squash is not set on those pseudo-roots the
>> access bits returned by server will cause the lookup of
>> /home/steved/work to fail.
>
> If '/', '/home' and '/home/steved' aren't exported directories, then how
> can they have properties such as acls?
They don't. '/', '/home' and '/home/steved' are not being exported. Only
/home/steved/work is being exported in the namespace. So /home/steved/work
can have properties such as acls, but the components in the path can't.

If you wanted those to those type of properties on the path components,
you would have to explicitly export them.


> I thought the whole point of the
> pseudo-filesystem was to just provide a namespace that bridges between
> actual exported filesystems.
That's exactly what happens....

> As long as I'm authenticated (i.e. my RPC credential matches the 'sec='
> line in /etc/exports), then why shouldn't I be able to 'cd'
> into /home/steved and run an 'ls'?
And you can. But all you are going to see is the exported directory, in
this case 'work'. For example: say you mount '/' on /mnt and do an ls.
This would be the tree:

# ls /mnt
./ ../ home/
# ls /mnt/work/home
./ ../ steved/
# ls /mnt/work/home/steved
./ ../ work/

steved.

2012-05-29 15:31:28

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [PATCH] Honor the no_root_squash flag on pseudo roots.

On Tue, May 29, 2012 at 09:07:16AM -0400, Steve Dickson wrote:
> If root squashing is turned off on a export that
> has multiple directories, the parent directories
> of the pseudo exports that's built, also needs to
> have root squashing turned off.
>
> Signed-off-by: Steve Dickson <[email protected]>
> ---
> utils/mountd/v4root.c | 9 ++++++++-
> 1 files changed, 8 insertions(+), 1 deletions(-)
>
> diff --git a/utils/mountd/v4root.c b/utils/mountd/v4root.c
> index 708eb61..ad8a3e7 100644
> --- a/utils/mountd/v4root.c
> +++ b/utils/mountd/v4root.c
> @@ -92,7 +92,14 @@ v4root_create(char *path, nfs_export *export)
> exp = export_create(&eep, 0);
> if (exp == NULL)
> return NULL;
> - xlog(D_CALL, "v4root_create: path '%s'", exp->m_export.e_path);
> + /*
> + * Honor the no_root_squash flag
> + */
> + if ((curexp->e_flags & NFSEXP_ROOTSQUASH) == 0)
> + exp->m_export.e_flags &= ~NFSEXP_ROOTSQUASH;
> + xlog(D_CALL, "v4root_create: path '%s' flags 0x%x",
> + exp->m_export.e_path, exp->m_export.e_flags);
> +

Whoops, good catch.

But the right place to put this is in set_pseudofs_security(), as
follows (untested).

Otherwise you'll run into the same problem in cases where subdirectories
have a mixture of root_squash and no_root_squash set.

--b.

diff --git a/utils/mountd/v4root.c b/utils/mountd/v4root.c
index 81f813b..76bda37 100644
--- a/utils/mountd/v4root.c
+++ b/utils/mountd/v4root.c
@@ -61,6 +61,8 @@ void set_pseudofs_security(struct exportent *pseudo, struct exportent *source)

if (source->e_flags & NFSEXP_INSECURE_PORT)
pseudo->e_flags |= NFSEXP_INSECURE_PORT;
+ if (source->e_flags & NFSEXP_ROOTSQUASH == 0)
+ pseudo->e_flags &= ~NFSEXP_ROOTSQUASH;
for (se = source->e_secinfo; se->flav; se++) {
struct sec_entry *new;