linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: linux-kernel@vger.kernel.org,
	parisc-linux@lists.parisc-linux.org, linux-mm@kvack.org,
	linux-arch@vger.kernel.org, Ollie Wild <aaw@google.com>,
	Ingo Molnar <mingo@elte.hu>, Andi Kleen <ak@suse.de>,
	linux-audit@redhat.com
Subject: Re: [PATCH 2/4] audit: rework execve audit
Date: Tue, 5 Jun 2007 16:39:15 -0700	[thread overview]
Message-ID: <20070605163915.e9cc7bc8.akpm@linux-foundation.org> (raw)
In-Reply-To: <20070605151203.626442000@chello.nl>

On Tue, 05 Jun 2007 17:05:25 +0200
Peter Zijlstra <a.p.zijlstra@chello.nl> wrote:

> The purpose of audit_bprm() is to log the argv array to a userspace daemon at
> the end of the execve system call. Since user-space hasn't had time to run,
> this array is still in pristine state on the process' stack; so no need to copy
> it, we can just grab it from there.
> 
> In order to minimize the damage to audit_log_*() copy each string into a
> temporary kernel buffer first.
> 
> Currently the audit code requires that the full argument vector fits in a
> single packet. So currently it does clip the argv size to a (sysctl) limit, but
> only when execve auditing is enabled.
> 
> If the audit protocol gets extended to allow for multiple packets this check
> can be removed.
> 
> ...
>  

Please try to avoid trigger-happiness with the BUG_ON()s..

>  struct audit_aux_data_socketcall {
> @@ -834,6 +834,47 @@ static int audit_log_pid_context(struct 
>  	return rc;
>  }
>  
> +static void audit_log_execve_info(struct audit_buffer *ab,
> +		struct audit_aux_data_execve *axi)
> +{
> +	int i;
> +	long len;
> +	const char __user *p = (const char __user *)axi->mm->arg_start;
> +
> +	if (axi->mm != current->mm)
> +		return; /* execve failed, no additional info */
> +
> +	for (i = 0; i < axi->argc; i++, p += len) {
> +		long ret;
> +		char *tmp;
> +
> +		len = strnlen_user(p, MAX_ARG_PAGES*PAGE_SIZE);
> +		/*
> +		 * We just created this mm, if we can't find the strings
> +		 * we just copied in something is _very_ wrong.
> +		 */
> +		BUG_ON(!len);
> +
> +		tmp = kmalloc(len, GFP_KERNEL);
> +		if (!tmp) {
> +			audit_panic("out of memory for argv string\n");
> +			break;
> +		}
> +
> +		ret = copy_from_user(tmp, p, len);
> +		/*
> +		 * There is no reason for this copy to be short.
> +		 */
> +		BUG_ON(ret);

You sure?  What happens if another thread does munmap() in parallel?

I think I'll make this WARN_ON just out of principle.

> +		audit_log_format(ab, "a%d=", i);
> +		audit_log_untrustedstring(ab, tmp);
> +		audit_log_format(ab, "\n");
> +
> +		kfree(tmp);
> +	}
> +}
> +
>
> ...
>
> ===================================================================
> --- linux-2.6-2.orig/fs/exec.c	2007-06-05 09:51:42.000000000 +0200
> +++ linux-2.6-2/fs/exec.c	2007-06-05 10:03:11.000000000 +0200
> @@ -1154,6 +1154,7 @@ int do_execve(char * filename,
>  {
>  	struct linux_binprm *bprm;
>  	struct file *file;
> +	unsigned long tmp;
>  	int retval;
>  	int i;
>  
> @@ -1208,9 +1209,11 @@ int do_execve(char * filename,
>  	if (retval < 0)
>  		goto out;
>  
> +	tmp = bprm->p;
>  	retval = copy_strings(bprm->argc, argv, bprm);
>  	if (retval < 0)
>  		goto out;
> +	bprm->argv_len = tmp - bprm->p;





--- a/include/linux/kernel.h~a
+++ a/include/linux/kernel.h
@@ -5,6 +5,8 @@
  * 'kernel.h' contains some often-used function prototypes etc
  */
 
+#define tmp don't call your variables tmp!
+
 #ifdef __KERNEL__
 
 #include <stdarg.h>
_
  



--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2007-06-05 23:39 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-05 15:05 [PATCH 0/4] no MAX_ARG_PAGES Peter Zijlstra
2007-06-05 15:05 ` [PATCH 1/4] arch: personality independent stack top Peter Zijlstra
2007-06-05 15:05 ` [PATCH 2/4] audit: rework execve audit Peter Zijlstra
2007-06-05 23:39   ` Andrew Morton [this message]
2007-06-06  5:52     ` Peter Zijlstra
2007-06-05 15:05 ` [PATCH 3/4] mm: move_page_tables{,_up} Peter Zijlstra
2007-06-05 19:46   ` Christoph Lameter
2007-06-05 23:39   ` Andrew Morton
2007-06-06 19:06   ` Ollie Wild
2007-06-06 19:12     ` Peter Zijlstra
2007-06-06 19:50       ` Ollie Wild
2007-06-06 19:53         ` Peter Zijlstra
2007-06-05 15:05 ` [PATCH 4/4] mm: variable length argument support Peter Zijlstra, Ollie Wild
2007-06-05 23:39   ` Andrew Morton
2007-06-06  0:48     ` Ollie Wild
2007-06-06  6:02     ` Peter Zijlstra
2007-06-06  8:36   ` Andrew Morton
2007-06-06  8:44     ` Paul Mundt
2007-06-06  8:54     ` Peter Zijlstra
2007-06-06  9:06       ` Andrew Morton
2007-06-06  9:12         ` Peter Zijlstra
2007-06-06 14:40           ` [parisc-linux] " Grant Grundler
2007-06-06  9:34         ` Peter Zijlstra
2007-06-06  9:44           ` Paul Mundt
2007-06-06  9:47             ` Peter Zijlstra
2007-06-06  9:53               ` Andi Kleen

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=20070605163915.e9cc7bc8.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=aaw@google.com \
    --cc=ak@suse.de \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-audit@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mingo@elte.hu \
    --cc=parisc-linux@lists.parisc-linux.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox