From nobody@FreeBSD.org  Mon Mar 24 13:07:09 2008
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 CF1CD106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 24 Mar 2008 13:07:09 +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 CE83A8FC17
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 24 Mar 2008 13:07:09 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m2OD6xmt055382
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 24 Mar 2008 13:06:59 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m2OD6xBf055381;
	Mon, 24 Mar 2008 13:06:59 GMT
	(envelope-from nobody)
Message-Id: <200803241306.m2OD6xBf055381@www.freebsd.org>
Date: Mon, 24 Mar 2008 13:06:59 GMT
From: Ighighi <ighighi@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: incorrect handling of UF_IMMUTABLE / UF_APPEND flag on EXT2FS (maybe others)
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         122047
>Category:       kern
>Synopsis:       [ext2fs] [patch] incorrect handling of UF_IMMUTABLE / UF_APPEND flag on EXT2FS (maybe others)
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    jh
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Mar 24 13:10:02 UTC 2008
>Closed-Date:    Wed Apr 07 15:52:15 UTC 2010
>Last-Modified:  Wed Apr 07 15:52:15 UTC 2010
>Originator:     Ighighi
>Release:        6.3-STABLE
>Organization:
>Environment:
FreeBSD orion 6.3-STABLE FreeBSD 6.3-STABLE #0: Fri Mar 21 15:20:50 VET 2008     root@orion:/usr/obj/usr/src/sys/CUSTOM  i386
>Description:
On EXT2 filesystems (and maybe others), the kernels seems to handle
UF_IMMUTABLE and SF_IMMUTABLE separately only until they're unmounted.
When these filesystems are mounted afterwards, both flags are set. This
of course happens because EXT2FS has only one immutable bit.

So it is now a question of policy:

How should we map UF_IMMUTABLE & SF_IMMUTABLE to EXT2_IMMUTABLE_FL ?

The problem is that users may set any of the UF_* flags.  If any of these is 
later made SF_ too, those UF_* flags would be useless (and inconvenient) for
the user because suddenly they can't turn them off and work on files they own...
So being those flags usable by root alone, we must ask this question:
Are they useful to the superuser or they are not ?  If they are not, then 
dropping support for append/immutable flags for EXT2FS makes sense. If they are,
we shouldn't allow normal users to set those SF_* flags in this indirect way.

In this case, the issue of policy is better left on the administrator to choose
from, as it's done in the UNIX world ;)

I found this kernel option in NetBSD in options(5):
     options EXT2FS_SYSTEM_FLAGS
     This option changes the behavior of the APPEND and IMMUTABLE flags for a
     file on an EXT2FS file system.  Without this option, the superuser or
     owner of the file can set and clear them.	With this option, only the
     superuser can set them, and they can't be cleared if the securelevel is
     greater than 0.  See also chflags(1).

I believe it'd be best on a per-filesystem basis as a mount() option anyway and
to ignore the SF_* flags on filesystems mounted by normal users by default.

FWIW, I think this PR may apply to REISERFS and DragonFly.
>How-To-Repeat:
As root, run:

# /bin/dd if=/dev/zero of=/tmp/ext2fs.img bs=1k count=1024
1024+0 records in
1024+0 records out
1048576 bytes transferred in 0.042202 secs (24846597 bytes/sec)                      
# device=$(/sbin/mdconfig -f /tmp/ext2fs.img)
# /usr/local/sbin/mke2fs /dev/$device
# /bin/mkdir /tmp/ext2fs.mnt
# /sbin/mount_ext2fs /dev/$device /tmp/ext2fs.mnt
# /bin/mkdir -m 1777 /tmp/ext2fs.mnt/tmp                                      

Then, on a user account:

$ touch /tmp/ext2fs.mnt/tmp/foobar
$ /bin/ls -lo /tmp/ext2fs.mnt/tmp/foobar
-rw-r--r--  1 ighighi  wheel  - 0 Mar 24 06:57 /tmp/ext2fs.mnt/tmp/foobar            
$ /bin/chflags uchg /tmp/ext2fs.mnt/tmp/foobar
$ /bin/ls -lo /tmp/ext2fs.mnt/tmp/foobar
-rw-r--r--  1 ighighi  wheel  uchg 0 Mar 24 06:57 /tmp/ext2fs.mnt/tmp/foobar
$ /bin/chflags nouchg /tmp/ext2fs.mnt/tmp/foobar
$ ls -l /tmp/ext2fs.mnt/tmp/foobar
-rw-r--r--  1 ighighi  wheel  - 0 Mar 24 06:57 /tmp/ext2fs.mnt/tmp/foobar            
$ /bin/chflags uchg /tmp/ext2fs.mnt/tmp/foobar

Then, as root, run:

# /sbin/umount -v /tmp/ext2fs.mnt
/dev/md0: unmount from /var/tmp/ext2fs.mnt                                           
# /sbin/mount_ext2fs /dev/$device /tmp/ext2fs.mnt                                                 

Now, as the user, run:

$ /bin/ls -lo /tmp/ext2fs.mnt/tmp/foobar
-rw-r--r--  1 ighighi  wheel  schg,uchg 0 Mar 24 06:57 tmp/ext2fs.mnt/tmp/foobar    
$ /bin/chflags nouchg /tmp/ext2fs.mnt/tmp/foobar
chflags: /tmp/ext2fs.mnt/tmp/foobar: Operation not permitted                         


>Fix:


>Release-Note:
>Audit-Trail:

From: "Ighighi Ighighi" <ighighi@gmail.com>
To: bug-followup@freebsd.org, freebsd-fs@freebsd.org.
Cc:  
Subject: Re: kern/122047: [ext2fs] incorrect handling of UF_IMMUTABLE / UF_APPEND flag on EXT2FS (maybe others)
Date: Fri, 30 May 2008 02:16:35 +1930

 ------=_Part_19656_29267160.1212043595698
 Content-Type: text/plain; charset=ISO-8859-1
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline
 
 See attached patch.
 
 ------=_Part_19656_29267160.1212043595698
 Content-Type: text/plain; name=ext2fs.patch.txt
 Content-Transfer-Encoding: base64
 X-Attachment-Id: f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1NZU0NUTF9OT0RFKF92ZnMsIE9JRF9BVVRPLCBlMmZzLCBDVExG
 TEFHX1JXLCAwLCAiRVhUMkZTIGZpbGVzeXN0ZW0iKTsKIFNZU0NUTF9JTlQoX3Zmc19lMmZzLCBP
 SURfQVVUTywgZGlyY2hlY2ssIENUTEZMQUdfUlcsICZkaXJjaGssIDAsICIiKTsKIAogLyoKLS0t
 IHNyYy9zeXMvZ251L2ZzL2V4dDJmcy9leHQyX3Zub3BzLmMub3JpZwkyMDA2LTAyLTE5IDIwOjUz
 OjE0LjAwMDAwMDAwMCAtMDQwMAorKysgc3JjL3N5cy9nbnUvZnMvZXh0MmZzL2V4dDJfdm5vcHMu
 YwkyMDA4LTA1LTI4IDA3OjU4OjAyLjE4OTE1NzQ0MSAtMDQzMApAQCAtMzU4LDYgKzM1OCw4IEBA
 IGV4dDJfZ2V0YXR0cihhcCkKIAl2YXAtPnZhX210aW1lLnR2X25zZWMgPSBpcC0+aV9tdGltZW5z
 ZWM7CiAJdmFwLT52YV9jdGltZS50dl9zZWMgPSBpcC0+aV9jdGltZTsKIAl2YXAtPnZhX2N0aW1l
 LnR2X25zZWMgPSBpcC0+aV9jdGltZW5zZWM7CisJdmFwLT52YV9iaXJ0aHRpbWUudHZfc2VjID0g
 MDsKKwl2YXAtPnZhX2JpcnRodGltZS50dl9uc2VjID0gMDsKIAl2YXAtPnZhX2ZsYWdzID0gaXAt
 PmlfZmxhZ3M7CiAJdmFwLT52YV9nZW4gPSBpcC0+aV9nZW47CiAJdmFwLT52YV9ibG9ja3NpemUg
 PSB2cC0+dl9tb3VudC0+bW50X3N0YXQuZl9pb3NpemU7Cg==
 ------=_Part_19656_29267160.1212043595698--

From: "Ighighi Ighighi" <ighighi@gmail.com>
To: bug-followup@freebsd.org
Cc: freebsd-fs@freebsd.org
Subject: Re: kern/122047: [ext2fs] incorrect handling of UF_IMMUTABLE / UF_APPEND flag on EXT2FS (maybe others)
Date: Fri, 30 May 2008 02:00:09 +1930

 See attached patch.

From: Ighighi <ighighi@gmail.com>
To: bug-followup@freebsd.org
Cc: freebsd-fs@freebsd.org.
Subject: Re: kern/122047: [ext2fs] incorrect handling of UF_IMMUTABLE / UF_APPEND
 flag on EXT2FS (maybe others)
