aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Cowell <matt.cowell@nokia.com>2021-11-11 05:11:43 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-11-11 10:32:56 +0000
commit300d7570720bc14d01f49d285498d71cce3ce44e (patch)
tree7859c5d46f9c33b18f0367ee2b795e23efe495c8
parentd34f2f6cedccf8488730001bcbde6bb7499f8814 (diff)
downloadpseudo-oe-core.zip
pseudo-oe-core.tar.gz
pseudo-oe-core.tar.bz2
pseudo_fix_path: do not expand symlinks in /procoe-core
Some symlinks in /proc, such as those under /proc/[pid]/fd, /proc/[pid]/cwd, and /proc/[pid]/exe that are not real and should not have readlink called on them. These look like symlinks, but behave like hardlinks. Readlink does not return actual paths. Previously pseudo_fix_path would expand files such as /dev/stdin to paths such as /proc/6680/fd/pipe:[1270830076] which do not exist. This issue affects: - deleted files - deleted directories - fifos - sockets - anon_inodes (epoll, eventfd, inotify, signalfd, timerfd, etc) Testing: - run_tests: all tests passed (3 tests check the new code path). Checked test output to make sure the new codepath gets executed. - perftest: measured time before and after applying the patch had insignificant differences (roughly ~1%) - world build: completed without warning/errors Signed-off-by: Sakib Sajal <sakib.sajal@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--pseudo_util.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/pseudo_util.c b/pseudo_util.c
index b6980c2..b9de81e 100644
--- a/pseudo_util.c
+++ b/pseudo_util.c
@@ -29,6 +29,11 @@
#include "pseudo_ipc.h"
#include "pseudo_db.h"
+/* O_PATH is defined in glibc 2.16 and later only */
+#ifndef O_PATH
+#define O_PATH 010000000
+#endif
+
struct pseudo_variables {
char *key;
size_t key_len;
@@ -678,6 +683,18 @@ pseudo_append_element(char *newpath, char *root, size_t allocated, char **pcurre
*/
if (!leave_this && is_dir) {
int is_link = S_ISLNK(buf->st_mode);
+
+ /* do not expand symlinks in the proc filesystem, since they may not be real
+ * check if newpath starts with "/proc/"
+ * strlen of "/proc/" = 6
+ */
+ if (is_link && (strncmp("/proc/", newpath, 6) == 0)) {
+ pseudo_debug(PDBGF_PATH | PDBGF_VERBOSE,
+ "pae: '%s' is procfs symlink, not expanding\n",
+ newpath);
+ is_link = 0;
+ }
+
if (link_recursion >= PSEUDO_MAX_LINK_RECURSION && is_link) {
pseudo_diag("link recursion too deep, not expanding path '%s'.\n", newpath);
is_link = 0;