From: P J P <ppandit@redhat.com>
To: Qemu Developers <qemu-devel@nongnu.org>
Cc: Riku Voipio <riku.voipio@iki.fi>, Jann Horn <jannh@google.com>,
Prasad J Pandit <pjp@fedoraproject.org>
Subject: [Qemu-devel] [PATCH] linux-user: limit number of arguments to execve
Date: Fri, 3 Mar 2017 16:55:03 +0530 [thread overview]
Message-ID: <20170303112503.32277-1-ppandit@redhat.com> (raw)
From: Prasad J Pandit <pjp@fedoraproject.org>
Limit the number of arguments passed to execve(2) call from
a user program, as large number of them could lead to a bad
guest address error.
Reported-by: Jann Horn <jannh@google.com>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
---
linux-user/syscall.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 9be8e95..c545c12 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7766,6 +7766,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
#endif
case TARGET_NR_execve:
{
+#define ARG_MAX 65535
char **argp, **envp;
int argc, envc;
abi_ulong gp;
@@ -7794,6 +7795,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
envc++;
}
+ if (argc > ARG_MAX || envc > ARG_MAX) {
+ fprintf(stderr,
+ "argc(%d), envc(%d) exceed %d\n", argc, envc, ARG_MAX);
+ ret = -TARGET_EFAULT;
+ break;
+ }
argp = alloca((argc + 1) * sizeof(void *));
envp = alloca((envc + 1) * sizeof(void *));
--
2.9.3
next reply other threads:[~2017-03-03 11:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-03 11:25 P J P [this message]
2017-03-03 14:54 ` [Qemu-devel] [PATCH] linux-user: limit number of arguments to execve Eric Blake
2017-03-03 15:56 ` Peter Maydell
2017-03-03 16:00 ` Jann Horn
2017-03-06 7:20 ` P J P
2017-03-03 15:55 ` Peter Maydell
2017-03-03 15:57 ` Jann Horn
2017-03-03 15:59 ` Peter Maydell
2017-03-06 5:26 ` P J P
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=20170303112503.32277-1-ppandit@redhat.com \
--to=ppandit@redhat.com \
--cc=jannh@google.com \
--cc=pjp@fedoraproject.org \
--cc=qemu-devel@nongnu.org \
--cc=riku.voipio@iki.fi \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).