linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [nfs-utils PATCH] Don't allow junction tests to trigger automounts
@ 2022-12-13 16:01 Jeff Layton
  2022-12-13 16:25 ` Chuck Lever III
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jeff Layton @ 2022-12-13 16:01 UTC (permalink / raw)
  To: steved; +Cc: linux-nfs, Chuck Lever, JianHong Yin

JianHong reported some strange behavior with automounts on an nfs server
without an explicit pseudoroot. When clients issued a readdir in the
pseudoroot, automounted directories that were not yet mounted would show
up even if they weren't exported, though the clients wouldn't be able to
do anything with them.

The issue was that triggering the automount on a directory would cause
the mountd upcall to time out, which would cause nfsd to include the
automounted dentry in the readdir response. Eventually, the automount
would work and report that it wasn't exported and subsequent attempts to
access the dentry would (properly) fail.

We never want mountd to trigger an automount. The kernel should do that
if it wants to use it. Change the junction checks to do an O_PATH open
and use fstatat with AT_NO_AUTOMOUNT.

Cc: Chuck Lever <chuck.lever@oracle.com>
Link: https://bugzilla.redhat.com/show_bug.cgi?id=2148353
Reported-by: JianHong Yin <jiyin@redhat.com>
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
 support/junction/junction.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/support/junction/junction.c b/support/junction/junction.c
index 41cce261cb52..0628bb0ffffb 100644
--- a/support/junction/junction.c
+++ b/support/junction/junction.c
@@ -63,7 +63,7 @@ junction_open_path(const char *pathname, int *fd)
 	if (pathname == NULL || fd == NULL)
 		return FEDFS_ERR_INVAL;
 
-	tmp = open(pathname, O_DIRECTORY);
+	tmp = open(pathname, O_PATH|O_DIRECTORY);
 	if (tmp == -1) {
 		switch (errno) {
 		case EPERM:
@@ -93,7 +93,7 @@ junction_is_directory(int fd, const char *path)
 {
 	struct stat stb;
 
-	if (fstat(fd, &stb) == -1) {
+	if (fstatat(fd, "", &stb, AT_NO_AUTOMOUNT|AT_EMPTY_PATH) == -1) {
 		xlog(D_GENERAL, "%s: failed to stat %s: %m",
 				__func__, path);
 		return FEDFS_ERR_ACCESS;
@@ -121,7 +121,7 @@ junction_is_sticky_bit_set(int fd, const char *path)
 {
 	struct stat stb;
 
-	if (fstat(fd, &stb) == -1) {
+	if (fstatat(fd, "", &stb, AT_NO_AUTOMOUNT|AT_EMPTY_PATH) == -1) {
 		xlog(D_GENERAL, "%s: failed to stat %s: %m",
 				__func__, path);
 		return FEDFS_ERR_ACCESS;
@@ -155,7 +155,7 @@ junction_set_sticky_bit(int fd, const char *path)
 {
 	struct stat stb;
 
-	if (fstat(fd, &stb) == -1) {
+	if (fstatat(fd, "", &stb, AT_NO_AUTOMOUNT|AT_EMPTY_PATH) == -1) {
 		xlog(D_GENERAL, "%s: failed to stat %s: %m",
 			__func__, path);
 		return FEDFS_ERR_ACCESS;
@@ -393,7 +393,7 @@ junction_get_mode(const char *pathname, mode_t *mode)
 	if (retval != FEDFS_OK)
 		return retval;
 
-	if (fstat(fd, &stb) == -1) {
+	if (fstatat(fd, "", &stb, AT_NO_AUTOMOUNT|AT_EMPTY_PATH) == -1) {
 		xlog(D_GENERAL, "%s: failed to stat %s: %m",
 			__func__, pathname);
 		(void)close(fd);
-- 
2.38.1


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

* Re: [nfs-utils PATCH] Don't allow junction tests to trigger automounts
  2022-12-13 16:01 [nfs-utils PATCH] Don't allow junction tests to trigger automounts Jeff Layton
@ 2022-12-13 16:25 ` Chuck Lever III
  2022-12-13 16:41   ` Jeff Layton
  2023-01-04 12:23 ` Jeff Layton
  2023-01-11 15:55 ` Steve Dickson
  2 siblings, 1 reply; 5+ messages in thread
From: Chuck Lever III @ 2022-12-13 16:25 UTC (permalink / raw)
  To: Jeff Layton; +Cc: Steve Dickson, Linux NFS Mailing List, JianHong Yin



> On Dec 13, 2022, at 11:01 AM, Jeff Layton <jlayton@kernel.org> wrote:
> 
> JianHong reported some strange behavior with automounts on an nfs server
> without an explicit pseudoroot. When clients issued a readdir in the
> pseudoroot, automounted directories that were not yet mounted would show
> up even if they weren't exported, though the clients wouldn't be able to
> do anything with them.
> 
> The issue was that triggering the automount on a directory would cause
> the mountd upcall to time out, which would cause nfsd to include the
> automounted dentry in the readdir response. Eventually, the automount
> would work and report that it wasn't exported and subsequent attempts to
> access the dentry would (properly) fail.
> 
> We never want mountd to trigger an automount. The kernel should do that
> if it wants to use it. Change the junction checks to do an O_PATH open
> and use fstatat with AT_NO_AUTOMOUNT.
> 
> Cc: Chuck Lever <chuck.lever@oracle.com>
> Link: https://bugzilla.redhat.com/show_bug.cgi?id=2148353

And also https://bugzilla.kernel.org/show_bug.cgi?id=216777 ?


> Reported-by: JianHong Yin <jiyin@redhat.com>
> Signed-off-by: Jeff Layton <jlayton@kernel.org>
> ---
> support/junction/junction.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/support/junction/junction.c b/support/junction/junction.c
> index 41cce261cb52..0628bb0ffffb 100644
> --- a/support/junction/junction.c
> +++ b/support/junction/junction.c
> @@ -63,7 +63,7 @@ junction_open_path(const char *pathname, int *fd)
> 	if (pathname == NULL || fd == NULL)
> 		return FEDFS_ERR_INVAL;
> 
> -	tmp = open(pathname, O_DIRECTORY);
> +	tmp = open(pathname, O_PATH|O_DIRECTORY);
> 	if (tmp == -1) {
> 		switch (errno) {
> 		case EPERM:
> @@ -93,7 +93,7 @@ junction_is_directory(int fd, const char *path)
> {
> 	struct stat stb;
> 
> -	if (fstat(fd, &stb) == -1) {
> +	if (fstatat(fd, "", &stb, AT_NO_AUTOMOUNT|AT_EMPTY_PATH) == -1) {
> 		xlog(D_GENERAL, "%s: failed to stat %s: %m",
> 				__func__, path);
> 		return FEDFS_ERR_ACCESS;
> @@ -121,7 +121,7 @@ junction_is_sticky_bit_set(int fd, const char *path)
> {
> 	struct stat stb;
> 
> -	if (fstat(fd, &stb) == -1) {
> +	if (fstatat(fd, "", &stb, AT_NO_AUTOMOUNT|AT_EMPTY_PATH) == -1) {
> 		xlog(D_GENERAL, "%s: failed to stat %s: %m",
> 				__func__, path);
> 		return FEDFS_ERR_ACCESS;
> @@ -155,7 +155,7 @@ junction_set_sticky_bit(int fd, const char *path)
> {
> 	struct stat stb;
> 
> -	if (fstat(fd, &stb) == -1) {
> +	if (fstatat(fd, "", &stb, AT_NO_AUTOMOUNT|AT_EMPTY_PATH) == -1) {
> 		xlog(D_GENERAL, "%s: failed to stat %s: %m",
> 			__func__, path);
> 		return FEDFS_ERR_ACCESS;
> @@ -393,7 +393,7 @@ junction_get_mode(const char *pathname, mode_t *mode)
> 	if (retval != FEDFS_OK)
> 		return retval;
> 
> -	if (fstat(fd, &stb) == -1) {
> +	if (fstatat(fd, "", &stb, AT_NO_AUTOMOUNT|AT_EMPTY_PATH) == -1) {
> 		xlog(D_GENERAL, "%s: failed to stat %s: %m",
> 			__func__, pathname);
> 		(void)close(fd);
> -- 
> 2.38.1
> 

--
Chuck Lever




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

* Re: [nfs-utils PATCH] Don't allow junction tests to trigger automounts
  2022-12-13 16:25 ` Chuck Lever III
