diff options
| author | Karel Zak <kzak@redhat.com> | 2023-08-03 13:06:30 +0200 |
|---|---|---|
| committer | Karel Zak <kzak@redhat.com> | 2023-08-03 13:11:28 +0200 |
| commit | 7f8206f8de922a285fbef2716d5b7e832a59bf1f (patch) | |
| tree | f24166f64293e1b67f6ad74765a818bce7155ff9 /libmount/src | |
| parent | c0136ac0c98b18208508fbcfac31a843e0bb8a37 (diff) | |
| download | util-linux-7f8206f8de922a285fbef2716d5b7e832a59bf1f.tar.gz | |
libmount: improve EPERM interpretation
In some cases mount(2)/open_tree(2) returns EPERM for root user. In
this case libmount reports it as "mount point is not a directory".
It does not makes sense for bind mount where target could be a
regular file.
This patch is not ideal, the error handler is generic, but semantic
for new mount API and mount(2) is different. For example now it checks
for regular file, but the new API supports bind over symlinks, so
proper fix will require lstat() and S_ISLNK(), etc. We need to move
error messages to hook_mount.c and mount_mount_legacy.c to make it
more specific.
Fixes: https://github.com/util-linux/util-linux/issues/2413
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src')
| -rw-r--r-- | libmount/src/context_mount.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c index 07971708bc..dcc5eb97fb 100644 --- a/libmount/src/context_mount.c +++ b/libmount/src/context_mount.c @@ -1580,10 +1580,13 @@ int mnt_context_get_mount_excode( if (!buf) break; if (geteuid() == 0) { - if (mnt_safe_stat(tgt, &st) || !S_ISDIR(st.st_mode)) - snprintf(buf, bufsz, _("mount point is not a directory")); - else + + if (mnt_safe_stat(tgt, &st) == 0 + && ((mflags & MS_BIND && S_ISREG(st.st_mode)) + || S_ISDIR(st.st_mode))) snprintf(buf, bufsz, _("permission denied")); + else + snprintf(buf, bufsz, _("mount point is not a directory")); } else snprintf(buf, bufsz, _("must be superuser to use mount")); break; |
