lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Wed, 21 Feb 2007 15:41:59 -0800
From:	Andrew Morton <akpm@...ux-foundation.org>
To:	Petr Tesa__ík <ptesarik@...e.cz>
Cc:	Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] free pages in remove_arg_zero()

On Tue, 20 Feb 2007 14:29:04 +0100
Petr Tesa____k <ptesarik@...e.cz> wrote:

> I've found a bug when executing scripts:

You've found more than that.

> When a script is loaded, load_script() replaces argv[0] with the
> name of the interpreter and the filename passed to the exec syscall.
> However, there is no guarantee that the length of the interpreter
> name plus the length of the filename is greater than the length of
> the original argv[0]. If the difference happens to cross a page boundary,
> setup_arg_pages() will call install_arg_page() with an address outside
> the VMA.
> 
> Therefore, remove_arg_zero() must free all pages which would be unused
> after the argument is removed.
> 
> Signed-off-by: Petr Tesarik <ptesarik@...e.cz>
> 
> --- linux-sles9.orig/fs/exec.c
> +++ linux-sles9/fs/exec.c
> @@ -1000,6 +1000,8 @@ void remove_arg_zero(struct linux_binprm
>  				continue;
>  			offset = 0;
>  			kunmap_atomic(kaddr, KM_USER0);
> +			__free_page(page);
> +			bprm->page[bprm->p/PAGE_SIZE - 1] = NULL;
>  inside:
>  			page = bprm->page[bprm->p/PAGE_SIZE];
>  			kaddr = kmap_atomic(page, KM_USER0);

I am not surprised that remove_arg_zero() is buggy.  Let us look at the
stupid thing:

void remove_arg_zero(struct linux_binprm *bprm)
{
	if (bprm->argc) {
		unsigned long offset;
		char * kaddr;
		struct page *page;

		offset = bprm->p % PAGE_SIZE;
		goto inside;

		while (bprm->p++, *(kaddr+offset++)) {
			if (offset != PAGE_SIZE)
				continue;
			offset = 0;
			kunmap_atomic(kaddr, KM_USER0);
inside:
			page = bprm->page[bprm->p/PAGE_SIZE];
			kaddr = kmap_atomic(page, KM_USER0);
		}
		kunmap_atomic(kaddr, KM_USER0);
		bprm->argc--;
	}
}

I mean.... what the hell?

As you appear to have managed to work out what the sorry thing is trying to
do, would you have time to simply rip it out and completely rewrite it,
including a nice comment telling the world what this function's function is?

Because what we have there is beyond repairing.

Thanks.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