@ 2022-12-13 16:41   ` Jeff Layton
  0 siblings, 0 replies; 5+ messages in thread
From: Jeff Layton @ 2022-12-13 16:41 UTC (permalink / raw)
  To: Chuck Lever III; +Cc: Steve Dickson, Linux NFS Mailing List, JianHong Yin

On Tue, 2022-12-13 at 16:25 +0000, Chuck Lever III wrote:
> 
> > On Dec 13, 2022, at 11:01 AM, Jeff Layton <jlayton@kernel.org> wrote:
> > 
> > JianHong reported some strange behavior with automounts on an nfs server
> > without an explicit pseudoroot. When clients issued a readdir in the
> > pseudoroot, automounted directories that were not yet mounted would show
> > up even if they weren't exported, though the clients wouldn't be able to
> > do anything with them.
> > 
> > The issue was that triggering the automount on a directory would cause
> > the mountd upcall to time out, which would cause nfsd to include the
> > automounted dentry in the readdir response. Eventually, the automount
> > would work and report that it wasn't exported and subsequent attempts to
> > access the dentry would (properly) fail.
> > 
> > We never want mountd to trigger an automount. The kernel should do that
> > if it wants to use it. Change the junction checks to do an O_PATH open
> > and use fstatat with AT_NO_AUTOMOUNT.
> > 
> > Cc: Chuck Lever <chuck.lever@oracle.com>
> > Link: https://bugzilla.redhat.com/show_bug.cgi?id=2148353
> 
> And also https://bugzilla.kernel.org/show_bug.cgi?id=216777 ?
> 

Yes indeed, thanks! Note too that I suspect there may also be a kernel
error handling bug related to this.

I know that nfsd_cross_mnt returned -ETIMEDOUT, but the READDIR response
still contained the dentry. The follow-on stat call failed, but it seems
like the readdir response shouldn't have included that dentry in the
first place.

I'm still looking at that bit, but we should probably aim to fix that
too.

> 
> > Reported-by: JianHong Yin <jiyin@redhat.com>
> > Signed-off-by: Jeff Layton <jlayton@kernel.org>
> > ---
> > support/junction/junction.c | 10 +++++-----
> > 1 file changed, 5 insertions(+), 5 deletions(-)
> > 
> > diff --git a/support/junction/junction.c b/support/junction/junction.c
> > index 41cce261cb52..0628bb0ffffb 100644
> > --- a/support/junction/junction.c
> > +++ b/support/junction/junction.c
> > @@ -63,7 +63,7 @@ junction_open_path(const char *pathname, int *fd)
> > 	if (pathname == NULL || fd == NULL)
> > 		return FEDFS_ERR_INVAL;
> > 
> > -	tmp = open(pathname, O_DIRECTORY);
> > +	tmp = open(pathname, O_PATH|O_DIRECTORY);
> > 	if (tmp == -1) {
> > 		switch (errno) {
> > 		case EPERM:
> > @@ -93,7 +93,7 @@ junction_is_directory(int fd, const char *path)
> > {
> > 	struct stat stb;
> > 
> > -	if (fstat(fd, &stb) == -1) {
> > +	if (fstatat(fd, "", &stb, AT_NO_AUTOMOUNT|AT_EMPTY_PATH) == -1) {
> > 		xlog(D_GENERAL, "%s: failed to stat %s: %m",
> > 				__func__, path);
> > 		return FEDFS_ERR_ACCESS;
> > @@ -121,7 +121,7 @@ junction_is_sticky_bit_set(int fd, const char *path)
> > {
> > 	struct stat stb;
> > 
> > -	if (fstat(fd, &stb) == -1) {
> > +	if (fstatat(fd, "", &stb, AT_NO_AUTOMOUNT|AT_EMPTY_PATH) == -1) {
> > 		xlog(D_GENERAL, "%s: failed to stat %s: %m",
> > 				__func__, path);
> > 		return FEDFS_ERR_ACCESS;
> > @@ -155,7 +155,7 @@ junction_set_sticky_bit(int fd, const char *path)
> > {
> > 	struct stat stb;
> > 
> > -	if (fstat(fd, &stb) == -1) {
> > +	if (fstatat(fd, "", &stb, AT_NO_AUTOMOUNT|AT_EMPTY_PATH) == -1) {
> > 		xlog(D_GENERAL, "%s: failed to stat %s: %m",
> > 			__func__, path);
> > 		return FEDFS_ERR_ACCESS;
> > @@ -393,7 +393,7 @@ junction_get_mode(const char *pathname, mode_t *mode)
> > 	if (retval != FEDFS_OK)
> > 		return retval;
> > 
> > -	if (fstat(fd, &stb) == -1) {
> > +	if (fstatat(fd, "", &stb, AT_NO_AUTOMOUNT|AT_EMPTY_PATH) == -1) {
> > 		xlog(D_GENERAL, "%s: failed to stat %s: %m",
> > 			__func__, pathname);
> > 		(void)close(fd);
> > -- 
> > 2.38.1
> > 
> 
> --
> Chuck Lever
> 
> 
> 

-- 
Jeff Layton <jlayton@kernel.org>

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

* Re: [nfs-utils PATCH] Don't allow junction tests to trigger automounts
  2022-12-13 16:01 [nfs-utils PATCH] Don't allow junction tests to trigger automounts Jeff Layton
  2022-12-13 16:25 ` Chuck Lever III
