Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

karelzak
Copy link
Collaborator

@karelzak karelzak commented Jul 1, 2025

No description provided.

karelzak added 8 commits July 1, 2025 16:42
 * introduce do_canonicalize() with proper return values

 * use do_canonicalize() everywhere

Signed-off-by: Karel Zak <[email protected]>
* add ul_restricted_path_oper() to fileutils.c

* use it as backed for canonicalize_path_restricted()

Signed-off-by: Karel Zak <[email protected]>
Based on ul_restricted_path_oper().

Signed-off-by: Karel Zak <[email protected]>
@karelzak karelzak marked this pull request as draft July 1, 2025 15:05
@karelzak karelzak force-pushed the PR/libmount-mkdir-precheck branch from fb3655d to 02f6eb5 Compare July 1, 2025 15:15
karelzak added 4 commits July 2, 2025 15:34
* test classic user-mount (mount.static required)
* test user-mount with X-mount.mkdir

Signed-off-by: Karel Zak <[email protected]>
@karelzak karelzak marked this pull request as ready for review July 16, 2025 09:34
@karelzak karelzak requested a review from t-8ch July 29, 2025 12:32
len = canonical ? (ssize_t) strlen(canonical) :
errno ? -errno : -EINVAL;
len = canonical ?(ssize_t) strlen(canonical) :
errno ? -errno : -EINVAL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spurious whitespace changes? If intentional should be in a dedicated commit.

if (!path || !*path)
return NULL;
if (result)
*result = NULL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result seems to be always non-NULL.


errno = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems unnecessary.

* unreachable path is not an error (!), and in this case, it just duplicates
* @path.
*/
char *canonicalize_path(const char *path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these also all get the ul_ prefix?

fprintf(stdout, "real: %s\n", canonicalize_path(argv[1]));

fprintf(stdout, "real: %s\n", canonicalize_path(argv[1]));
fprintf(stdout, "real-restricted: %s\n", canonicalize_path_restricted(argv[1]));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be used to have a real unittest which validates the results?

ts_init_subtest "basic"
TS_FSTAB="/etc/fstab"
ts_fstab_add $MOUNT_SOURCE $MOUNT_TARGET "none" "bind,user,default,noauto"
runuser -u testuser_mount -- $TS_CMD_MOUNT_STATIC $MOUNT_TARGET >> $TS_OUTPUT 2>> $TS_ERRLOG
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use the runuser from the current build.


# Add test user
#
useradd -u 9899 --shell /bin/bash testuser_mount
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of this. Can we use nobody?
Or just a random user id from a transient uid range.

# classic user-mount
#
ts_init_subtest "basic"
TS_FSTAB="/etc/fstab"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the regular test fstab not enough?

runuser -u testuser_mount -- $TS_CMD_MOUNT_STATIC $MOUNT_TARGET >> $TS_OUTPUT 2>> $TS_ERRLOG
opts=$(findmnt -nr -o VFS-OPTIONS --mountpoint $MOUNT_TARGET)
[[ $opts == *"noexec"* && $opts == *"nosuid"* && $opts == *"nodev"* ]] \
|| ts_log "Cannot find user options"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ts_errlog

TS_FSTAB="/etc/fstab"
ts_fstab_add $MOUNT_SOURCE $MOUNT_TARGET "none" "bind,user,default,noauto"
runuser -u testuser_mount -- $TS_CMD_MOUNT_STATIC $MOUNT_TARGET >> $TS_OUTPUT 2>> $TS_ERRLOG
opts=$(findmnt -nr -o VFS-OPTIONS --mountpoint $MOUNT_TARGET)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TS_CMD_FINDMNT

@karelzak karelzak marked this pull request as draft August 27, 2025 10:47
@karelzak
Copy link
Collaborator Author

I'll split this pull request into three separate pull requests:

  1. canonicalization refactoring
  2. non-root mount test
  3. non-root X-mount.mkdir

I'll keep it open as a draw until all is implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants