Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 16 Oct 2011 20:10:05 +0300
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:  <20111016171005.GB50300@deviant.kiev.zoral.com.ua>
In-Reply-To: <86y5wkeuw9.fsf@kopusha.home.net>
References:  <86y5wkeuw9.fsf@kopusha.home.net>

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

--v9Ux+11Zm5mwPlX6
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sun, Oct 16, 2011 at 07:57:57PM +0300, Mikolaj Golub wrote:
> Hi,
>=20
> I have a patch that makes kvm_uread() read from user space using ptrace(2=
).
>=20
> http://people.freebsd.org/~trociny/kvm_uread.ptrace.patch
>=20
> With this change 'ps -e' does not requires procfs(5).
>=20
> Do you like it or there might be some reasons why it is a bad idea?
>=20
> Grepping sources it looks like currently only ps uses kvm_getenvv(3) (and=
 thus
> kvm_uread()).
>=20
> Note, when reading from its own user space it just does bcopy(3), so if a
> wrong address range is passed to kvm_uread() the program will segfault. D=
o we
> need some protection here and what? Masking SIGSEGV?
Ptracing a random process may have a disastrous consequences for the traced
process, caller or system.

For the process, the ptrace(2) can cause spurious signal delivery or EINTR
returns. If the process you attached to is critical for the system operatio=
n,
you can get hung or failed system.

In my opinion, the way to implement the feature is to (re)use
linprocfs_doargv() and provide another kern.proc sysctl to retrieve the
argv and env vectors. Then, ps(1) and procstat(1) can use it, as well as
procfs and linprocfs inside the kernel.

While you are at the code, it would be useful to also export the auxv vecto=
r,
which is immediately before env.

--v9Ux+11Zm5mwPlX6
Content-Type: application/pgp-signature
Content-Disposition: inline

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

iEUEARECAAYFAk6bD+0ACgkQC3+MBN1Mb4gUHQCeIrgATdu4B/y00uhBeWP1OxEi
oiIAkgL4Qm5nLQpUlSuO0HoynlWFw3c=
=4+U2
-----END PGP SIGNATURE-----

--v9Ux+11Zm5mwPlX6--



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