Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 04 Jan 2009 19:06:18 +0100
From:      Christoph Mallon <christoph.mallon@gmx.de>
To:        "David E. O'Brien" <obrien@FreeBSD.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r186504 - head/sbin/mount
Message-ID:  <4960FA9A.1090509@gmx.de>
In-Reply-To: <200812262254.mBQMsrbR052676@svn.freebsd.org>
References:  <200812262254.mBQMsrbR052676@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------040804020300050601020108
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi David,

I'm pretty sure $SUPERNATURAL_BEING_OF_YOUR_CHOICE killed a kitten for 
the ugly hack you added to mount. The moment you overflow a buffer, you 
are in no man's land and there's no escape. I appended a patch, which 
solves this issue once and for all: The argv array gets dynamically 
expanded, when its limit is reached.
Please - for all kittens out there - commit this patch.

	Christoph


David E. O'Brien schrieb:
> Author: obrien
> Date: Fri Dec 26 22:54:53 2008
> New Revision: 186504
> URL: http://svn.freebsd.org/changeset/base/186504
> 
> Log:
>   Make the sub-'argc' static to make it harder to overwrite thru a buffer
>   overflow.
> 
> Modified:
>   head/sbin/mount/mount.c
> 
> Modified: head/sbin/mount/mount.c
> ==============================================================================
> --- head/sbin/mount/mount.c	Fri Dec 26 22:47:11 2008	(r186503)
> +++ head/sbin/mount/mount.c	Fri Dec 26 22:54:53 2008	(r186504)
> @@ -503,9 +503,10 @@ int
>  mountfs(const char *vfstype, const char *spec, const char *name, int flags,
>  	const char *options, const char *mntopts)
>  {
> +	static int argc;
>  	char *argv[MAX_ARGS];
>  	struct statfs sf;
> -	int argc, i, ret;
> +	int i, ret;
>  	char *optbuf, execname[PATH_MAX], mntpath[PATH_MAX];
>  
>  	/* resolve the mountpoint with realpath(3) */
> _______________________________________________
> svn-src-all@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/svn-src-all
> To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
> 


--------------040804020300050601020108
Content-Type: text/plain;
 name="mount.diff"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
 filename="mount.diff"

SW5kZXg6IG1vdW50LmMKPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PQotLS0gbW91bnQuYwkoUmV2aXNpb24gMTg2
NzQwKQorKysgbW91bnQuYwkoQXJiZWl0c2tvcGllKQpAQCAtNjgsMTYgKzY4LDE3IEBACiAj
ZGVmaW5lIE1PVU5UX01FVEFfT1BUSU9OX0ZTVEFCCQkiZnN0YWIiCiAjZGVmaW5lIE1PVU5U
X01FVEFfT1BUSU9OX0NVUlJFTlQJImN1cnJlbnQiCiAKLSNkZWZpbmUJTUFYX0FSR1MJCQkx
MDAKLQogaW50IGRlYnVnLCBmc3RhYl9zdHlsZSwgdmVyYm9zZTsKK3N0YXRpYyBjaGFyICoq
bW50X2FyZ3Y7CitzdGF0aWMgaW50IG1udF9hcmd2X3NpemU7CitzdGF0aWMgaW50IG1udF9h
cmdjOwogCiBjaGFyICAgKmNhdG9wdChjaGFyICosIGNvbnN0IGNoYXIgKik7CiBzdHJ1Y3Qg
c3RhdGZzICpnZXRtbnRwdChjb25zdCBjaGFyICopOwogaW50CWhhc29wdChjb25zdCBjaGFy
ICosIGNvbnN0IGNoYXIgKik7CiBpbnQJaXNtb3VudGVkKHN0cnVjdCBmc3RhYiAqLCBzdHJ1
Y3Qgc3RhdGZzICosIGludCk7CiBpbnQJaXNyZW1vdW50YWJsZShjb25zdCBjaGFyICopOwot
dm9pZAltYW5nbGUoY2hhciAqLCBpbnQgKiwgY2hhciAqW10pOworc3RhdGljIHZvaWQJbWFu
Z2xlKGNoYXIgKik7CiBjaGFyICAgKnVwZGF0ZV9vcHRpb25zKGNoYXIgKiwgY2hhciAqLCBp
bnQpOwogaW50CW1vdW50Zn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cmd2W2FyZ2MrK10gPSBw
OworCQkJCWFwcGVuZF9hcmd2KHN0cmR1cCgiLW8iKSk7CisJCQkJYXBwZW5kX2FyZ3YocCk7
CiAJCQl9CiAJCX0KLQotCSphcmdjcCA9IGFyZ2M7CiB9CiAKIAo=
--------------040804020300050601020108--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4960FA9A.1090509>