From owner-freebsd-current@FreeBSD.ORG Sun Dec 28 10:24:18 2003 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E2E4216A4CE for ; Sun, 28 Dec 2003 10:24:18 -0800 (PST) Received: from transport.cksoft.de (transport.cksoft.de [62.111.66.27]) by mx1.FreeBSD.org (Postfix) with ESMTP id 63D1243D31 for ; Sun, 28 Dec 2003 10:24:17 -0800 (PST) (envelope-from bzeeb-lists@lists.zabbadoz.net) Received: from transport.cksoft.de (localhost [127.0.0.1]) by transport.cksoft.de (Postfix) with ESMTP id 8070B1FF9A6; Sun, 28 Dec 2003 19:24:16 +0100 (CET) Received: by transport.cksoft.de (Postfix, from userid 66) id BFBCB1FF90C; Sun, 28 Dec 2003 19:24:14 +0100 (CET) Received: by mail.int.zabbadoz.net (Postfix, from userid 1060) id 46164153ED; Sun, 28 Dec 2003 18:21:09 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mail.int.zabbadoz.net (Postfix) with ESMTP id 43C2B15329; Sun, 28 Dec 2003 18:21:09 +0000 (UTC) Date: Sun, 28 Dec 2003 18:21:09 +0000 (UTC) From: "Bjoern A. Zeeb" X-X-Sender: bz@e0-0.zab2.int.zabbadoz.net To: David Malone In-Reply-To: <20031228180536.GA49762@walton.maths.tcd.ie> Message-ID: References: <20031227205000.GG86308@e-Gitt.NET> <1035.1072561906@critter.freebsd.dk> <20031228180536.GA49762@walton.maths.tcd.ie> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS cksoft-s20020300-20031204bz on transport.cksoft.de cc: freebsd-current@freebsd.org Subject: Re: file descriptor leak in 5.2-RC X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 28 Dec 2003 18:24:19 -0000 On Sun, 28 Dec 2003, David Malone wrote: > > I'd call it a surprise if someone after all had a fix within the next 10 > > hours or so. > > I'm fairly certain I've found the problem (and, indeed, it looks > like I introduced it too while changing how falloc works). You loose > a reference to /dev/null every time you exec a suid program with > at least one of std{in,out,err} closed. I'm guessing that some part > of postfix does this. > > I believe the patch below will fix the problem. I guess I'm too > late for you to test it now? I think it's the correct place... I could not reproduce the problem on a machine with a kernel from late september. Ok, now that we have the patch I can also send a simple program to test it out to the list ... Be aware that local users can eat a lot of fds with that ... on current and 5.2-prereleases --- end --- cat > exec-closed123-ping.c < #ifndef MAX_CHILDS #define MAX_CHILDS 16 #endif static int _execsetuid() { execl("/sbin/ping", "-c", "1", "localhost", NULL); return 1; } int main(int argc, char *argv[]) { int i = 0; pid_t pid; (void) close(0); (void) close(1); (void) close(2); while (i++ < MAX_CHILDS) { pid = fork(); switch (pid) { case 0: _exit(_execsetuid()); } } return 0; } EOF gcc -Wall exec-closed123-ping.c -o exec-closed123-ping sysctl kern.openfiles ./exec-closed123-ping sysctl kern.openfiles --- end --- there should be a difference of 16 in kern.openfiles. -- Bjoern A. Zeeb bzeeb at Zabbadoz dot NeT 56 69 73 69 74 http://www.zabbadoz.net/