Module Name: src
Committed By: riastradh
Date: Tue Jul 23 22:00:00 UTC 2024
Modified Files:
src/libexec/ld.elf_so: tls.c
Log Message:
ld.elf_so: Fix off-by-one error in common __tls_get_addr.
DTV_MAX_INDEX(dtv) is an _inclusive_ upper bound, i.e., the actual
maximum value of the allowed indices. It is not an exclusive upper
bound -- it is not the number of allowed indices.
This off-by-one doesn't hurt correctness, but it may hurt performance
by using the slow path when the fast path would be safe.
Found by pho@ in PR lib/58154.
To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/libexec/ld.elf_so/tls.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/libexec/ld.elf_so/tls.c
diff -u src/libexec/ld.elf_so/tls.c:1.21 src/libexec/ld.elf_so/tls.c:1.22
--- src/libexec/ld.elf_so/tls.c:1.21 Mon Jul 22 23:15:57 2024
+++ src/libexec/ld.elf_so/tls.c Tue Jul 23 22:00:00 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: tls.c,v 1.21 2024/07/22 23:15:57 riastradh Exp $ */
+/* $NetBSD: tls.c,v 1.22 2024/07/23 22:00:00 riastradh Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: tls.c,v 1.21 2024/07/22 23:15:57 riastradh Exp $");
+__RCSID("$NetBSD: tls.c,v 1.22 2024/07/23 22:00:00 riastradh Exp $");
/*
* Thread-local storage
@@ -523,7 +523,7 @@ __tls_get_addr(void *arg_)
* application bug if code of the module is still running at
* that point.
*/
- if (__predict_true(idx < DTV_MAX_INDEX(dtv) && dtv[idx] != NULL))
+ if (__predict_true(idx <= DTV_MAX_INDEX(dtv) && dtv[idx] != NULL))
return (uint8_t *)dtv[idx] + offset;
return _rtld_tls_get_addr(tcb, idx, offset);