From nobody@FreeBSD.org  Tue Aug 10 12:06:55 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 3CCB3106571A
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 10 Aug 2010 12:06:55 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 2C7268FC20
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 10 Aug 2010 12:06:55 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o7AC6shN033712
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 10 Aug 2010 12:06:54 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o7AC6sJI033709;
	Tue, 10 Aug 2010 12:06:54 GMT
	(envelope-from nobody)
Message-Id: <201008101206.o7AC6sJI033709@www.freebsd.org>
Date: Tue, 10 Aug 2010 12:06:54 GMT
From: Daniel Zhelev <daniel@zhelev.biz>
To: freebsd-gnats-submit@FreeBSD.org
Subject: chflags sappend on zfs not working right
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         149495
>Category:       kern
>Synopsis:       [zfs] chflags sappend on zfs not working right
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-fs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Aug 10 12:10:02 UTC 2010
>Closed-Date:    Sun Nov 28 09:22:35 UTC 2010
>Last-Modified:  Mon Feb 20 19:20:14 UTC 2012
>Originator:     Daniel Zhelev
>Release:        8.1-RELEASE
>Organization:
none
>Environment:
root@wolfdale~# uname -a
FreeBSD wolfdale.sgate.org 8.1-RELEASE FreeBSD 8.1-RELEASE #0: Mon Jul 19 02:36:49 UTC 2010     root@mason.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  amd64
root@wolfdale~# 

