From owner-freebsd-fs@FreeBSD.ORG Mon Feb 21 16:06:25 2011 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9093A1065696 for ; Mon, 21 Feb 2011 16:06:25 +0000 (UTC) (envelope-from Mark.Martinec+freebsd@ijs.si) Received: from mail.ijs.si (mail.ijs.si [IPv6:2001:1470:ff80::25]) by mx1.freebsd.org (Postfix) with ESMTP id 0CEBA8FC2A for ; Mon, 21 Feb 2011 16:06:25 +0000 (UTC) Received: from amavis-proxy-ori.ijs.si (localhost [IPv6:::1]) by mail.ijs.si (Postfix) with ESMTP id CAA901D1D9A for ; Mon, 21 Feb 2011 17:06:23 +0100 (CET) Authentication-Results: mail.ijs.si; dkim=pass (1024-bit key) header.i=@ijs.si header.b=CQ/lY4Tl; dkim-adsp=pass DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ijs.si; h= message-id:content-transfer-encoding:content-type:content-type :mime-version:user-agent:date:date:subject:subject:organization :from:from:received:received:received:vbr-info; s=jakla2; t= 1298304380; x=1300896381; bh=GI1paPI3ryNclHAstfF8XUf3UX4HxnX6J2M wn/+2B5w=; b=CQ/lY4Tl8HkVhSSKl99aHgsMr0pXV1n2scAWmjvcY5GrvwMjfWi +ZECrDZzpxLFYFTlMpVCee7A8nLmEhKO0pyvlNZBSBOBgpuqoq5yAuf34ah7YPMs Kd7DJLceLSyhv9oXHOMWg+er3ZbCp0SGUqr7R9ryANR1HYLif6DawMNM= VBR-Info: md=ijs.si; mc=all; mv=dwl.spamhaus.org; X-Virus-Scanned: amavisd-new at ijs.si Received: from mail.ijs.si ([127.0.0.1]) by amavis-proxy-ori.ijs.si (mail.ijs.si [127.0.0.1]) (amavisd-new, port 10012) with ESMTP id Cu0xRJBqgvSg for ; Mon, 21 Feb 2011 17:06:20 +0100 (CET) Received: from edina.ijs.si (unknown [IPv6:2001:1470:ff80:0:2e0:81ff:fe72:51d]) by mail.ijs.si (Postfix) with ESMTP for ; Mon, 21 Feb 2011 17:06:20 +0100 (CET) Received: from neli.ijs.si (neli.ijs.si [193.2.4.95]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by edina.ijs.si (Postfix) with ESMTPSA id A201022F229 for ; Mon, 21 Feb 2011 17:06:18 +0100 (CET) From: Mark Martinec Organization: J. Stefan Institute To: freebsd-fs@freebsd.org Date: Mon, 21 Feb 2011 17:06:18 +0100 User-Agent: KMail/1.13.5 (FreeBSD/8.1-RELEASE-p2; KDE/4.5.5; amd64; ; ) MIME-Version: 1.0 Content-Type: Text/Plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-Id: <201102211706.18084.Mark.Martinec+freebsd@ijs.si> Subject: ftruncate under ZFS requires W file access permission, instead of testing file open mode (O_RDWR) X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Feb 2011 16:06:25 -0000 I filed this as: http://www.freebsd.org/cgi/query-pr.cgi?pr=154873 under a 'standards' category - should be assigned to [freebsd-fs]: standards/154873: ZFS violates POSIX on open/O_CREAT -> ftruncate Description: POSIX.1-2008 requires that the third argument to open(2) on O_CREAT does not affect whether the file is open for reading, writing, or for both. A subsequent ftruncate should not depend on access permission bits of the file, but solely on the read/write flags specified on the open(2). The bug affects a mailer Postfix, which reports a permission problem on ftruncate, affecting the smtpd service when option speed_adjust is requested. As the problem is in the file system violating a POSIX specification and not in the application, it is unlikely that the program will be modified. Reproducible on: FreeBSD 8.1-RELEASE-p2, ZFS: pool version 14, ZFS version 3 as well as on: FreeBSD 8.2-RC3, ZFS: pool version 15, ZFS version 4 How-To-Repeat: Run the following test program. It will report: Error truncating: Permission denied when (cwd) on a ZFS file system, but will pass clean when on UFS or on some other file system. #include #include #include int main(int argc, char *argv[]) { const char fname[] = "truncate-posix-test.tmp"; /* POSIX.1-2008: ( http://www.opengroup.org/onlinepubs/9699919799/ ) * open() [...] O_CREAT [...] The file status flags and file * access modes of the open file description shall be set according * to the value of oflag. [...] The argument following the oflag * argument does not affect whether the file is open for reading, * writing, or for both. * * In other words, read/write access is controlled with the * O_RDWR flags, not the read/write permissions argument. * * Create a file with mode 0, i.e. all access permission bits off: */ int fd = open(fname, O_CREAT|O_RDWR|O_EXCL, 0); if (fd < 0) { perror("Error creating file"); return 1; } if (unlink(fname) < 0) perror("Error unlinking"); /* ftruncate should succeed, * it must not depend on access permission bits, its rights * should solely be governed by an O_RDWR file access flag. * * This FAILS on a ZFS file system, reporting "Permission denied"! */ if (ftruncate(fd,0) < 0) perror("Error truncating"); if (close(fd) < 0) perror("Error closing"); return 0; } Fix: Fix unknown. Work around by not using ZFS, or by allowing less strict access permission bits on open(2) - which may be hard to achieve if code is buried inside some application. Mark