• Miklos Szeredi's avatar
    ovl: get_write_access() in truncate · a7ed367c
    Miklos Szeredi authored
    commit 03bea604 upstream.
    
    When truncating a file we should check write access on the underlying
    inode.  And we should do so on the lower file as well (before copy-up) for
    consistency.
    
    Original patch and test case by Aihua Zhang.
    
     - - >o >o - - test.c - - >o >o - -
    #include <stdio.h>
    #include <errno.h>
    #include <unistd.h>
    
    int main(int argc, char *argv[])
    {
    	int ret;
    
    	ret = truncate(argv[0], 4096);
    	if (ret != -1) {
    		fprintf(stderr, "truncate(argv[0]) should have failed\n");
    		return 1;
    	}
    	if (errno != ETXTBSY) {
    		perror("truncate(argv[0])");
    		return 1;
    	}
    
    	return 0;
    }
     - - >o >o - - >o >o - - >o >o - -
    Reported-by: default avatarAihua Zhang <zhangaihua1@huawei.com>
    Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    a7ed367c
inode.c 9.74 KB