2.4 setproctitle breakage (was reiserfs marathon thread)

From: Nick Holloway (Nick.Holloway@pyrites.org.uk)
Date: Tue Jun 13 2000 - 17:37:33 EST


khim@sch57.msk.ru (Khimenko Victor) wrote:
> Alan Cox (alan@lxorguk.ukuu.org.uk) wrote:
> >> wu-ftpd's ftpwho works on Irix, HP-UX, Solaris and more (perhaps even more
> >> then PostgreSQL). It does not work with Linux 2.3.x ...
>
> AC> It works on 2.2.x but not 2.3.x - can you tell me more ? I dont like things
> AC> stopping working.
>
> General reaction was "sendmail, ftpd and bunch of other daemons using
> setproctitle(3) and hack used in 2.2 does not work anymore but we do not
> bother at all since setproctitle(3) is not POSIX anyway [...]

The problem is that /proc/$$/cmdline only returns the number of bytes
initially set up for it.

I posted a patch in March which changes the behaviour of /proc/$$/cmdline
to be compatable with that of 2.2 -- so an application can use the
environment space in addition to the command line for the purpose of
setproctitle.

The patch is against 2.3.99-pre1, but a) I'm too tired to do anything to
check it is up to date right now, and b) I don't believe that anything
has changed in this area of /proc.

===========================================================================

--cNdxnHkX5QqsyA0e
Content-Type: text/plain; charset=us-ascii

Here is a change to proc_pid_cmdline so that applications that attempt to
present their current state to ps(1) using some variant of setproctitle(3)
work in the same manner under 2.3 as they do under 2.2.

Whereas 2.2 would look into the environment area to return the full
information available from setproctitle(3), 2.3 only looks the area set
aside for the arguments.

This patch uses the following heuristic. If the nul byte at the end
of the argument area has been overwritten, then setproctitle(3) is
being used. If there is no nul in the argument area, then the contents
of environment area up to the first nul is also included.

If the argument area is not modified, then the only overhead is checking
a byte in the buffer to be returned to the user. It is not possible to
get /proc/$$/cmdline to look outside the argument and environment space,
nor to return more than 1 page of data. I've left /proc/$$/environ
to return random garbage if setproctitle(3) is being used -- behaviour
compatable with 2.2.

I've given this a quick workout using assignments to $0 in Perl. I'd like
others to have a look at this and try it out, and see how it works with
their favorite applications.

-- 
 `O O'  | Nick.Holloway@alfie.demon.co.uk
// ^ \\ | http://www.alfie.demon.co.uk/

--cNdxnHkX5QqsyA0e Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="setproctitle.diff"

--- linux-2.3/fs/proc/base.c Mon Mar 20 21:06:55 2000 +++ linux-2.3-hacked/fs/proc/base.c Mon Mar 20 20:42:02 2000 @@ -123,6 +123,24 @@ if (len > PAGE_SIZE) len = PAGE_SIZE; res = access_process_vm(task, mm->arg_start, buffer, len, 0); + // If the nul at the end of args has been overwritten, then + // assume application is using setproctitle(3). + if ( res > 0 && buffer[res-1] != '\0' ) + { + len = strnlen( buffer, res ); + if ( len < res ) + { + res = len; + } + else + { + len = mm->env_end - mm->env_start; + if (len > PAGE_SIZE - res) + len = PAGE_SIZE - res; + res += access_process_vm(task, mm->env_start, buffer+res, len, 0); + res = strnlen( buffer, res ); + } + } } return res; }

--cNdxnHkX5QqsyA0e--

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



This archive was generated by hypermail 2b29 : Thu Jun 15 2000 - 21:00:29 EST