Date: Thu, 29 May 2008 03:06:30 -0430

 This is a multi-part message in MIME format.
 --------------010600060401000202060602
 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
 Content-Transfer-Encoding: 7bit
 
 See attached patch.  Gmail sucks at sending patches to GNATS =(
 
 --------------010600060401000202060602
 Content-Type: text/plain;
  name="ext2fs.patch.txt"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
  filename="ext2fs.patch.txt"
 
 #
 # (!c) 2008 by Ighighi
 #
 # See http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/122047
 #
 # This patch adds a "vfs.e2fs.userflags" sysctl to permit regular users
 # to set/clear the APPEND/IMMUTABLE filesystem flags on EXT2 filesystems.
 # As a bonus, it also sets st_birthtime to zero.
 #
 # Built and tested on FreeBSD 6.3-STABLE (RELENG_6).
 # Known to patch on -CURRENT
 #
 # To install, run as root:
 #   /sbin/umount -v -t ext2fs -a
 #   /sbin/kldunload -v ext2fs
 #   /usr/bin/patch -d /usr < /path/to/ext2fs.patch
 #   cd /sys/modules/ext2fs/
 #   make clean obj depend && make && make install
 #   /sbin/kldload -v ext2fs
 #   /sbin/sysctl vfs.e2fs.userflags=1  # 0 is default
 #   /sbin/mount -v -t ext2fs -a
 #
 
 --- src/sys/gnu/fs/ext2fs/ext2_inode_cnv.c.orig	2005-06-14 22:36:10.000000000 -0400
 +++ src/sys/gnu/fs/ext2fs/ext2_inode_cnv.c	2008-05-28 15:15:27.527318854 -0430
 @@ -30,11 +30,19 @@
  #include <sys/lock.h>
  #include <sys/stat.h>
  #include <sys/vnode.h>
 +#include <sys/kernel.h>
 +#include <sys/sysctl.h>
  
  #include <gnu/fs/ext2fs/inode.h>
  #include <gnu/fs/ext2fs/ext2_fs.h>
  #include <gnu/fs/ext2fs/ext2_extern.h>
  
 +SYSCTL_DECL(_vfs_e2fs);
 +
 +static int userflags = 0;
 +SYSCTL_INT(_vfs_e2fs, OID_AUTO, userflags, CTLFLAG_RW,
 +    &userflags, 0, "Users may set/clear filesystem flags");
 +
  void
  ext2_print_inode( in )
  	struct inode *in;
 @@ -83,8 +91,17 @@ ext2_ei2i(ei, ip)
  	ip->i_mtime = ei->i_mtime;
  	ip->i_ctime = ei->i_ctime;
  	ip->i_flags = 0;
 -	ip->i_flags |= (ei->i_flags & EXT2_APPEND_FL) ? APPEND : 0;
 -	ip->i_flags |= (ei->i_flags & EXT2_IMMUTABLE_FL) ? IMMUTABLE : 0;
 +	if (userflags) {
 +		if (ei->i_flags & EXT2_APPEND_FL)
 +			ip->i_flags |= UF_APPEND;
 +		if (ei->i_flags & EXT2_IMMUTABLE_FL)
 +			ip->i_flags |= UF_IMMUTABLE;
 +	} else {
 +		if (ei->i_flags & EXT2_APPEND_FL)
 +			ip->i_flags |= APPEND;
 +		if (ei->i_flags & EXT2_IMMUTABLE_FL)
 +			ip->i_flags |= IMMUTABLE;
 +	}
  	ip->i_blocks = ei->i_blocks;
  	ip->i_gen = ei->i_generation;
  	ip->i_uid = ei->i_uid;
 --- src/sys/gnu/fs/ext2fs/ext2_lookup.c.orig	2006-01-04 15:32:00.000000000 -0400
 +++ src/sys/gnu/fs/ext2fs/ext2_lookup.c	2008-05-28 13:35:16.841349269 -0430
 @@ -66,7 +66,7 @@ static int dirchk = 1;
  static int dirchk = 0;
  #endif
  
 -static SYSCTL_NODE(_vfs, OID_AUTO, e2fs, CTLFLAG_RD, 0, "EXT2FS filesystem");
 +SYSCTL_NODE(_vfs, OID_AUTO, e2fs, CTLFLAG_RW, 0, "EXT2FS filesystem");
  SYSCTL_INT(_vfs_e2fs, OID_AUTO, dircheck, CTLFLAG_RW, &dirchk, 0, "");
  
  /*
 --- src/sys/gnu/fs/ext2fs/ext2_vnops.c.orig	2006-02-19 20:53:14.000000000 -0400
 +++ src/sys/gnu/fs/ext2fs/ext2_vnops.c	2008-05-28 07:58:02.189157441 -0430
 @@ -358,6 +358,8 @@ ext2_getattr(ap)
  	vap->va_mtime.tv_nsec = ip->i_mtimensec;
  	vap->va_ctime.tv_sec = ip->i_ctime;
  	vap->va_ctime.tv_nsec = ip->i_ctimensec;
 +	vap->va_birthtime.tv_sec = 0;
 +	vap->va_birthtime.tv_nsec = 0;
  	vap->va_flags = ip->i_flags;
  	vap->va_gen = ip->i_gen;
  	vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
 
 --------------010600060401000202060602--

From: Ighighi <ighighi@gmail.com>
To: bug-followup@freebsd.org
Cc: freebsd-fs@freebsd.org
Subject: Re: kern/122047: [ext2fs] incorrect handling of UF_IMMUTABLE / UF_APPEND,
 flag on EXT2FS (maybe others)
Date: Mon, 02 Jun 2008 01:05:03 -0430

 This is a multi-part message in MIME format.
 --------------050007060101030401040504
 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
 Content-Transfer-Encoding: 7bit
 
 On Linux, only the root user may set/clear the immutable/append flags
 on ext2 filesystems... Shouldn't FreeBSD do this too, as a POLA?
 
 Anyway the attached patch extends the previous one by making it possible
 to follow the current Linux convention by setting the sysctl to 0.
 Setting it to 1, allows normal users to set them as well, and setting it
 to -1 preserves current (though erroneous) FreeBSD behavior.
 
 --------------050007060101030401040504
 Content-Type: text/plain;
  name="ext2fs.patch.txt"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
  filename="ext2fs.patch.txt"
 
 #
 # (!c) 2008 by Ighighi
 #
 # See http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/122047
 #
 # This patch adds a vfs.e2fs.userflags sysctl to allow/prevent normal users
 # to set/clear the append/immutable filesystem flags on EXT2 filesystems.
 # If set to 0, only the superuser may set/clear these flags.  This is the
 # default behavior on Linux, which FreeBSD should mimick (POLA).
 # If set to 1, users are also permitted to set/clear them on files they own.
 # If set to -1 (default), maintain the current (erroneus) behavior.
 #
 # As a bonus, this patch sets st_birthtime to zero.
 #
 # Built and tested on FreeBSD 6.3-STABLE (RELENG_6).
 # Known to patch on -CURRENT
 #
 # To install, run as root:
 #   /sbin/umount -v -t ext2fs -a
 #   /sbin/kldunload -v ext2fs
 #   /usr/bin/patch -d /usr < /path/to/ext2fs.patch
 #   cd /sys/modules/ext2fs/
 #   make clean obj depend && make && make install
 #   /sbin/kldload -v ext2fs
 #   /sbin/sysctl vfs.e2fs.userflags=1
 #   /sbin/mount -v -t ext2fs -a
 #
 
 --- src/sys/gnu/fs/ext2fs/ext2_inode_cnv.c.orig	2005-06-14 22:36:10.000000000 -0400
 +++ src/sys/gnu/fs/ext2fs/ext2_inode_cnv.c	2008-06-02 00:35:34.658524358 -0430
 @@ -30,11 +30,19 @@
  #include <sys/lock.h>
  #include <sys/stat.h>
  #include <sys/vnode.h>
 +#include <sys/kernel.h>
 +#include <sys/sysctl.h>
  
  #include <gnu/fs/ext2fs/inode.h>
  #include <gnu/fs/ext2fs/ext2_fs.h>
  #include <gnu/fs/ext2fs/ext2_extern.h>
  
 +SYSCTL_DECL(_vfs_e2fs);
 +
 +static int userflags = -1;
 +SYSCTL_INT(_vfs_e2fs, OID_AUTO, userflags, CTLFLAG_RW,
 +    &userflags, 0, "Users may set/clear filesystem flags");
 +
  void
  ext2_print_inode( in )
  	struct inode *in;
 @@ -83,8 +91,37 @@ ext2_ei2i(ei, ip)
  	ip->i_mtime = ei->i_mtime;
  	ip->i_ctime = ei->i_ctime;
  	ip->i_flags = 0;
 -	ip->i_flags |= (ei->i_flags & EXT2_APPEND_FL) ? APPEND : 0;
 -	ip->i_flags |= (ei->i_flags & EXT2_IMMUTABLE_FL) ? IMMUTABLE : 0;
 +	switch (userflags) {
 +	case 0:
 +		/*
 +		 * Only the superuser may set/clear these flags.
 +		 * This is the current behavior on Linux.
 +		 */
 +		if (ei->i_flags & EXT2_APPEND_FL)
 +			ip->i_flags |= SF_APPEND;
 +		if (ei->i_flags & EXT2_IMMUTABLE_FL)
 +			ip->i_flags |= SF_IMMUTABLE;
 +		break;
 +	case 1:
 +		/*
 +		 * Users may set/clear these flags on files they own.
 +		 */
 +		if (ei->i_flags & EXT2_APPEND_FL)
 +			ip->i_flags |= UF_APPEND;
 +		if (ei->i_flags & EXT2_IMMUTABLE_FL)
 +			ip->i_flags |= UF_IMMUTABLE;
 +		break;
 +	case -1:
 +	default:
 +		/*
 +		 * Default behavior on FreeBSD
 +		 */
 +		if (ei->i_flags & EXT2_APPEND_FL)
 +			ip->i_flags |= APPEND;
 +		if (ei->i_flags & EXT2_IMMUTABLE_FL)
 +			ip->i_flags |= IMMUTABLE;
 +		break;
 +	}
  	ip->i_blocks = ei->i_blocks;
  	ip->i_gen = ei->i_generation;
  	ip->i_uid = ei->i_uid;
 @@ -121,8 +158,37 @@ ext2_i2ei(ip, ei)
  	ei->i_ctime = ip->i_ctime;
  	ei->i_flags = ip->i_flags;
  	ei->i_flags = 0;
 -	ei->i_flags |= (ip->i_flags & APPEND) ? EXT2_APPEND_FL: 0;
 -	ei->i_flags |= (ip->i_flags & IMMUTABLE) ? EXT2_IMMUTABLE_FL: 0;
 +	switch (userflags) {
 +	case 0:
 +		/*
 +		 * Only the superuser may set/clear these flags.
 +		 * This is the current behavior on Linux.
 +		 */
 +		if (ip->i_flags & SF_APPEND)
 +			ei->i_flags |= EXT2_APPEND_FL;
 +		if (ip->i_flags & SF_IMMUTABLE)
 +			ei->i_flags |= EXT2_IMMUTABLE_FL;
 +		break;
 +	case 1:
 +		/*
 +		 * Users may set/clear these flags on files they own.
 +		 */
 +		if (ip->i_flags & UF_APPEND)
 +			ei->i_flags |= EXT2_APPEND_FL;
 +		if (ip->i_flags & UF_IMMUTABLE)
 +			ei->i_flags |= EXT2_IMMUTABLE_FL;
 +		break;
 +	case -1:
 +	default:
 +		/*
 +		 * Default behavior on FreeBSD
 +		 */
 +		if (ip->i_flags & APPEND)
 +			ei->i_flags |= EXT2_APPEND_FL;
 +		if (ip->i_flags & IMMUTABLE)
 +			ei->i_flags |= EXT2_IMMUTABLE_FL;
 +		break;
 +	}
  	ei->i_blocks = ip->i_blocks;
  	ei->i_generation = ip->i_gen;
  	ei->i_uid = ip->i_uid;
 --- src/sys/gnu/fs/ext2fs/ext2_lookup.c.orig	2006-01-04 15:32:00.000000000 -0400
 +++ src/sys/gnu/fs/ext2fs/ext2_lookup.c	2008-06-01 05:38:42.363332933 -0430
 @@ -66,7 +66,7 @@ static int dirchk = 1;
  static int dirchk = 0;
  #endif
  
 -static SYSCTL_NODE(_vfs, OID_AUTO, e2fs, CTLFLAG_RD, 0, "EXT2FS filesystem");
 +SYSCTL_NODE(_vfs, OID_AUTO, e2fs, CTLFLAG_RD, 0, "EXT2FS filesystem");
  SYSCTL_INT(_vfs_e2fs, OID_AUTO, dircheck, CTLFLAG_RW, &dirchk, 0, "");
  
  /*
 --- src/sys/gnu/fs/ext2fs/ext2_vnops.c.orig	2006-02-19 20:53:14.000000000 -0400
 +++ src/sys/gnu/fs/ext2fs/ext2_vnops.c	2008-05-28 07:58:02.189157441 -0430
 @@ -358,6 +358,8 @@ ext2_getattr(ap)
  	vap->va_mtime.tv_nsec = ip->i_mtimensec;
  	vap->va_ctime.tv_sec = ip->i_ctime;
  	vap->va_ctime.tv_nsec = ip->i_ctimensec;
 +	vap->va_birthtime.tv_sec = 0;
 +	vap->va_birthtime.tv_nsec = 0;
  	vap->va_flags = ip->i_flags;
  	vap->va_gen = ip->i_gen;
  	vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
 
 --------------050007060101030401040504--

From: Julian Elischer <julian@elischer.org>
To: Ighighi <ighighi@gmail.com>
Cc: bug-followup@freebsd.org, freebsd-fs@freebsd.org
Subject: Re: kern/122047: [ext2fs] incorrect handling of UF_IMMUTABLE / UF_APPEND,
 flag on EXT2FS (maybe others)
Date: Mon, 02 Jun 2008 00:14:46 -0700

 Ighighi wrote:
 > On Linux, only the root user may set/clear the immutable/append flags
 > on ext2 filesystems... Shouldn't FreeBSD do this too, as a POLA?
 
 No I think it should preserver the BSD scheme where being able to
 change the immutable bits is controlled by the system secure level.
 (and your UID of course). At least I think that is what I would
 expect. (All file systems to behave about the same for a
 particular OS.
 
 
 > 
 > Anyway the attached patch extends the previous one by making it possible
 > to follow the current Linux convention by setting the sysctl to 0.
 > Setting it to 1, allows normal users to set them as well, and setting it
 > to -1 preserves current (though erroneous) FreeBSD behavior.
 
 
 > 
 > 
 > ------------------------------------------------------------------------
 > 
 > _______________________________________________
 > freebsd-fs@freebsd.org mailing list
 > http://lists.freebsd.org/mailman/listinfo/freebsd-fs
 > To unsubscribe, send any mail to "freebsd-fs-unsubscribe@freebsd.org"
 

From: Bruce Evans <brde@optusnet.com.au>
To: Ighighi <ighighi@gmail.com>
Cc: bug-followup@FreeBSD.org, freebsd-fs@FreeBSD.org
Subject: Re: kern/122047: [ext2fs] incorrect handling of UF_IMMUTABLE /
 UF_APPEND, flag on EXT2FS (maybe others)
Date: Mon, 2 Jun 2008 17:50:45 +1000 (EST)

 On Mon, 2 Jun 2008, Ighighi wrote:
 
 > On Linux, only the root user may set/clear the immutable/append flags
 > on ext2 filesystems... Shouldn't FreeBSD do this too, as a POLA?
 
 I think it should do just that...
 
 > Anyway the attached patch extends the previous one by making it possible
 > to follow the current Linux convention by setting the sysctl to 0.
 > Setting it to 1, allows normal users to set them as well, and setting it
 > to -1 preserves current (though erroneous) FreeBSD behavior.
 
 ... but nothing more.  Why have complications provide more control over
 Linux file systems than Linux does?  The current behaviour seems to be
 just a bug from not understanding that Linux has no user immutable/append
 flags.
 
 % --- src/sys/gnu/fs/ext2fs/ext2_inode_cnv.c.orig	2005-06-14 22:36:10.000000000 -0400
 % +++ src/sys/gnu/fs/ext2fs/ext2_inode_cnv.c	2008-06-02 00:35:34.658524358 -0430
 % @@ -30,11 +30,19 @@
 %  #include <sys/lock.h>
 %  #include <sys/stat.h>
 %  #include <sys/vnode.h>
 % +#include <sys/kernel.h>
 % +#include <sys/sysctl.h>
 % 
 %  #include <gnu/fs/ext2fs/inode.h>
 %  #include <gnu/fs/ext2fs/ext2_fs.h>
 %  #include <gnu/fs/ext2fs/ext2_extern.h>
 % 
 % +SYSCTL_DECL(_vfs_e2fs);
 % +
 % +static int userflags = -1;
 % +SYSCTL_INT(_vfs_e2fs, OID_AUTO, userflags, CTLFLAG_RW,
 % +    &userflags, 0, "Users may set/clear filesystem flags");
 % +
 %  void
 %  ext2_print_inode( in )
 %  	struct inode *in;
 
 The existence of vfs sysctls is another bug.  They should be mount options,
 or perhaps system-wide, or not exist at all.  ext2fs has only one vfs sysctl
 now:
 - vfs.e2fs.dircheck.  This sysctl is less broken than in ffs, where the
    corresponding sysctl is spelled debug.dircheck and a comment still
    says that the corresponding static kernel variable `dirchk' is changed
    by "patching".  The kernel variable is spelled differently to the
    sysctl to confuse me when grepping for dircheck.
 - the debug.doasyncfree sysctl is in dead code (under the non-option
    FANCY_REALLOC.  Block reallocation is also dead in ext2fs).  This
    sysctl is less broken in ffs.  There it is named vfs.ffs.doasyncfree.
 OTOH, perhaps these sysctls really did belong under debug or vfs.debug.
 It is not very useful to restrict them to just ffs or ext2fs when 
 have many mounted file systems.
 
 This bug should not be extended.
 
 % @@ -83,8 +91,37 @@ ext2_ei2i(ei, ip)
 %  	ip->i_mtime = ei->i_mtime;
 %  	ip->i_ctime = ei->i_ctime;
 %  	ip->i_flags = 0;
 % -	ip->i_flags |= (ei->i_flags & EXT2_APPEND_FL) ? APPEND : 0;
 % -	ip->i_flags |= (ei->i_flags & EXT2_IMMUTABLE_FL) ? IMMUTABLE : 0;
 
 I think it would work to just map EXT2*_FL to SF_*.
 
 % +	switch (userflags) {
 % +	case 0:
 % +		/*
 % +		 * Only the superuser may set/clear these flags.
 % +		 * This is the current behavior on Linux.
 % +		 */
 % +		if (ei->i_flags & EXT2_APPEND_FL)
 % +			ip->i_flags |= SF_APPEND;
 % +		if (ei->i_flags & EXT2_IMMUTABLE_FL)
 % +			ip->i_flags |= SF_IMMUTABLE;
 % +		break;
 % +	case 1:
 % +		/*
 % +		 * Users may set/clear these flags on files they own.
 % +		 */
 % +		if (ei->i_flags & EXT2_APPEND_FL)
 % +			ip->i_flags |= UF_APPEND;
 % +		if (ei->i_flags & EXT2_IMMUTABLE_FL)
 % +			ip->i_flags |= UF_IMMUTABLE;
 % +		break;
 
 For administration it can be convenient for the file system to behave
 a little differently to native mode, but I letting root change the
 (system) immutable flags is enough.
 
 % +	case -1:
 % +	default:
 % +		/*
 % +		 * Default behavior on FreeBSD
 % +		 */
 % +		if (ei->i_flags & EXT2_APPEND_FL)
 % +			ip->i_flags |= APPEND;
 % +		if (ei->i_flags & EXT2_IMMUTABLE_FL)
 % +			ip->i_flags |= IMMUTABLE;
 % +		break;
 % +	}
 
 I think the current behaviour is too buggy to keep.  (Your original PR
 describes the bugs -- FreeBSD makes a mess by setting 2 flags in the
 in-core inode and allowing these flags to be changed independently, then
 cannot merge the flags properly when writing to the on-disk inode.)
 
 [conversion to the on-disk inode]
 
 Similarly.
 
 There is a problem in ext2_vnops.c that is not touched by these patches.
 Even in the simple version that only support SF_*, ext2_setattr() needs
 changes to disallow setting of UF_* -- otherwise FreeBSD still makes a
 mess, with stat() showing changes to UF_* succeeding while the inode is
 in-core but going away when the inode is flushed from the inode/vnode
 cache.  The fix is simply to remove the code that supports UF_*.  (We
 could also globably replace IMMUTABLE and APPEND by SF_IMMUTABLE and
 SF_APPEND.  This would be clearer but would increase divergence from
 ffs.)  The fix to support all 3 sysctl modes is not so simple:
 - case 0: dynamically disallow attempts to set UF_*.
 - case 1: dynamically disallow attempts to set SF_*.
 - case -1: dynamically convert attempts to set SF_* or UF*_ into attempts
    to set both, and somehow relax the checks for setting SF_* so that this
    has a chance of succeeding for non-root.
 I don't want these complications.
 
 Note that the corresponding code in ffs is poorly organized and buggy
 (it doesn't allow preservation of flags in the right way).  ext2_setattr()
 was once almost identical to ufs_settatr() but now has the following
 bitrot:
 - missing support for setting atimes on exec.
 - different comments about privilege though the code is the same.
 - different comments about truncate() on r/o file systems.  Missing a
    critical fix for truncate().
 - missing the comment expansion and cleanup for utimes().  I think there was
    a minor security-related fix in there too, but this is now null.
 
 % --- src/sys/gnu/fs/ext2fs/ext2_vnops.c.orig	2006-02-19 20:53:14.000000000 -0400
 % +++ src/sys/gnu/fs/ext2fs/ext2_vnops.c	2008-05-28 07:58:02.189157441 -0430
 % @@ -358,6 +358,8 @@ ext2_getattr(ap)
 %  	vap->va_mtime.tv_nsec = ip->i_mtimensec;
 %  	vap->va_ctime.tv_sec = ip->i_ctime;
 %  	vap->va_ctime.tv_nsec = ip->i_ctimensec;
 % +	vap->va_birthtime.tv_sec = 0;
 % +	vap->va_birthtime.tv_nsec = 0;
 %  	vap->va_flags = ip->i_flags;
 %  	vap->va_gen = ip->i_gen;
 %  	vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
 
 This is unrelated and should be handled centrally.  Almost all file
 systems get this wrong.  Most fail to set va_birthtime, so stat()
 returns kernel stack garbage for st_birthtime.  ffs1 does the same
 as the above.  msdosfs does the above correctly, by setting tv_sec to
 (time_t)-1 in unsupported cases.
 
 Bruce

From: Bruce Evans <brde@optusnet.com.au>
To: Julian Elischer <julian@elischer.org>
Cc: Ighighi <ighighi@gmail.com>, freebsd-fs@freebsd.org,
        bug-followup@freebsd.org
Subject: Re: kern/122047: [ext2fs] incorrect handling of UF_IMMUTABLE /
 UF_APPEND, flag on EXT2FS (maybe others)
Date: Mon, 2 Jun 2008 20:30:02 +1000 (EST)

 On Mon, 2 Jun 2008, Julian Elischer wrote:
 
 > Ighighi wrote:
 >> On Linux, only the root user may set/clear the immutable/append flags
 >> on ext2 filesystems... Shouldn't FreeBSD do this too, as a POLA?
 >
 > No I think it should preserver the BSD scheme where being able to
 > change the immutable bits is controlled by the system secure level.
 > (and your UID of course). At least I think that is what I would
 > expect. (All file systems to behave about the same for a
 > particular OS.
 
 No, the securelevel already controls things, and the BSD scheme reduces
 to only allowing root (strictly, processes with appropriate privilege,
 as restricted by securelevel and jails etc, but never mere users), to
 change immutable bits, because ext2fs doesn't have any user immutable
 bits to change (except phantom bits due to bugs in the current FreeBSD
 implementation).
 
 Bruce

From: Kirk McKusick <mckusick@chez.mckusick.com>
To: Bruce Evans <brde@optusnet.com.au>
Cc: Ighighi <ighighi@gmail.com>, freebsd-fs@freebsd.org,
        Julian Elischer <julian@elischer.org>, bug-followup@freebsd.org
Subject: Re: kern/122047: [ext2fs] incorrect handling of UF_IMMUTABLE / UF_APPEND, flag on EXT2FS (maybe others) 
Date: Sun, 08 Jun 2008 12:04:26 -0700

 Bruce,
 
 I concur with your analysis of what should be done here. Disallow
 manipulation of UF_ flags in ext2 and restrict SF_ flags to appropriate
 priviledge as is done in both FreeBSD and Linux. The only debate is
 whether to enforce FreeBSD securelevel for ext2 which I would be
 inclined to do.
 
 	Kirk McKusick
Responsible-Changed-From-To: freebsd-bugs->freebsd-fs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Mon May 18 04:31:25 UTC 2009 
Responsible-Changed-Why:  
Over to maintainer(s). 

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

From: Aditya Sarawgi <sarawgi.aditya@gmail.com>
To: bug-followup@freebsd.org
Cc: ighighi@freebsd.org, brde@optusnet.com.au, mckusick@chez.mckusick.com
Subject: Re: kern/122047: [ext2fs] [patch] incorrect handling of
	UF_IMMUTABLE / UF_APPEND flag on EXT2FS (maybe others)
Date: Fri, 29 May 2009 15:57:13 +0530

 --2oS5YaxWCcQjTEyO
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 I have created a patch for this. Its a simple patch that maps EXT2_* flags to only SF_* flags and disallows setting of UF_* flags with an EOPNOTSUPP 
 error. 
 
 --
 Aditya Sarawgi
 
 --2oS5YaxWCcQjTEyO
 Content-Type: text/x-diff; charset=us-ascii
 Content-Disposition: attachment; filename="uf.patch"
 
 86,87c86,87
 < 	ip->i_flags |= (ei->i_flags & EXT2_APPEND_FL) ? APPEND : 0;
 < 	ip->i_flags |= (ei->i_flags & EXT2_IMMUTABLE_FL) ? IMMUTABLE : 0;
 ---
 > 	ip->i_flags |= (ei->i_flags & EXT2_APPEND_FL) ? SF_APPEND : 0;
 > 	ip->i_flags |= (ei->i_flags & EXT2_IMMUTABLE_FL) ? SF_IMMUTABLE : 0;
 124,125c124,125
 < 	ei->i_flags |= (ip->i_flags & APPEND) ? EXT2_APPEND_FL: 0;
 < 	ei->i_flags |= (ip->i_flags & IMMUTABLE) ? EXT2_IMMUTABLE_FL: 0;
 ---
 > 	ei->i_flags |= (ip->i_flags & SF_APPEND) ? EXT2_APPEND_FL: 0;
 > 	ei->i_flags |= (ip->i_flags & SF_IMMUTABLE) ? EXT2_IMMUTABLE_FL: 0;
 250c250
 < 	if ((VTOI(ap->a_vp)->i_flags & APPEND) &&
 ---
 > 	if ((VTOI(ap->a_vp)->i_flags & SF_APPEND) &&
 318c318
 < 	if ((accmode & VWRITE) && (ip->i_flags & (IMMUTABLE | SF_SNAPSHOT)))
 ---
 > 	if ((accmode & VWRITE) && (ip->i_flags & (SF_IMMUTABLE | SF_SNAPSHOT)))
 394a395,399
 > 		/* 
 > 		 * Deny setting of UF_* flags
 > 		 */ 
 > 		if(vap->va_flags & UF_SETTABLE)
 > 			return (EOPNOTSUPP);
 425c430
 < 		if (vap->va_flags & (IMMUTABLE | APPEND))
 ---
 > 		if (vap->va_flags & (SF_IMMUTABLE | SF_APPEND))
 428c433
 < 	if (ip->i_flags & (IMMUTABLE | APPEND))
 ---
 > 	if (ip->i_flags & (SF_IMMUTABLE | SF_APPEND))
 678,679c683,684
 < 	if ((ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
 < 	    (VTOI(dvp)->i_flags & APPEND)) {
 ---
 > 	if ((ip->i_flags & (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND)) ||
 > 	    (VTOI(dvp)->i_flags & SF_APPEND)) {
 722c727
 < 	if (ip->i_flags & (IMMUTABLE | APPEND)) {
 ---
 > 	if (ip->i_flags & (SF_IMMUTABLE | SF_APPEND)) {
 789,790c794,795
 < 	if (tvp && ((VTOI(tvp)->i_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
 < 	    (VTOI(tdvp)->i_flags & APPEND))) {
 ---
 > 	if (tvp && ((VTOI(tvp)->i_flags & (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND)) ||
 > 	    (VTOI(tdvp)->i_flags & SF_APPEND))) {
 814,815c819,820
 < 	if ((ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND))
 < 	    || (dp->i_flags & APPEND)) {
 ---
 > 	if ((ip->i_flags & (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND))
 > 	    || (dp->i_flags & SF_APPEND)) {
 1274,1275c1279,1280
 < 	if ((dp->i_flags & APPEND)
 < 	    || (ip->i_flags & (NOUNLINK | IMMUTABLE | APPEND))) {
 ---
 > 	if ((dp->i_flags & SF_APPEND)
 > 	    || (ip->i_flags & (SF_NOUNLINK | SF_IMMUTABLE | SF_APPEND))) {
 
 --2oS5YaxWCcQjTEyO--
Responsible-Changed-From-To: freebsd-fs->jh 
Responsible-Changed-By: jh 
Responsible-Changed-When: Mon Nov 2 15:17:43 UTC 2009 
Responsible-Changed-Why:  
Take. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/122047: commit references a PR
Date: Thu,  5 Nov 2009 04:51:50 +0000 (UTC)

 Author: jh
 Date: Thu Nov  5 04:51:38 2009
 New Revision: 198940
 URL: http://svn.freebsd.org/changeset/base/198940
 
 Log:
   File flags handling fixes for ext2fs:
   
   - Disallow setting of flags not supported by ext2fs.
   - Map EXT2_APPEND_FL to SF_APPEND.
   - Map EXT2_IMMUTABLE_FL to SF_IMMUTABLE.
   - Map EXT2_NODUMP_FL to UF_NODUMP.
   
   Note that ext2fs doesn't support user settable append and immutable flags.
   EXT2_NODUMP_FL is an user settable flag also on Linux.
   
   PR:		kern/122047
   Reported by:	Ighighi
   Submitted by:	Aditya Sarawgi (original version)
   Reviewed by:	bde
   Approved by:	trasz (mentor)
 
 Modified:
   head/sys/gnu/fs/ext2fs/ext2_inode_cnv.c
   head/sys/gnu/fs/ext2fs/ext2_vnops.c
 
 Modified: head/sys/gnu/fs/ext2fs/ext2_inode_cnv.c
 ==============================================================================
 --- head/sys/gnu/fs/ext2fs/ext2_inode_cnv.c	Thu Nov  5 03:54:03 2009	(r198939)
 +++ head/sys/gnu/fs/ext2fs/ext2_inode_cnv.c	Thu Nov  5 04:51:38 2009	(r198940)
 @@ -83,8 +83,9 @@ ext2_ei2i(ei, ip)
  	ip->i_mtime = ei->i_mtime;
  	ip->i_ctime = ei->i_ctime;
  	ip->i_flags = 0;
 -	ip->i_flags |= (ei->i_flags & EXT2_APPEND_FL) ? APPEND : 0;
 -	ip->i_flags |= (ei->i_flags & EXT2_IMMUTABLE_FL) ? IMMUTABLE : 0;
 +	ip->i_flags |= (ei->i_flags & EXT2_APPEND_FL) ? SF_APPEND : 0;
 +	ip->i_flags |= (ei->i_flags & EXT2_IMMUTABLE_FL) ? SF_IMMUTABLE : 0;
 +	ip->i_flags |= (ei->i_flags & EXT2_NODUMP_FL) ? UF_NODUMP : 0;
  	ip->i_blocks = ei->i_blocks;
  	ip->i_gen = ei->i_generation;
  	ip->i_uid = ei->i_uid;
 @@ -121,8 +122,9 @@ ext2_i2ei(ip, ei)
  	ei->i_ctime = ip->i_ctime;
  	ei->i_flags = ip->i_flags;
  	ei->i_flags = 0;
 -	ei->i_flags |= (ip->i_flags & APPEND) ? EXT2_APPEND_FL: 0;
 -	ei->i_flags |= (ip->i_flags & IMMUTABLE) ? EXT2_IMMUTABLE_FL: 0;
 +	ei->i_flags |= (ip->i_flags & SF_APPEND) ? EXT2_APPEND_FL: 0;
 +	ei->i_flags |= (ip->i_flags & SF_IMMUTABLE) ? EXT2_IMMUTABLE_FL: 0;
 +	ei->i_flags |= (ip->i_flags & UF_NODUMP) ? EXT2_NODUMP_FL : 0;
  	ei->i_blocks = ip->i_blocks;
  	ei->i_generation = ip->i_gen;
  	ei->i_uid = ip->i_uid;
 
 Modified: head/sys/gnu/fs/ext2fs/ext2_vnops.c
 ==============================================================================
 --- head/sys/gnu/fs/ext2fs/ext2_vnops.c	Thu Nov  5 03:54:03 2009	(r198939)
 +++ head/sys/gnu/fs/ext2fs/ext2_vnops.c	Thu Nov  5 04:51:38 2009	(r198940)
 @@ -391,6 +391,10 @@ ext2_setattr(ap)
  		return (EINVAL);
  	}
  	if (vap->va_flags != VNOVAL) {
 +		/* Disallow flags not supported by ext2fs. */
 +		if (vap->va_flags & ~(SF_APPEND | SF_IMMUTABLE | UF_NODUMP))
 +			return (EOPNOTSUPP);
 +
  		if (vp->v_mount->mnt_flag & MNT_RDONLY)
  			return (EROFS);
  		/*
 _______________________________________________
 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->patched 
State-Changed-By: jh 
State-Changed-When: Thu Nov 5 05:10:05 UTC 2009 
State-Changed-Why:  
Patched in head (r198940). 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/122047: commit references a PR
Date: Mon,  4 Jan 2010 14:35:46 +0000 (UTC)

 Author: jh
 Date: Mon Jan  4 14:35:36 2010
 New Revision: 201497
 URL: http://svn.freebsd.org/changeset/base/201497
 
 Log:
   MFC r198940:
   
   File flags handling fixes for ext2fs:
   
   - Disallow setting of flags not supported by ext2fs.
   - Map EXT2_APPEND_FL to SF_APPEND.
   - Map EXT2_IMMUTABLE_FL to SF_IMMUTABLE.
   - Map EXT2_NODUMP_FL to UF_NODUMP.
   
   Note that ext2fs doesn't support user settable append and immutable flags.
   EXT2_NODUMP_FL is an user settable flag also on Linux.
   
   PR:		kern/122047
   Approved by:	trasz (mentor)
 
 Modified:
   stable/8/sys/gnu/fs/ext2fs/ext2_inode_cnv.c
   stable/8/sys/gnu/fs/ext2fs/ext2_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)
   stable/8/sys/dev/xen/xenpci/   (props changed)
 
 Modified: stable/8/sys/gnu/fs/ext2fs/ext2_inode_cnv.c
 ==============================================================================
 --- stable/8/sys/gnu/fs/ext2fs/ext2_inode_cnv.c	Mon Jan  4 14:34:01 2010	(r201496)
 +++ stable/8/sys/gnu/fs/ext2fs/ext2_inode_cnv.c	Mon Jan  4 14:35:36 2010	(r201497)
 @@ -83,8 +83,9 @@ ext2_ei2i(ei, ip)
  	ip->i_mtime = ei->i_mtime;
  	ip->i_ctime = ei->i_ctime;
  	ip->i_flags = 0;
 -	ip->i_flags |= (ei->i_flags & EXT2_APPEND_FL) ? APPEND : 0;
 -	ip->i_flags |= (ei->i_flags & EXT2_IMMUTABLE_FL) ? IMMUTABLE : 0;
 +	ip->i_flags |= (ei->i_flags & EXT2_APPEND_FL) ? SF_APPEND : 0;
 +	ip->i_flags |= (ei->i_flags & EXT2_IMMUTABLE_FL) ? SF_IMMUTABLE : 0;
 +	ip->i_flags |= (ei->i_flags & EXT2_NODUMP_FL) ? UF_NODUMP : 0;
  	ip->i_blocks = ei->i_blocks;
  	ip->i_gen = ei->i_generation;
  	ip->i_uid = ei->i_uid;
 @@ -121,8 +122,9 @@ ext2_i2ei(ip, ei)
  	ei->i_ctime = ip->i_ctime;
  	ei->i_flags = ip->i_flags;
  	ei->i_flags = 0;
 -	ei->i_flags |= (ip->i_flags & APPEND) ? EXT2_APPEND_FL: 0;
 -	ei->i_flags |= (ip->i_flags & IMMUTABLE) ? EXT2_IMMUTABLE_FL: 0;
 +	ei->i_flags |= (ip->i_flags & SF_APPEND) ? EXT2_APPEND_FL: 0;
 +	ei->i_flags |= (ip->i_flags & SF_IMMUTABLE) ? EXT2_IMMUTABLE_FL: 0;
 +	ei->i_flags |= (ip->i_flags & UF_NODUMP) ? EXT2_NODUMP_FL : 0;
  	ei->i_blocks = ip->i_blocks;
  	ei->i_generation = ip->i_gen;
  	ei->i_uid = ip->i_uid;
 
 Modified: stable/8/sys/gnu/fs/ext2fs/ext2_vnops.c
 ==============================================================================
 --- stable/8/sys/gnu/fs/ext2fs/ext2_vnops.c	Mon Jan  4 14:34:01 2010	(r201496)
 +++ stable/8/sys/gnu/fs/ext2fs/ext2_vnops.c	Mon Jan  4 14:35:36 2010	(r201497)
 @@ -391,6 +391,10 @@ ext2_setattr(ap)
  		return (EINVAL);
  	}
  	if (vap->va_flags != VNOVAL) {
 +		/* Disallow flags not supported by ext2fs. */
 +		if (vap->va_flags & ~(SF_APPEND | SF_IMMUTABLE | UF_NODUMP))
 +			return (EOPNOTSUPP);
 +
  		if (vp->v_mount->mnt_flag & MNT_RDONLY)
  			return (EROFS);
  		/*
 _______________________________________________
 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/122047: commit references a PR
Date: Wed,  7 Apr 2010 15:33:38 +0000 (UTC)

 Author: jh
 Date: Wed Apr  7 15:33:19 2010
 New Revision: 206359
 URL: http://svn.freebsd.org/changeset/base/206359
 
 Log:
   MFC r198940:
   
   File flags handling fixes for ext2fs:
   
   - Disallow setting of flags not supported by ext2fs.
   - Map EXT2_APPEND_FL to SF_APPEND.
   - Map EXT2_IMMUTABLE_FL to SF_IMMUTABLE.
   - Map EXT2_NODUMP_FL to UF_NODUMP.
   
   Note that ext2fs doesn't support user settable append and immutable flags.
   EXT2_NODUMP_FL is an user settable flag also on Linux.
   
   PR:		kern/122047
 
 Modified:
   stable/7/sys/gnu/fs/ext2fs/ext2_inode_cnv.c
   stable/7/sys/gnu/fs/ext2fs/ext2_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/gnu/fs/ext2fs/ext2_inode_cnv.c
 ==============================================================================
 --- stable/7/sys/gnu/fs/ext2fs/ext2_inode_cnv.c	Wed Apr  7 15:29:13 2010	(r206358)
 +++ stable/7/sys/gnu/fs/ext2fs/ext2_inode_cnv.c	Wed Apr  7 15:33:19 2010	(r206359)
 @@ -83,8 +83,9 @@ ext2_ei2i(ei, ip)
  	ip->i_mtime = ei->i_mtime;
  	ip->i_ctime = ei->i_ctime;
  	ip->i_flags = 0;
 -	ip->i_flags |= (ei->i_flags & EXT2_APPEND_FL) ? APPEND : 0;
 -	ip->i_flags |= (ei->i_flags & EXT2_IMMUTABLE_FL) ? IMMUTABLE : 0;
 +	ip->i_flags |= (ei->i_flags & EXT2_APPEND_FL) ? SF_APPEND : 0;
 +	ip->i_flags |= (ei->i_flags & EXT2_IMMUTABLE_FL) ? SF_IMMUTABLE : 0;
 +	ip->i_flags |= (ei->i_flags & EXT2_NODUMP_FL) ? UF_NODUMP : 0;
  	ip->i_blocks = ei->i_blocks;
  	ip->i_gen = ei->i_generation;
  	ip->i_uid = ei->i_uid;
 @@ -121,8 +122,9 @@ ext2_i2ei(ip, ei)
  	ei->i_ctime = ip->i_ctime;
  	ei->i_flags = ip->i_flags;
  	ei->i_flags = 0;
 -	ei->i_flags |= (ip->i_flags & APPEND) ? EXT2_APPEND_FL: 0;
 -	ei->i_flags |= (ip->i_flags & IMMUTABLE) ? EXT2_IMMUTABLE_FL: 0;
 +	ei->i_flags |= (ip->i_flags & SF_APPEND) ? EXT2_APPEND_FL: 0;
 +	ei->i_flags |= (ip->i_flags & SF_IMMUTABLE) ? EXT2_IMMUTABLE_FL: 0;
 +	ei->i_flags |= (ip->i_flags & UF_NODUMP) ? EXT2_NODUMP_FL : 0;
  	ei->i_blocks = ip->i_blocks;
  	ei->i_generation = ip->i_gen;
  	ei->i_uid = ip->i_uid;
 
 Modified: stable/7/sys/gnu/fs/ext2fs/ext2_vnops.c
 ==============================================================================
 --- stable/7/sys/gnu/fs/ext2fs/ext2_vnops.c	Wed Apr  7 15:29:13 2010	(r206358)
 +++ stable/7/sys/gnu/fs/ext2fs/ext2_vnops.c	Wed Apr  7 15:33:19 2010	(r206359)
 @@ -399,6 +399,10 @@ ext2_setattr(ap)
  		return (EINVAL);
  	}
  	if (vap->va_flags != VNOVAL) {
 +		/* Disallow flags not supported by ext2fs. */
 +		if (vap->va_flags & ~(SF_APPEND | SF_IMMUTABLE | UF_NODUMP))
 +			return (EOPNOTSUPP);
 +
  		if (vp->v_mount->mnt_flag & MNT_RDONLY)
  			return (EROFS);
  		/*
 _______________________________________________
 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: patched->closed 
State-Changed-By: jh 
State-Changed-When: Wed Apr 7 15:52:14 UTC 2010 
State-Changed-Why:  
Fixed in head, stable/8 and stable/7. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=122047 
>Unformatted:
