* [PATCH] libselinux: avcstat: reject out-of-range interval values
@ 2026-10-08 7:27 Evgeniy Gorbanyov
2026-10-08 14:58 ` Stephen Smalley
0 siblings, 1 reply; 4+ messages in thread
From: Evgeniy Gorbanyov @ 2026-10-08 7:27 UTC (permalink / raw)
To: selinux; +Cc: Evgeniy Gorbanyov
strtoul() returns unsigned long, but avcstat stored the result in a
signed int and passed it to sleep(). A value above INT_MAX becomes
negative, and sleep() then treats it as a large unsigned duration.
Compare the full strtoul() result with INT_MAX before narrowing it.
Signed-off-by: Evgeniy Gorbanyov <esgor@altlinux.org>
---
libselinux/utils/avcstat.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/libselinux/utils/avcstat.c b/libselinux/utils/avcstat.c
index 640a7a05..0c534f51 100644
--- a/libselinux/utils/avcstat.c
+++ b/libselinux/utils/avcstat.c
@@ -13,6 +13,7 @@
#include <libgen.h>
#include <stdarg.h>
#include <errno.h>
+#include <limits.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
@@ -122,9 +123,9 @@ int main(int argc, char **argv)
if (optind < argc) {
char *arg = argv[optind];
- unsigned int n = strtoul(arg, NULL, 10);
+ unsigned long n = strtoul(arg, NULL, 10);
- if (errno == ERANGE) {
+ if (errno == ERANGE || n > INT_MAX) {
usage();
die("invalid interval \'%s\'", arg);
}
--
2.50.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] libselinux: avcstat: reject out-of-range interval values
2026-10-08 7:27 [PATCH] libselinux: avcstat: reject out-of-range interval values Evgeniy Gorbanyov
@ 2026-10-08 14:58 ` Stephen Smalley
2026-10-09 5:57 ` [PATCH v2] " Evgeniy Gorbanyov
0 siblings, 1 reply; 4+ messages in thread
From: Stephen Smalley @ 2026-10-08 14:58 UTC (permalink / raw)
To: Evgeniy Gorbanyov; +Cc: selinux
On Thu, Oct 8, 2026 at 3:33 AM Evgeniy Gorbanyov <esgor@altlinux.org> wrote:
>
> strtoul() returns unsigned long, but avcstat stored the result in a
> signed int and passed it to sleep(). A value above INT_MAX becomes
> negative, and sleep() then treats it as a large unsigned duration.
> Compare the full strtoul() result with INT_MAX before narrowing it.
>
> Signed-off-by: Evgeniy Gorbanyov <esgor@altlinux.org>
> ---
> libselinux/utils/avcstat.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/libselinux/utils/avcstat.c b/libselinux/utils/avcstat.c
> index 640a7a05..0c534f51 100644
> --- a/libselinux/utils/avcstat.c
> +++ b/libselinux/utils/avcstat.c
> @@ -13,6 +13,7 @@
> #include <libgen.h>
> #include <stdarg.h>
> #include <errno.h>
> +#include <limits.h>
> #include <string.h>
> #include <fcntl.h>
> #include <unistd.h>
> @@ -122,9 +123,9 @@ int main(int argc, char **argv)
>
> if (optind < argc) {
> char *arg = argv[optind];
> - unsigned int n = strtoul(arg, NULL, 10);
> + unsigned long n = strtoul(arg, NULL, 10);
>
> - if (errno == ERANGE) {
> + if (errno == ERANGE || n > INT_MAX) {
Since you are touching this: errno is checked for ERANGE but never
cleared before the strtoul() call so a stale ERANGE from earlier would
reject a valid interval. Pre-existing and probably not reachable with
the current call sequence, but addin errno = 0; before strtoul() would
make the check future-proof. Up to you whether you fold it in and or
leave it for a follow-up.
Otherwise,
Reviewed-by: Stephen Smalley <stephen.smalley.work@gmail.com>
> usage();
> die("invalid interval \'%s\'", arg);
> }
> --
> 2.50.1
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v2] libselinux: avcstat: reject out-of-range interval values
2026-10-08 14:58 ` Stephen Smalley
@ 2026-10-09 5:57 ` Evgeniy Gorbanyov
2026-10-09 12:29 ` Stephen Smalley
0 siblings, 1 reply; 4+ messages in thread
From: Evgeniy Gorbanyov @ 2026-10-09 5:57 UTC (permalink / raw)
To: selinux; +Cc: stephen.smalley.work, Evgeniy Gorbanyov
strtoul() returns unsigned long, but avcstat stored the result in a
signed int and passed it to sleep(). A value above INT_MAX becomes
negative, and sleep() then treats it as a large unsigned duration.
Compare the full strtoul() result with INT_MAX before narrowing it.
Clear errno before strtoul() so a stale ERANGE cannot reject a valid
interval.
Signed-off-by: Evgeniy Gorbanyov <esgor@altlinux.org>
Reviewed-by: Stephen Smalley <stephen.smalley.work@gmail.com>
---
libselinux/utils/avcstat.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/libselinux/utils/avcstat.c b/libselinux/utils/avcstat.c
index 640a7a05..c7658792 100644
--- a/libselinux/utils/avcstat.c
+++ b/libselinux/utils/avcstat.c
@@ -13,6 +13,7 @@
#include <libgen.h>
#include <stdarg.h>
#include <errno.h>
+#include <limits.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
@@ -122,9 +123,12 @@ int main(int argc, char **argv)
if (optind < argc) {
char *arg = argv[optind];
- unsigned int n = strtoul(arg, NULL, 10);
+ unsigned long n;
- if (errno == ERANGE) {
+ errno = 0;
+ n = strtoul(arg, NULL, 10);
+
+ if (errno == ERANGE || n > INT_MAX) {
usage();
die("invalid interval \'%s\'", arg);
}
--
2.50.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v2] libselinux: avcstat: reject out-of-range interval values
2026-10-09 5:57 ` [PATCH v2] " Evgeniy Gorbanyov
@ 2026-10-09 12:29 ` Stephen Smalley
0 siblings, 0 replies; 4+ messages in thread
From: Stephen Smalley @ 2026-10-09 12:29 UTC (permalink / raw)
To: Evgeniy Gorbanyov; +Cc: selinux
On Fri, Oct 9, 2026 at 1:57 AM Evgeniy Gorbanyov <esgor@altlinux.org> wrote:
>
> strtoul() returns unsigned long, but avcstat stored the result in a
> signed int and passed it to sleep(). A value above INT_MAX becomes
> negative, and sleep() then treats it as a large unsigned duration.
> Compare the full strtoul() result with INT_MAX before narrowing it.
>
> Clear errno before strtoul() so a stale ERANGE cannot reject a valid
> interval.
>
> Signed-off-by: Evgeniy Gorbanyov <esgor@altlinux.org>
> Reviewed-by: Stephen Smalley <stephen.smalley.work@gmail.com>
Thanks, merged.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-10-09 12:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-08 7:27 [PATCH] libselinux: avcstat: reject out-of-range interval values Evgeniy Gorbanyov
2026-10-08 14:58 ` Stephen Smalley
2026-10-09 5:57 ` [PATCH v2] " Evgeniy Gorbanyov
2026-10-09 12:29 ` Stephen Smalley
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.