lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 16 Nov 2021 11:58:10 +0800
From:   Jubin Zhong <zhongjubin@...wei.com>
To:     <hch@...radead.org>
CC:     <kechengsong@...wei.com>, <linux-fsdevel@...r.kernel.org>,
        <linux-kernel@...r.kernel.org>, <viro@...iv.linux.org.uk>,
        <wangfangpeng1@...wei.com>, <zhongjubin@...wei.com>
Subject: Re: [PATCH] fs: Fix truncate never updates m/ctime

> On Mon, Nov 15, 2021 at 07:00:18PM +0800, Jubin Zhong wrote:
>> From: zhongjubin <zhongjubin@...wei.com>
>> 
>> Syscall truncate() never updates m/ctime even if the file size is
>> changed. However, this is incorrect according to man file:
>> 
>>   truncate (2):
>>   If  the  size  changed, then the st_ctime and st_mtime fields
>>   (respectively, time of last status change and time of last modification;
>>   see stat(2)) for the file are updated, and the set-user-ID and
>>   set-group-ID mode bits may be cleared.
>> 
>> Check file size before do_truncate() to fix this.
>
> Please try to actually reproduce your alleged "bug".  And maybe also
> look at the actual setattr implementations.  Hint: The XFS one even
> has extensive comments.

Thanks for your advice. I found this problem on yaffs2 in the beginning,
ftruncate() always works fine but truncate() does not. Now I have done 
a few more tests and the following are the results:

Test Environmont:
	kernel: Linux Kernel v5.16
	hardware: QEMU emulator version 3.1.0
	arch: vexpress-v2p-ca9

Teset Results:
	filesystems     m/ctime updated by truncate?
	jffs2           fail
	yaffs2          fail
	ubifs           success
	ext2            success
	ext4            success
	tmpfs           success
	xfs             success

Test Steps:
	1. cd /path/to/mnt/point
	2. dd if=/dev/zero of=test bs=1M count=1
	3. stat test
	4. /bin/my_truncate -s 1024 test
	5. stat test
	6. compare m/ctime of step 5 with step 3

Program source:
	#include <stdio.h>
	#include <stdlib.h>
	#include <string.h>
	#include <unistd.h>
	#include <sys/types.h>
	int main(int argc, char **argv)
	{
		int ret;
		char file_name[128] = {0};
		
		if (argc < 4 || argv == NULL || argv[1] == NULL || argv[2] == NULL || argv[3] == NULL) {
			return -1;
		}
		
		if (strcmp(argv[1], "-s")) {
			return -1;
		}
		
		if (realpath(argv[3], file_name) == NULL) {
			printf("truncate: input file name %s err.\n", argv[3]);
			return -1;
		}
		
		off_t size = (off_t)strtol(argv[2], 0, 0);
		ret = truncate(file_name, size);
		if (ret) {
			printf("truncate return err %d\n", ret);
		}   
		return ret;
	}   

I work on embedded devices so concern about jffs2/yaffs2/ubifs the most. 
If there are any errors in my test program please let me know.

Thanks.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