Don't allow junction tests to trigger automounts
Subsystems (2)
Jeff Layton
maintainerPATCH 1/1 Don't allow junction tests to trigger automounts
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.
--- support/junction/junction.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
support/junction/junction.c +5 -5
@@ -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);
Signature · 1 line
2.38.1
Quoted 16 lines · Jeff Layton
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.
Quoted 6 lines
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_PATHopen and use fstatat withAT_NO_AUTOMOUNT.Cc Chuck Lever <[email protected]>
And also https://bugzilla.kernel.org/show_bug.cgi?id=216777 ?
Quoted 58 lines
Reported-by JianHong Yin <[email protected]>Signed-off-by Jeff Layton <[email protected]>---
support/junction/junction.c| 10 +++++-----1 file changed, 5 insertions(+), 5 deletions(-)support/junction/junction.c +5
-5@@ -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);Signature · 1 line
2.38.1
--
Chuck Lever
Jeff Layton
maintainerQuoted 15 lines · Chuck Lever III
Quoted 15 lines · Jeff Layton
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.
Quoted 9 lines
Quoted 6 lines
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_PATHopen and use fstatat withAT_NO_AUTOMOUNT.Cc Chuck Lever <[email protected]>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.
Quoted 65 lines
Quoted 59 lines
Reported-by JianHong Yin <[email protected]>Signed-off-by Jeff Layton <[email protected]>---
support/junction/junction.c| 10 +++++-----1 file changed, 5 insertions(+), 5 deletions(-)support/junction/junction.c +5
-5@@ -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);Signature · 1 line
2.38.1--
Chuck Lever
Signature · 1 line
Jeff Layton <[email protected]>
Jeff Layton
maintainerQuoted 16 lines · Jeff Layton
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_PATHopen and use fstatat withAT_NO_AUTOMOUNT.
Quoted 8 lines
Cc Chuck Lever <[email protected]>Reported-by JianHong Yin <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- support/junction/junction.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
Ping? Steve, can you comment on (or merge) this patch?
Thanks,
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 12 lines · Jeff Layton
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.
Quoted 8 lines
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_PATHopen and use fstatat withAT_NO_AUTOMOUNT.Cc Chuck Lever <[email protected]>Reported-by JianHong Yin <[email protected]>Signed-off-by Jeff Layton <[email protected]>
Committed... (tag: nfs-utils-2-6-3-rc6)
steved
Quoted 53 lines
--- support/junction/junction.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)support/junction/junction.c +5
-5@@ -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);