@ 2023-01-04 12:23 ` Jeff Layton
  2023-01-11 15:55 ` Steve Dickson
  2 siblings, 0 replies; 5+ messages in thread
From: Jeff Layton @ 2023-01-04 12:23 UTC (permalink / raw)
  To: steved; +Cc: linux-nfs, Chuck Lever, JianHong Yin

On Tue, 2022-12-13 at 11:01 -0500, Jeff Layton wrote:
> JianHong reported some strange behavior with automounts on an nfs server
> without an explicit pseudoroot. When clients issued a readdir in the
> pseudoroot, automounted directories that were not yet mounted would show
> up even if they weren't exported, though the clients wouldn't be able to
> do anything with them.
> 
> The issue was that triggering the automount on a directory would cause
> the mountd upcall to time out, which would cause nfsd to include the
> automounted dentry in the readdir response. Eventually, the automount
> would work and report that it wasn't exported and subsequent attempts to
> access the dentry would (properly) fail.
> 
> We never want mountd to trigger an automount. The kernel should do that
> if it wants to use it. Change the junction checks to do an O_PATH open
> and use fstatat with AT_NO_AUTOMOUNT.
> 
> Cc: Chuck Lever <chuck.lever@oracle.com>
> Link: https://bugzilla.redhat.com/show_bug.cgi?id=2148353
> Reported-by: JianHong Yin <jiyin@redhat.com>
> Signed-off-by: Jeff Layton <jlayton@kernel.org>
> ---
>  support/junction/junction.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 

