Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 1 Nov 2011 12:55:34 +0200
From:      Kostik Belousov <kostikbel@gmail.com>
To:        Mikolaj Golub <trociny@freebsd.org>
Cc:        freebsd-hackers@freebsd.org, Robert Watson <rwatson@freebsd.org>
Subject:   Re: "ps -e" without procfs(5)
Message-ID:  <20111101105534.GT50300@deviant.kiev.zoral.com.ua>
In-Reply-To: <86boswjp7k.fsf@in138.ua3>
References:  <86y5wkeuw9.fsf@kopusha.home.net> <20111016171005.GB50300@deviant.kiev.zoral.com.ua> <86aa8qozyx.fsf@kopusha.home.net> <20111025082451.GO50300@deviant.kiev.zoral.com.ua> <86aa8k2im0.fsf@kopusha.home.net> <20111031094948.GB50300@deviant.kiev.zoral.com.ua> <86boswjp7k.fsf@in138.ua3>

next in thread | previous in thread | raw e-mail | index | archive | help

--a0dfbevZYcQh5kCn
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Tue, Nov 01, 2011 at 09:07:11AM +0200, Mikolaj Golub wrote:
>=20
> On Mon, 31 Oct 2011 11:49:48 +0200 Kostik Belousov wrote:
>=20
>  KB> For PROC_ARG and PROC_ENV, you blindly trust the read values of the =
arg and
>  KB> env vector sizes. This can easily cause kernel panics due to unabili=
ty to
>  KB> malloc the requested memory. I recommend to put some clump, and twice
>  KB> of (PATH_MAX + ARG_MAX) is probably enough (see kern_exec.c, in part=
icular,
>  KB> exec_alloc_args). Also, you might use the swappable memory for the s=
trings
>  KB> as well, in the style of exec_alloc_args().
>=20
> After looking at it more closely, I am not sure if I need to use
> exec_alloc_args. I malloc explicitly only for array vector (proc_vector).=
 And
> actually it should be much smaller than 2 * (PATH_MAX + ARG_MAX). Current=
ly in
> linprocfs the limit is 512 entries:
>=20
>         #define MAX_ARGV_STR    512     /* Max number of argv-like string=
s */
>=20
> The same limit is in libkvm:
>=20
>         /*
>          * Check that there aren't an unreasonable number of arguments,
>          * and that the address is in user space.  Special test for
>          * VM_MIN_ADDRESS as it evaluates to zero, but is not a simple ze=
ro
>          * constant for some archs.  We cannot use the pre-processor here=
 and
>          * for some archs the compiler would trigger a signedness warning.
>          */
>         if (narg > 512 || addr + 1 < VM_MIN_ADDRESS + 1 || addr >=3D VM_M=
AXUSER_ADDRESS)
>                 return (0);
>=20
> (BTW, may be the VM_MIN_ADDRESS - VM_MAXUSER_ADDRESS is worth adding in my
> code too?)
>=20
> So it looks like I should use the same limit (512 * sizeof(char *)) for t=
he
> allocated array. I could use exec_alloc_args() for the allocation but it =
would
> reqire some changes: I would have to free using kmem_free_wakeup(), which
> requires size of the region, while I return the number of entries. So I'd
> rather not use exec_alloc_args() for vector allocation because the benefi=
t is
> not significant here.
>=20
> For strings I use sbuf and set it up using sbuf_new_for_sysctl. I could s=
et it
> up manually as SBUF_FIXEDLEN allocating buf (up to 2 * (PATH_MAX + ARG_MA=
X))
> with exec_alloc_args() but this would complicate things a little. Do you =
think
> it is worth doing?
I mean using the swappable memory for strings, i.e. for the data you are
currently store in sbuf. It indeed may be tricky, it was only an idea.

--a0dfbevZYcQh5kCn
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.18 (FreeBSD)

iEYEARECAAYFAk6v0CYACgkQC3+MBN1Mb4jNzgCghfAuh6dws+2TLXLFotDUIAXb
z2IAnA9ZieBI7GugXFeqZcXz7olsr1G1
=fEmU
-----END PGP SIGNATURE-----

--a0dfbevZYcQh5kCn--



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