git: 9fcbd4c0d19c - stable/13 - libprocstat: simplify auxv value conversion
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 26 Oct 2023 20:39:12 UTC
The branch stable/13 has been updated by brooks:
URL: https://cgit.FreeBSD.org/src/commit/?id=9fcbd4c0d19cdbfa1fb4711c00c9c9cf84dbefb0
commit 9fcbd4c0d19cdbfa1fb4711c00c9c9cf84dbefb0
Author: Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2023-10-26 20:38:41 +0000
Commit: Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2023-10-26 20:38:41 +0000
libprocstat: simplify auxv value conversion
Avoid a weird dance through the union and treat all 32-bit values as
unsigned integers. This avoids sign extension of flags and userspace
pointers.
Reviewed by: markj
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D42198
(cherry picked from commit 9735cc0e41825bb9e95d16433d381ffe4c190f38)
---
lib/libprocstat/libprocstat.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/lib/libprocstat/libprocstat.c b/lib/libprocstat/libprocstat.c
index d27c9f773151..0d7a0bcc2649 100644
--- a/lib/libprocstat/libprocstat.c
+++ b/lib/libprocstat/libprocstat.c
@@ -2417,7 +2417,6 @@ procstat_getauxv32_sysctl(pid_t pid, unsigned int *cntp)
{
Elf_Auxinfo *auxv;
Elf32_Auxinfo *auxv32;
- void *ptr;
size_t len;
unsigned int i, count;
int name[4];
@@ -2451,8 +2450,17 @@ procstat_getauxv32_sysctl(pid_t pid, unsigned int *cntp)
* necessarily true.
*/
auxv[i].a_type = auxv32[i].a_type;
- ptr = &auxv32[i].a_un;
- auxv[i].a_un.a_val = *((uint32_t *)ptr);
+ /*
+ * Don't sign extend values. Existing entries are positive
+ * integers or pointers. Under freebsd32, programs typically
+ * have a full [0, 2^32) address space (perhaps minus the last
+ * page) and treating this as a signed integer would be
+ * confusing since these are not kernel pointers.
+ *
+ * XXX: A more complete translation would be ABI and
+ * type-aware.
+ */
+ auxv[i].a_un.a_val = (uint32_t)auxv32[i].a_un.a_val;
}
*cntp = count;
out: