From: Evgeniy Gorbanyov <esgor@altlinux.org>
To: selinux@vger.kernel.org
Cc: stephen.smalley.work@gmail.com, Evgeniy Gorbanyov <esgor@altlinux.org>
Subject: [PATCH v2] libselinux: avcstat: reject out-of-range interval values
Date: Fri, 9 Oct 2026 11:57:13 +0600 [thread overview]
Message-ID: <20261009055713.16085-1-esgor@altlinux.org> (raw)
In-Reply-To: <CAEjxPJ4Uh+_GsevF3xtxeKPkz=KAgwj-=+JNq3Uc7SWrLDq04Q@mail.gmail.com>
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
next prev parent reply other threads:[~2026-10-09 5:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Evgeniy Gorbanyov [this message]
2026-10-09 12:29 ` [PATCH v2] " Stephen Smalley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261009055713.16085-1-esgor@altlinux.org \
--to=esgor@altlinux.org \
--cc=selinux@vger.kernel.org \
--cc=stephen.smalley.work@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.