diff mbox series

Fix `statx()` emulation breaking exports

Message ID a5547a1af1dc90d65100c873204a5b0912ecb9a8.1618563564.git.ps@pks.im (mailing list archive)
State New
Headers show
Series Fix `statx()` emulation breaking exports | expand

Commit Message

Patrick Steinhardt April 16, 2021, 9 a.m. UTC
Ever since commit 76c21e3f (mountd: Check the stat() return values in
match_fsid(), 2020-05-08), it wasn't possible to export filesystems
on my musl based system anymore.

The root cause of this is the innocuous-looking change to decide based
on `errno` whether `is_mountpoint()` raised a real error or whether it
simply didn't match. The issue is that `is_mountpoint()` transitively
calls into our `xlstat()` wrapper, which either executes `statx()` if
the system supports it or otherwise falls back to `fstatat()`. But if
`statx()` is not supported, then we'll always first set `errno = ENOSYS`
before calling `fstatat()`. So effectively, all systems which do not
have `statx()` and whose `fstatat()` doesn't reset `errno` will cause us
to end up with errno set to `ENOSYS`.

Fix the issue by resetting `errno` before calling `fstatat()` in both
`xlstat()` and `xstat()`.

Fixes: 76c21e3f (mountd: Check the stat() return values in match_fsid(), 2020-05-08)
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 support/misc/xstat.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Steve Dickson May 6, 2021, 5:31 p.m. UTC | #1
On 4/16/21 5:00 AM, Patrick Steinhardt wrote:
> Ever since commit 76c21e3f (mountd: Check the stat() return values in
> match_fsid(), 2020-05-08), it wasn't possible to export filesystems
> on my musl based system anymore.
> 
> The root cause of this is the innocuous-looking change to decide based
> on `errno` whether `is_mountpoint()` raised a real error or whether it
> simply didn't match. The issue is that `is_mountpoint()` transitively
> calls into our `xlstat()` wrapper, which either executes `statx()` if
> the system supports it or otherwise falls back to `fstatat()`. But if
> `statx()` is not supported, then we'll always first set `errno = ENOSYS`
> before calling `fstatat()`. So effectively, all systems which do not
> have `statx()` and whose `fstatat()` doesn't reset `errno` will cause us
> to end up with errno set to `ENOSYS`.
> 
> Fix the issue by resetting `errno` before calling `fstatat()` in both
> `xlstat()` and `xstat()`.
> 
> Fixes: 76c21e3f (mountd: Check the stat() return values in match_fsid(), 2020-05-08)
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
Committed (tag: nfs-utils-2-5-4-rc3)

steved.
> ---
>  support/misc/xstat.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/support/misc/xstat.c b/support/misc/xstat.c
> index a438fbcc..6f751f7f 100644
> --- a/support/misc/xstat.c
> +++ b/support/misc/xstat.c
> @@ -85,6 +85,7 @@ int xlstat(const char *pathname, struct stat *statbuf)
>  		return 0;
>  	else if (errno != ENOSYS)
>  		return -1;
> +	errno = 0;
>  	return fstatat(AT_FDCWD, pathname, statbuf, AT_NO_AUTOMOUNT |
>  			AT_SYMLINK_NOFOLLOW);
>  }
> @@ -95,6 +96,7 @@ int xstat(const char *pathname, struct stat *statbuf)
>  		return 0;
>  	else if (errno != ENOSYS)
>  		return -1;
> +	errno = 0;
>  	return fstatat(AT_FDCWD, pathname, statbuf, AT_NO_AUTOMOUNT);
>  }
>  
>
diff mbox series

Patch

diff --git a/support/misc/xstat.c b/support/misc/xstat.c
index a438fbcc..6f751f7f 100644
--- a/support/misc/xstat.c
+++ b/support/misc/xstat.c
@@ -85,6 +85,7 @@  int xlstat(const char *pathname, struct stat *statbuf)
 		return 0;
 	else if (errno != ENOSYS)
 		return -1;
+	errno = 0;
 	return fstatat(AT_FDCWD, pathname, statbuf, AT_NO_AUTOMOUNT |
 			AT_SYMLINK_NOFOLLOW);
 }
@@ -95,6 +96,7 @@  int xstat(const char *pathname, struct stat *statbuf)
 		return 0;
 	else if (errno != ENOSYS)
 		return -1;
+	errno = 0;
 	return fstatat(AT_FDCWD, pathname, statbuf, AT_NO_AUTOMOUNT);
 }