From: Craig Small Date: Tue, 27 Oct 2020 10:59:25 +0000 (+1100) Subject: fuser: Check pathname only on non-block devices X-Git-Tag: v23.4rc1~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b4566f854f29cad3d2249abcb7e472f5d3fbf169;p=psmisc fuser: Check pathname only on non-block devices The referenced commit we would check the pathname to ensure it matched our target. This worked fine for real files. However for block devices it would fail because "/dev/sda1" doesn't match "/mnt/myfile". We only check the pathname if the thing we are matching against is not a block file. Thanks to @MarsChan for the report and also the suggested fix! References: commit 5c979b38253d187a8ecb8e52a0878b8bb668894f psmisc/psmisc#31 Signed-off-by: Craig Small --- diff --git a/ChangeLog b/ChangeLog index 1a88488..3e77df6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ Changes in NEXT =============== * pstree: Do not crash on missing processes !21 * fuser: Get less confused about duplicate dev_id !10 + * fuser: Only check pathname on non-block devices !31 Changes in 23.3 =============== diff --git a/src/fuser.c b/src/fuser.c index 70da121..03e6237 100644 --- a/src/fuser.c +++ b/src/fuser.c @@ -1606,13 +1606,15 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, if (thedev != dev_tmp->device) continue; - /* check the paths match */ - if (readlink(filepath, real_filepath, PATH_MAX-1) < 0) { - if (strncmp(dev_tmp->name->filename, filepath, strlen(dev_tmp->name->filename)) != 0) - continue; - } else { - if (strncmp(dev_tmp->name->filename, real_filepath, strlen(dev_tmp->name->filename)) != 0) - continue; + /* check the paths match if it is not a block device */ + if (! S_ISBLK(dev_tmp->name->st.st_mode)) { + if (readlink(filepath, real_filepath, PATH_MAX-1) < 0) { + if (strncmp(dev_tmp->name->filename, filepath, strlen(dev_tmp->name->filename)) != 0) + continue; + } else { + if (strncmp(dev_tmp->name->filename, real_filepath, strlen(dev_tmp->name->filename)) != 0) + continue; + } } if (access == ACCESS_FILE && (lstat(filepath, &lst) == 0)