[PATCH] erofs-utils: stop mkfs when access permission denied

Gao Xiang hsiangkao at redhat.com
Sun Nov 22 16:37:27 AEDT 2020


Hi Guifu,

I'd suggest the following subject...

erofs-utils: stop building tree if file fails to open

On Sun, Nov 22, 2020 at 12:27:59PM +0800, Li Guifu via Linux-erofs wrote:
> It would not has the permission to access one file when mkfs.erofs
> was not run in the root mode, eg run without sudo, So stop and
> exit immediately

stop and exit immediately if it fails to open a file, e.g mkfs.erofs
doesn't run under the root user (e.g. run without sudo.)

> 
> Signed-off-by: Li Guifu <bluce.lee at aliyun.com>
> ---
>  lib/inode.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/inode.c b/lib/inode.c
> index fee5c96..4641561 100644
> --- a/lib/inode.c
> +++ b/lib/inode.c
> @@ -364,6 +364,7 @@ int erofs_write_file(struct erofs_inode *inode)
>  	}
>  
>  	/* fallback to all data uncompressed */
> +	errno = 0;

Why is it necessary, -errno is only used and returned if (fd < 0)

Could you update and resend this?

Thanks,
Gao Xiang

>  	fd = open(inode->i_srcpath, O_RDONLY | O_BINARY);
>  	if (fd < 0)
>  		return -errno;
> @@ -908,7 +909,9 @@ struct erofs_inode *erofs_mkfs_build_tree(struct erofs_inode *dir)
>  			if (ret)
>  				return ERR_PTR(ret);
>  		} else {
> -			erofs_write_file(dir);
> +			ret = erofs_write_file(dir);
> +			if (ret)
> +				return ERR_PTR(ret);
>  		}
>  
>  		erofs_prepare_inode_buffer(dir);
> @@ -982,10 +985,11 @@ struct erofs_inode *erofs_mkfs_build_tree(struct erofs_inode *dir)
>  
>  		d->inode = erofs_mkfs_build_tree_from_path(dir, buf);
>  		if (IS_ERR(d->inode)) {
> +			ret = PTR_ERR(d->inode);
>  fail:
>  			d->inode = NULL;
>  			d->type = EROFS_FT_UNKNOWN;
> -			continue;
> +			goto err_closedir;
>  		}
>  
>  		d->type = erofs_type_by_mode[d->inode->i_mode >> S_SHIFT];
> -- 
> 2.17.1
> 



More information about the Linux-erofs mailing list