Bug 749117

Summary: extN: new file created even if open(2) returned -EPERM
Product: Red Hat Enterprise Linux 6 Reporter: Eryu Guan <eguan>
Component: kernelAssignee: Eric Sandeen <esandeen>
Status: CLOSED ERRATA QA Contact: Petr Beňas <pbenas>
Severity: low Docs Contact:
Priority: unspecified    
Version: 6.3CC: dchinner, esandeen, kzhang, lczerner, pbenas, pstehlik, rwheeler
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: kernel-2.6.32-229.el6 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 756309 (view as bug list) Environment:
Last Closed: 2012-06-20 08:00:14 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 756309, 767187    

Description Eryu Guan 2011-10-26 08:43:19 UTC
Description of problem:
In an append only dir, a open(2) call without O_RDONLY and O_APPEND will return -EPERM, but after the call new file is created.

Version-Release number of selected component (if applicable):
kernel-2.6.32-211.el6

How reproducible:
100%

Steps to Reproduce:
1. mkdir /mnt/ext4/append-only
2. chattr +a /mnt/ext4/append-only
3. ./test /mnt/ext4/append-only/testfile (touch /mnt/ext4/append-only/testfile will also work, but touch won't return error, you have to strace touch and search for open, it returns -EPERM)

# cat test.c
#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <errno.h>

int main(int argc, char *argv[])
{
        int fd;
        fd = open(argv[1], O_RDWR|O_CREAT, 0666);
        if (fd == -1)
                perror("open failed");
        exit(errno);
}
  
Actual results:
[root@fstest xfstests]# mkdir -p /mnt/ext4/append-only
[root@fstest xfstests]# chattr +a /mnt/ext4/append-only
[root@fstest xfstests]# lsattr /mnt/ext4/
--------------- /mnt/ext4/lost+found
-----a-------e- /mnt/ext4/append-only
[root@fstest xfstests]# ./test /mnt/ext4/append-only/testfile
open failed: Operation not permitted
[root@fstest xfstests]# ls -l /mnt/ext4/append-only/testfile
-rw-r--r--. 1 root root 0 Oct 26 16:07 /mnt/ext4/append-only/testfile
[root@fstest xfstests]# lsattr /mnt/ext4/append-only/testfile
-----a-------e- /mnt/ext4/append-only/testfile

Expected results:
open(2) return success or new file is not created at all

Additional info:
xfs will create new file with no problem
btrfs will fail too

Not sure if it's really a bug, but some kind of inconsistent

Comment 3 Ric Wheeler 2011-10-28 05:31:35 UTC
This would be an upstream discussion I think.

Comment 4 Eryu Guan 2011-10-30 01:33:19 UTC
Seems upstream prefers masking out append and immutable bits from EXTN_FL_INHERITED

http://permalink.gmane.org/gmane.comp.file-systems.ext4/27277

Comment 5 Eric Sandeen 2011-12-22 19:33:55 UTC
Upstream now as of commit 1cd9f097

Comment 7 RHEL Program Management 2011-12-22 19:49:46 UTC
This request was evaluated by Red Hat Product Management for inclusion
in a Red Hat Enterprise Linux maintenance release. Product Management has 
requested further review of this request by Red Hat Engineering, for potential
inclusion in a Red Hat Enterprise Linux Update release for currently deployed 
products. This request is not yet committed for inclusion in an Update release.

Comment 8 Aristeu Rozanski 2012-02-10 19:33:49 UTC
Patch(es) available on kernel-2.6.32-229.el6

Comment 12 Petr Beňas 2012-02-23 09:41:04 UTC
Reproduced in 2.6.32-221.el6.x86_64 and verified in 2.6.32-229.el6.x86_64.

Comment 14 errata-xmlrpc 2012-06-20 08:00:14 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHSA-2012-0862.html