From: Tobias Stoeckmann <tobias@stoeckmann.org>
To: util-linux@vger.kernel.org
Subject: [PATCH] setproctitle: fix out of boundary access
Date: Mon, 25 Sep 2017 21:55:34 +0200 [thread overview]
Message-ID: <20170925195534.GB25565@localhost> (raw)
A program using setproctitle can trigger an out of boundary access
if an attacker was able to clear the environment before execution.
The check in setproctitle prevents overflows, but does not take into
account that the whole length of the arguments could be 1, which is
possible by supplying such a program name to execlp(3) or using a
symbolic link, e.g. argv[0] = "l", argv[1] = NULL.
Only login uses setproctitle, which is not affected by this
problem due to initializing the environment right before the call.
---
lib/setproctitle.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/lib/setproctitle.c b/lib/setproctitle.c
index 93bc82e47..7168e4658 100644
--- a/lib/setproctitle.c
+++ b/lib/setproctitle.c
@@ -17,7 +17,7 @@
extern char **environ;
static char **argv0;
-static int argv_lth;
+static size_t argv_lth;
void initproctitle (int argc, char **argv)
{
@@ -42,16 +42,17 @@ void initproctitle (int argc, char **argv)
return;
environ[i] = NULL;
- argv0 = argv;
if (i > 0)
- argv_lth = envp[i-1] + strlen(envp[i-1]) - argv0[0];
+ argv_lth = envp[i-1] + strlen(envp[i-1]) - argv[0];
else
- argv_lth = argv0[argc-1] + strlen(argv0[argc-1]) - argv0[0];
+ argv_lth = argv[argc-1] + strlen(argv[argc-1]) - argv[0];
+ if (argv_lth > 1)
+ argv0 = argv;
}
void setproctitle (const char *prog, const char *txt)
{
- int i;
+ size_t i;
char buf[SPT_BUFSIZE];
if (!argv0)
--
2.14.1
next reply other threads:[~2017-09-25 19:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-25 19:55 Tobias Stoeckmann [this message]
2017-09-26 10:12 ` [PATCH] setproctitle: fix out of boundary access Karel Zak
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=20170925195534.GB25565@localhost \
--to=tobias@stoeckmann.org \
--cc=util-linux@vger.kernel.org \
/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.