>Description:
chmod o= /var/log/critical
chflags sappnd /var/log/critical
chflags sappnd /var/log/critical/* 
root@wolfdale/var/log/critical# echo "test" > critical.log
critical.log: Operation not permitted.
root@wolfdale/var/log/critical# echo "test" >> critical.log
root@wolfdale/var/log/critical# grep test critical.log 
Filesystem    1K-blocks Used   Avail Capacity  Mounted on
zroot/var/log   5242880  106 5242774     0%    /var/log
root@wolfdale~# sysctl kern.securelevel
kern.securelevel: 1

Flag sappnd/sappend is permitting also write to file not only delete on ZFS mounts. 
Submitting but-report since it is marked as done in http://wiki.freebsd.org/ZFS
Not tested other flags, please contact me if you need me to.


>How-To-Repeat:
Described above.
>Fix:
Using zvol with UFS on it - workaround 

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-fs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Tue Aug 10 15:13:17 UTC 2010 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=149495 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/149495: commit references a PR
Date: Fri,  8 Oct 2010 23:01:43 +0000 (UTC)

 Author: mm
 Date: Fri Oct  8 23:01:38 2010
 New Revision: 213634
 URL: http://svn.freebsd.org/changeset/base/213634
 
 Log:
   Change FAPPEND to IO_APPEND as this is a ioflag and not a fflag.
   This corrects writing to append-only files on ZFS.
   
   PR:		kern/149495 [1], kern/151082 [2]
   Submitted by:	Daniel Zhelev <daniel@zhelev.biz> [1], Michael Naef <cal@linu.gs> [2]
   Approved by:	delphij (mentor)
   MFC after:	1 week
 
 Modified:
   head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
 
 Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
 ==============================================================================
 --- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c	Fri Oct  8 21:54:33 2010	(r213633)
 +++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c	Fri Oct  8 23:01:38 2010	(r213634)
 @@ -755,7 +755,7 @@ zfs_write(vnode_t *vp, uio_t *uio, int i
  	 */
  	pflags = zp->z_phys->zp_flags;
  	if ((pflags & (ZFS_IMMUTABLE | ZFS_READONLY)) ||
 -	    ((pflags & ZFS_APPENDONLY) && !(ioflag & FAPPEND) &&
 +	    ((pflags & ZFS_APPENDONLY) && !(ioflag & IO_APPEND) &&
  	    (uio->uio_loffset < zp->z_phys->zp_size))) {
  		ZFS_EXIT(zfsvfs);
  		return (EPERM);
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->closed 
State-Changed-By: jh 
State-Changed-When: Sun Nov 28 09:22:33 UTC 2010 
State-Changed-Why:  
Duplicate of kern/151082. Patched in head (r213634). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=149495 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/149495: commit references a PR
Date: Sun, 28 Nov 2010 09:52:14 +0000 (UTC)

 Author: mm
 Date: Sun Nov 28 09:52:06 2010
 New Revision: 215992
 URL: http://svn.freebsd.org/changeset/base/215992
 
 Log:
   MFC r213634, r213673:
   
   MFC r213634:
   Change FAPPEND to IO_APPEND as this is a ioflag and not a fflag.
   This corrects writing to append-only files on ZFS.
   
   MFC r213673 (pjd):
   Provide internal ioflags() function that converts ioflag provided by FreeBSD's
   VFS to OpenSolaris-specific ioflag expected by ZFS. Use it for read and write
   operations.
   
   PR:		kern/149495 [1], kern/151082 [2]
   Submitted by:	Daniel Zhelev <daniel@zhelev.biz> [1], Michael Naef <cal@linu.gs> [2]
   Reviewed by:	mm (r213673)
   Approved by:	delphij (mentor)
 
 Modified:
   stable/8/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
 Directory Properties:
   stable/8/sys/   (props changed)
   stable/8/sys/amd64/include/xen/   (props changed)
   stable/8/sys/cddl/contrib/opensolaris/   (props changed)
   stable/8/sys/contrib/dev/acpica/   (props changed)
   stable/8/sys/contrib/pf/   (props changed)
 
 Modified: stable/8/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
 ==============================================================================
 --- stable/8/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c	Sun Nov 28 09:35:56 2010	(r215991)
 +++ stable/8/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c	Sun Nov 28 09:52:06 2010	(r215992)
 @@ -682,7 +682,7 @@ zfs_prefault_write(ssize_t n, struct uio
   *	IN:	vp	- vnode of file to be written to.
   *		uio	- structure supplying write location, range info,
   *			  and data buffer.
 - *		ioflag	- IO_APPEND flag set if in append mode.
 + *		ioflag	- FAPPEND flag set if in append mode.
   *		cr	- credentials of caller.
   *		ct	- caller context (NFS/CIFS fem monitor only)
   *
 @@ -749,7 +749,7 @@ zfs_write(vnode_t *vp, uio_t *uio, int i
  	/*
  	 * If in append mode, set the io offset pointer to eof.
  	 */
 -	if (ioflag & IO_APPEND) {
 +	if (ioflag & FAPPEND) {
  		/*
  		 * Range lock for a file append:
  		 * The value for the start of range will be determined by
 @@ -4176,6 +4176,21 @@ zfs_setsecattr(vnode_t *vp, vsecattr_t *
  }
  
  static int
 +ioflags(int ioflags)
 +{
 +	int flags = 0;
 +
 +	if (ioflags & IO_APPEND)
 +		flags |= FAPPEND;
 +	if (ioflags & IO_NDELAY)
 +        	flags |= FNONBLOCK;
 +	if (ioflags & IO_SYNC)
 +		flags |= (FSYNC | FDSYNC | FRSYNC);
 +
 +	return (flags);
 +}
 +
 +static int
  zfs_getpages(struct vnode *vp, vm_page_t *m, int count, int reqpage)
  {
  	znode_t *zp = VTOZ(vp);
 @@ -4322,7 +4337,8 @@ zfs_freebsd_read(ap)
  	} */ *ap;
  {
  
 -	return (zfs_read(ap->a_vp, ap->a_uio, ap->a_ioflag, ap->a_cred, NULL));
 +	return (zfs_read(ap->a_vp, ap->a_uio, ioflags(ap->a_ioflag),
 +	    ap->a_cred, NULL));
  }
  
  static int
 @@ -4335,7 +4351,8 @@ zfs_freebsd_write(ap)
  	} */ *ap;
  {
  
 -	return (zfs_write(ap->a_vp, ap->a_uio, ap->a_ioflag, ap->a_cred, NULL));
 +	return (zfs_write(ap->a_vp, ap->a_uio, ioflags(ap->a_ioflag),
 +	    ap->a_cred, NULL));
  }
  
  static int
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/149495: commit references a PR
Date: Sun, 28 Nov 2010 10:05:33 +0000 (UTC)

 Author: mm
 Date: Sun Nov 28 10:05:26 2010
 New Revision: 215993
 URL: http://svn.freebsd.org/changeset/base/215993
 
 Log:
   MFC r213634, r213673:
   
   MFC r213634:
   Change FAPPEND to IO_APPEND as this is a ioflag and not a fflag.
   This corrects writing to append-only files on ZFS.
   
   MFC r213673 (pjd):
   Provide internal ioflags() function that converts ioflag provided by FreeBSD's
   VFS to OpenSolaris-specific ioflag expected by ZFS. Use it for read and write
   operations.
   
   PR:		kern/149495 [1], kern/151082 [2]
   Submitted by:	Daniel Zhelev <daniel@zhelev.biz> [1], Michael Naef <cal@linu.gs> [2]
   Reviewed by:	mm (r213673)
   Approved by:	delphij (mentor)
 
 Modified:
   stable/7/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
 Directory Properties:
   stable/7/sys/   (props changed)
   stable/7/sys/cddl/contrib/opensolaris/   (props changed)
   stable/7/sys/contrib/dev/acpica/   (props changed)
   stable/7/sys/contrib/pf/   (props changed)
 
 Modified: stable/7/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
 ==============================================================================
 --- stable/7/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c	Sun Nov 28 09:52:06 2010	(r215992)
 +++ stable/7/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c	Sun Nov 28 10:05:26 2010	(r215993)
 @@ -660,7 +660,7 @@ zfs_prefault_write(ssize_t n, struct uio
   *	IN:	vp	- vnode of file to be written to.
   *		uio	- structure supplying write location, range info,
   *			  and data buffer.
 - *		ioflag	- IO_APPEND flag set if in append mode.
 + *		ioflag	- FAPPEND flag set if in append mode.
   *		cr	- credentials of caller.
   *		ct	- caller context (NFS/CIFS fem monitor only)
   *
 @@ -726,7 +726,7 @@ zfs_write(vnode_t *vp, uio_t *uio, int i
  	/*
  	 * If in append mode, set the io offset pointer to eof.
  	 */
 -	if (ioflag & IO_APPEND) {
 +	if (ioflag & FAPPEND) {
  		/*
  		 * Range lock for a file append:
  		 * The value for the start of range will be determined by
 @@ -3887,6 +3887,21 @@ zfs_setsecattr(vnode_t *vp, vsecattr_t *
  #endif	/* TODO */
  
  static int
 +ioflags(int ioflags)
 +{
 +	int flags = 0;
 +
 +	if (ioflags & IO_APPEND)
 +		flags |= FAPPEND;
 +	if (ioflags & IO_NDELAY)
 +        	flags |= FNONBLOCK;
 +	if (ioflags & IO_SYNC)
 +		flags |= (FSYNC | FDSYNC | FRSYNC);
 +
 +	return (flags);
 +}
 +
 +static int
  zfs_freebsd_open(ap)
  	struct vop_open_args /* {
  		struct vnode *a_vp;
 @@ -3944,7 +3959,8 @@ zfs_freebsd_read(ap)
  	} */ *ap;
  {
  
 -	return (zfs_read(ap->a_vp, ap->a_uio, ap->a_ioflag, ap->a_cred, NULL));
 +	return (zfs_read(ap->a_vp, ap->a_uio, ioflags(ap->a_ioflag),
 +	    ap->a_cred, NULL));
  }
  
  static int
 @@ -3957,7 +3973,8 @@ zfs_freebsd_write(ap)
  	} */ *ap;
  {
  
 -	return (zfs_write(ap->a_vp, ap->a_uio, ap->a_ioflag, ap->a_cred, NULL));
 +	return (zfs_write(ap->a_vp, ap->a_uio, ioflags(ap->a_ioflag),
 +	    ap->a_cred, NULL));
  }
  
  static int
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: Mattias Lindgren <mlindgren@gmail.com>
To: bug-followup@FreeBSD.org, daniel@zhelev.biz
Cc:  
Subject: Re: kern/149495: [zfs] chflags sappend on zfs not working right
Date: Mon, 20 Feb 2012 11:49:52 -0700

 --e0cb4efe31b482a54904b969c2c3
 Content-Type: text/plain; charset=ISO-8859-1
 
 Having similar issues in FreeBSD 9-AMD64 with ZFS v 28
 
 $ mkdir critical
 $ touch critical/critical.log
 $ sudo chmod o= critical
 
 $ sudo chflags sappnd critical
 $ sudo chflags sappnd critical/*
 
 $ echo "test" > critical/critical.log
 -bash: critical/critical.log: Operation not permitted
 $ echo "test" >> critical/critical.log
 $ grep test critical/critical.log
 test
 $ rm -rf critical/critical.log
 $ ls -l critical/
 total 0
 
 Am under the impression that I should not be able to delete files once the
 sappend flag has been set.
 
 Please let me know if you'd like me to do further testing.
 
 Thanks,
 
 Mattias
 
 --e0cb4efe31b482a54904b969c2c3
 Content-Type: text/html; charset=ISO-8859-1
 Content-Transfer-Encoding: quoted-printable
 
 Having similar issues in FreeBSD 9-AMD64 with ZFS v 28<div><br></div><div><=
 div>$ mkdir critical</div><div>$ touch critical/critical.log
 </div><div>$ sudo chmod o=3D critical</div><div><br></div><div>$ sudo chfla=
 gs sappnd critical</div><div>$ sudo chflags sappnd critical/*</div><div><br=
 ></div><div>$ echo &quot;test&quot; &gt; critical/critical.log</div><div>
 -bash: critical/critical.log: Operation not permitted</div><div>$ echo &quo=
 t;test&quot; &gt;&gt; critical/critical.log</div><div>$ grep test critical/=
 critical.log</div><div>test</div><div>$ rm -rf critical/critical.log</div>
 </div><div>$ ls -l critical/</div><div>total 0</div><div><br></div><div>Am =
 under the impression that I should not be able to delete files once the sap=
 pend flag has been set. =A0</div><div><br></div><div>Please let me know if =
 you&#39;d like me to do further testing.</div>
 <div><br></div><div>Thanks,</div><div><br></div><div>Mattias</div><div><br>=
 </div>
 
 --e0cb4efe31b482a54904b969c2c3--
>Unformatted:
