From 9d1211f13bfc806102f1d0ae3a7011158d003cac Mon Sep 17 00:00:00 2001 From: Mikael Heino Date: Fri, 22 Oct 2021 13:59:22 +0300 Subject: [PATCH] Halt mounting with a faulty usermapping path The driver mounts the volume with global permissions in case a usermapping file was given but opening or reading it had failed. The driver did not even warn about this behaviour. This could lead into potential security related problems when every user has full permissions in the mounted volume. --- src/lowntfs-3g.c | 14 ++++++++++++-- src/ntfs-3g.c | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/lowntfs-3g.c b/src/lowntfs-3g.c index 9330500c..e3fc6324 100644 --- a/src/lowntfs-3g.c +++ b/src/lowntfs-3g.c @@ -4787,6 +4787,16 @@ int main(int argc, char *argv[]) #endif /* POSIXACLS */ ctx->dmask = ctx->fmask = 0; } else { + /* + * User mapping path was defined, but building it failed + * Warn the user and halt the mounting + */ + if (ctx->usermap_path) { + ntfs_log_perror("Failed to load user mapping '%s'", + ctx->usermap_path); + err = NTFS_VOLUME_SYNTAX_ERROR; + goto err_out; + } ctx->security.uid = ctx->uid; ctx->security.gid = ctx->gid; /* same ownership/permissions for all files */ @@ -4808,8 +4818,6 @@ int main(int argc, char *argv[]) permissions_mode = "Ownership and permissions disabled"; } } - if (ctx->usermap_path) - free (ctx->usermap_path); #if defined(HAVE_SETXATTR) && defined(XATTR_MAPPINGS) xattr_mapping = ntfs_xattr_build_mapping(ctx->vol, @@ -4855,6 +4863,8 @@ int main(int argc, char *argv[]) fuse_session_destroy(se); err_out: ntfs_mount_error(opts.device, opts.mnt_point, err); + if (ctx->usermap_path) + free(ctx->usermap_path); if (ctx->abs_mnt_point) free(ctx->abs_mnt_point); #if defined(HAVE_SETXATTR) && defined(XATTR_MAPPINGS) diff --git a/src/ntfs-3g.c b/src/ntfs-3g.c index d8227e71..b551a3db 100644 --- a/src/ntfs-3g.c +++ b/src/ntfs-3g.c @@ -4514,6 +4514,16 @@ int main(int argc, char *argv[]) #endif /* POSIXACLS */ ctx->dmask = ctx->fmask = 0; } else { + /* + * User mapping path was defined, but building it failed + * Warn the user and halt the mounting + */ + if (ctx->usermap_path) { + ntfs_log_perror("Failed to load user mapping '%s'", + ctx->usermap_path); + err = NTFS_VOLUME_SYNTAX_ERROR; + goto err_out; + } ctx->security.uid = ctx->uid; ctx->security.gid = ctx->gid; /* same ownership/permissions for all files */ @@ -4535,8 +4545,6 @@ int main(int argc, char *argv[]) permissions_mode = "Ownership and permissions disabled"; } } - if (ctx->usermap_path) - free (ctx->usermap_path); #if defined(HAVE_SETXATTR) && defined(XATTR_MAPPINGS) xattr_mapping = ntfs_xattr_build_mapping(ctx->vol, @@ -4584,6 +4592,8 @@ int main(int argc, char *argv[]) fuse_destroy(fh); err_out: ntfs_mount_error(opts.device, opts.mnt_point, err); + if (ctx->usermap_path) + free(ctx->usermap_path); if (ctx->abs_mnt_point) free(ctx->abs_mnt_point); #if defined(HAVE_SETXATTR) && defined(XATTR_MAPPINGS)