Skip to contentSkip to conversation

target/ppc/kvm: Skip current and parent directories in kvmppc_find_cpu_dt

PATCH In review Murilo Opsfelder Araujo 3 participants 3 messages Jul 12, 2022 – Jul 14, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 target/ppc/kvm: Skip current and parent directories in kvmppc_find_cpu_dt

Some systems have /proc/device-tree/cpus/../clock-frequency. However, this is not the expected path for a CPU device tree directory.

---
v2:
- Skip current and parent directories.

v1: https://lore.kernel.org/qemu-devel/[email protected]/

 target/ppc/kvm.c | 6 ++++++
 1 file changed, 6 insertions(+)
target/ppc/kvm.c +6 -0
index 6eed466f80..466d0d2f4c 100644
@@ -1877,6 +1877,12 @@ static int kvmppc_find_cpu_dt(char *buf, int buf_len)
     buf[0] = '\0';
     while ((dirp = readdir(dp)) != NULL) {
         FILE *f;
+
+        /* Don't accidentally read from the current and parent directories */
+        if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0) {
+            continue;
+        }
+
         snprintf(buf, buf_len, "%s%s/clock-frequency", PROC_DEVTREE_CPU,
                  dirp->d_name);
         f = fopen(buf, "r");
Signature · 1 line
2.36.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines · Murilo Opsfelder Araujo

Some systems have /proc/device-tree/cpus/../clock-frequency. However, this is not the expected path for a CPU device tree directory.

and, I believe, mea culpa.

Quoted 26 lines

---
v2:
- Skip current and parent directories.

v1: https://lore.kernel.org/qemu-devel/[email protected]/

 target/ppc/kvm.c | 6 ++++++
 1 file changed, 6 insertions(+)
target/ppc/kvm.c +6 -0
index 6eed466f80..466d0d2f4c 100644
@@ -1877,6 +1877,12 @@ static int kvmppc_find_cpu_dt(char *buf, int buf_len)
     buf[0] = '\0';
     while ((dirp = readdir(dp)) != NULL) {
         FILE *f;
+
+        /* Don't accidentally read from the current and parent directories */
+        if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0) {
+            continue;
+        }
+
         snprintf(buf, buf_len, "%s%s/clock-frequency", PROC_DEVTREE_CPU,
                  dirp->d_name);
         f = fopen(buf, "r");
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
Reviewed-by on v2 1/1
#2 lore raw
In reply to Murilo Opsfelder Araujo
Quoted 6 lines · Murilo Opsfelder Araujo

Some systems have /proc/device-tree/cpus/../clock-frequency. However, this is not the expected path for a CPU device tree directory.

---

and queued.

Daniel

Quoted 25 lines

v2:
- Skip current and parent directories.

v1: https://lore.kernel.org/qemu-devel/[email protected]/

  target/ppc/kvm.c | 6 ++++++
  1 file changed, 6 insertions(+)
target/ppc/kvm.c +6 -0
index 6eed466f80..466d0d2f4c 100644
@@ -1877,6 +1877,12 @@ static int kvmppc_find_cpu_dt(char *buf, int buf_len)
      buf[0] = '\0';
      while ((dirp = readdir(dp)) != NULL) {
          FILE *f;
+
+        /* Don't accidentally read from the current and parent directories */
+        if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0) {
+            continue;
+        }
+
          snprintf(buf, buf_len, "%s%s/clock-frequency", PROC_DEVTREE_CPU,
                   dirp->d_name);
          f = fopen(buf, "r");