Ping? Steve, can you comment on (or merge) this patch?

Thanks,
-- 
Jeff Layton <jlayton@kernel.org>

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

* Re: [nfs-utils PATCH] Don't allow junction tests to trigger automounts
  2022-12-13 16:01 [nfs-utils PATCH] Don't allow junction tests to trigger automounts Jeff Layton
  2022-12-13 16:25 ` Chuck Lever III
  2023-01-04 12:23 ` Jeff Layton
@ 2023-01-11 15:55 ` Steve Dickson
  2 siblings, 0 replies; 5+ messages in thread
From: Steve Dickson @ 2023-01-11 15:55 UTC (permalink / raw)
  To: Jeff Layton; +Cc: linux-nfs, Chuck Lever, JianHong Yin



On 12/13/22 11:01 AM, Jeff Layton wrote:
> JianHong reported some strange behavior with automounts on an nfs server
> without an explicit pseudoroot. When clients issued a readdir in the
> pseudoroot, automounted directories that were not yet mounted would show
> up even if they weren't exported, though the clients wouldn't be able to
> do anything with them.
> 
> The issue was that triggering the automount on a directory would cause
> the mountd upcall to time out, which would cause nfsd to include the
> automounted dentry in the readdir response. Eventually, the automount
> would work and report that it wasn't exported and subsequent attempts to
> access the dentry would (properly) fail.
> 
> We never want mountd to trigger an automount. The kernel should do that
> if it wants to use it. Change the junction checks to do an O_PATH open
> and use fstatat with AT_NO_AUTOMOUNT.
> 
> Cc: Chuck Lever <chuck.lever@oracle.com>
> Link: https://bugzilla.redhat.com/show_bug.cgi?id=2148353
> Reported-by: JianHong Yin <jiyin@redhat.com>
> Signed-off-by: Jeff Layton <jlayton@kernel.org>
Committed... (tag: nfs-utils-2-6-3-rc6)

steved
> ---
>   support/junction/junction.c | 10 +++++-----
>   1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/support/junction/junction.c b/support/junction/junction.c
> index 41cce261cb52..0628bb0ffffb 100644
> --- a/support/junction/junction.c
> +++ b/support/junction/junction.c
> @@ -63,7 +63,7 @@ junction_open_path(const char *pathname, int *fd)
>   	if (pathname == NULL || fd == NULL)
>   		return FEDFS_ERR_INVAL;
>   
> -	tmp = open(pathname, O_DIRECTORY);
> +	tmp = open(pathname, O_PATH|O_DIRECTORY);
>   	if (tmp == -1) {
>   		switch (errno) {
>   		case EPERM:
> @@ -93,7 +93,7 @@ junction_is_directory(int fd, const char *path)
>   {
>   	struct stat stb;
>   
> -	if (fstat(fd, &stb) == -1) {
> +	if (fstatat(fd, "", &stb, AT_NO_AUTOMOUNT|AT_EMPTY_PATH) == -1) {
>   		xlog(D_GENERAL, "%s: failed to stat %s: %m",
>   				__func__, path);
>   		return FEDFS_ERR_ACCESS;
> @@ -121,7 +121,7 @@ junction_is_sticky_bit_set(int fd, const char *path)
>   {
>   	struct stat stb;
>   
> -	if (fstat(fd, &stb) == -1) {
> +	if (fstatat(fd, "", &stb, AT_NO_AUTOMOUNT|AT_EMPTY_PATH) == -1) {
>   		xlog(D_GENERAL, "%s: failed to stat %s: %m",
>   				__func__, path);
>   		return FEDFS_ERR_ACCESS;
> @@ -155,7 +155,7 @@ junction_set_sticky_bit(int fd, const char *path)
>   {
>   	struct stat stb;
>   
> -	if (fstat(fd, &stb) == -1) {
> +	if (fstatat(fd, "", &stb, AT_NO_AUTOMOUNT|AT_EMPTY_PATH) == -1) {
>   		xlog(D_GENERAL, "%s: failed to stat %s: %m",
>   			__func__, path);
>   		return FEDFS_ERR_ACCESS;
> @@ -393,7 +393,7 @@ junction_get_mode(const char *pathname, mode_t *mode)
>   	if (retval != FEDFS_OK)
>   		return retval;
>   
> -	if (fstat(fd, &stb) == -1) {
> +	if (fstatat(fd, "", &stb, AT_NO_AUTOMOUNT|AT_EMPTY_PATH) == -1) {
>   		xlog(D_GENERAL, "%s: failed to stat %s: %m",
>   			__func__, pathname);
>   		(void)close(fd);


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

end of thread, other threads:[~2023-01-11 15:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-13 16:01 [nfs-utils PATCH] Don't allow junction tests to trigger automounts Jeff Layton
2022-12-13 16:25 ` Chuck Lever III
2022-12-13 16:41   ` Jeff Layton
2023-01-04 12:23 ` Jeff Layton
2023-01-11 15:55 ` Steve Dickson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).