From owner-freebsd-hackers@FreeBSD.ORG Sat Nov 5 11:01:32 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B593A1065670; Sat, 5 Nov 2011 11:01:32 +0000 (UTC) (envelope-from to.my.trociny@gmail.com) Received: from mail-bw0-f54.google.com (mail-bw0-f54.google.com [209.85.214.54]) by mx1.freebsd.org (Postfix) with ESMTP id 165698FC14; Sat, 5 Nov 2011 11:01:31 +0000 (UTC) Received: by bkbzs8 with SMTP id zs8so40289bkb.13 for ; Sat, 05 Nov 2011 04:01:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:references:x-comment-to:sender:date:in-reply-to :message-id:user-agent:mime-version:content-type; bh=wKc26XfdCTmDqcwrb/5T30JHwK9ks+V5aiuYlu+WRF8=; b=gfuKy7SrK1Dc2fwkb8d7zFWLfDZvfnhHHO3AWQk/Vh5mnO2MdtGJFN9F6Zunnmrh9t ONQ0eqlLDWVoU9eyIxPKEmQXun2yODtoO5ZFRf8X0UsobDzpxytajnGnU7dmVJHBOQAc OFQYBBOFCpTNC6iyRa019w6Z3jDHFQPeSgFm4= Received: by 10.204.146.65 with SMTP id g1mr14166501bkv.63.1320490890705; Sat, 05 Nov 2011 04:01:30 -0700 (PDT) Received: from localhost ([95.69.173.122]) by mx.google.com with ESMTPS id k13sm9782558fah.0.2011.11.05.04.01.26 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 05 Nov 2011 04:01:27 -0700 (PDT) From: Mikolaj Golub To: Kostik Belousov 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> X-Comment-To: Kostik Belousov Sender: Mikolaj Golub Date: Sat, 05 Nov 2011 13:01:23 +0200 In-Reply-To: <20111031094948.GB50300@deviant.kiev.zoral.com.ua> (Kostik Belousov's message of "Mon, 31 Oct 2011 11:49:48 +0200") Message-ID: <86r51msuik.fsf@kopusha.home.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: freebsd-hackers@freebsd.org, Robert Watson Subject: Re: "ps -e" without procfs(5) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 05 Nov 2011 11:01:32 -0000 On Mon, 31 Oct 2011 11:49:48 +0200 Kostik Belousov wrote: KB> I suspect this is my bug: Reading the GET_PS_STRINGS_CHUNK_SZ may validly KB> return EFAULT if the string is shorter than the chunk and aligned at KB> the end of the page, assuming the next page is not mapped. There should KB> be a fallback to fubyte() read loop. I remember that copyinstr() was KB> unsuitable. Hm, I thought that this issue was only for reading arg and env strings (which could be shorter than GET_PS_STRINGS_CHUNK_SZ), but investigating the cases when EFAULT was returned in my tests (running buildworld and procstat in loop) I saw that it also returned when reading other objects (like struct ps_strings), and a fallback to fubyte() read loop was successful in those cases too. So I updated the patch to do fallback for any type of read (although it does not contain a good comment explaining why fubyte() read might succeed when proc_rwmem() failed). Also there were the cases when EFAULT was returned because arg vector contained the NULL pointer. I observed this for sh processes. In lib/libc/gen/setproctitle.c I found this comment: oargc = ps_strings->ps_nargvstr; oargv = ps_strings->ps_argvstr; for (i = len = 0; i < oargc; i++) { /* * The program may have scribbled into its * argv array, e.g., to remove some arguments. * If that has happened, break out before * trying to call strlen on a NULL pointer. */ if (oargv[i] == NULL) { oargc = i; break; } I have updated my patch to do the same. Running buildworld test after these changes I have observed EFAULT only once, for cc process, when argv contained a pointer to 0x40. Also, for kern.proc.args some times errors like below are observed: procstat: sysctl: kern.proc.args: 58002: 8: Exec format error And for kern.proc.env: procstat: sysctl: kern.proc.env: 81352: 16: Device busy But I have not investigated these cases yet. The update version: http://people.freebsd.org/~trociny/env.sys.2.patch -- Mikolaj Golub