Subject: [PATCH] exportfs: make root unexportable

If root of the filesystem is exported, it cannot be explicitly
unexported, since unexportfs_parsed, in order to deal with trailing
'/', will leave nlen at 0 for root exported case

Signed-off-by: Roberto Bergantinos Corpas <[email protected]>
---
utils/exportfs/exportfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c
index 9fcae0b3..9b6f4f5a 100644
--- a/utils/exportfs/exportfs.c
+++ b/utils/exportfs/exportfs.c
@@ -372,7 +372,7 @@ unexportfs_parsed(char *hname, char *path, int verbose)
* so need to deal with it.
*/
size_t nlen = strlen(path);
- while (path[nlen - 1] == '/')
+ while ((path[nlen - 1] == '/') && (nlen > 1))
nlen--;

for (exp = exportlist[htype].p_head; exp; exp = exp->m_next) {
--
2.21.0


2021-03-30 08:45:01

by Yongcheng Yang

[permalink] [raw]
Subject: Re: [PATCH] exportfs: make root unexportable

Hi SteveD,

This is a real problem introduced by my previous update. Sorry for it.

How about also adding this tag:
Fixes: a9a7728d (exportfs: Deal with path's trailing "/" in unexportfs_parsed())

Thanks,
Yongcheng

On Mon, Mar 29, 2021 at 12:54:35PM +0200, Roberto Bergantinos Corpas wrote:
> If root of the filesystem is exported, it cannot be explicitly
> unexported, since unexportfs_parsed, in order to deal with trailing
> '/', will leave nlen at 0 for root exported case
>
> Signed-off-by: Roberto Bergantinos Corpas <[email protected]>
> ---
> utils/exportfs/exportfs.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c
> index 9fcae0b3..9b6f4f5a 100644
> --- a/utils/exportfs/exportfs.c
> +++ b/utils/exportfs/exportfs.c
> @@ -372,7 +372,7 @@ unexportfs_parsed(char *hname, char *path, int verbose)
> * so need to deal with it.
> */
> size_t nlen = strlen(path);
> - while (path[nlen - 1] == '/')
> + while ((path[nlen - 1] == '/') && (nlen > 1))
> nlen--;
>
> for (exp = exportlist[htype].p_head; exp; exp = exp->m_next) {
> --
> 2.21.0
>

2021-04-07 21:52:08

by Steve Dickson

[permalink] [raw]
Subject: Re: [PATCH] exportfs: make root unexportable

Hello,

On 3/29/21 6:54 AM, Roberto Bergantinos Corpas wrote:
> If root of the filesystem is exported, it cannot be explicitly
> unexported, since unexportfs_parsed, in order to deal with trailing
> '/', will leave nlen at 0 for root exported case
>
> Signed-off-by: Roberto Bergantinos Corpas <[email protected]>
> ---
> utils/exportfs/exportfs.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c
> index 9fcae0b3..9b6f4f5a 100644
> --- a/utils/exportfs/exportfs.c
> +++ b/utils/exportfs/exportfs.c
> @@ -372,7 +372,7 @@ unexportfs_parsed(char *hname, char *path, int verbose)
> * so need to deal with it.
> */
> size_t nlen = strlen(path);
> - while (path[nlen - 1] == '/')
> + while ((path[nlen - 1] == '/') && (nlen > 1))
> nlen--;
I decided to use Ondrej's version sine the nlen is tested
first before the index into path was made.

steved.
>
> for (exp = exportlist[htype].p_head; exp; exp = exp->m_next) {
>