From mboxrd@z Thu Jan 1 00:00:00 1970 From: Zhang AiHua Subject: =?UTF-8?Q?retry=ef=bc=9a[PATCH]_fix_error:_a_bin_file_can_truncate_?= =?UTF-8?Q?itself_while_running_on_overlayfs?= Date: Mon, 27 Jun 2016 09:06:54 +0800 Message-ID: <57707C2E.2080500@huawei.com> References: <1466590388-4914-1-git-send-email-zhangaihua1@huawei.com> Mime-Version: 1.0 Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: Received: from szxga03-in.huawei.com ([119.145.14.66]:55771 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751554AbcF0BJZ (ORCPT ); Sun, 26 Jun 2016 21:09:25 -0400 In-Reply-To: <1466590388-4914-1-git-send-email-zhangaihua1@huawei.com> Sender: linux-unionfs-owner@vger.kernel.org List-Id: linux-unionfs@vger.kernel.org To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-unionfs@vger.kernel.org -------- =D7=AA=B7=A2=B5=C4=CF=FB=CF=A2 -------- =D6=F7=CC=E2: [PATCH] fix error: a bin file can truncate itself while r= unning on overlayfs =C8=D5=C6=DA: Wed, 22 Jun 2016 18:13:08 +0800 =B7=A2=BC=FE=C8=CB: zhangaihua1@huawei.com =CA=D5=BC=FE=C8=CB: linux-fsdevel@vger.kernel.org, linux-kernel@vger.ke= rnel.org, linux-unionfs@vger.kernel.org =B3=AD=CB=CD: Aihua Zhang =46rom: Aihua Zhang I wrote a testcase to truncate a bin file while it is running on overla= yfs. the mount: /dev/mapper/fedora-home on /home type ext4 (rw,relatime,data=3Dordered) overlay on /tmp type overlay (rw,relatime,lowerdir=3D/home/zah/lower, upperdir=3D/home/zah/upper,workdir=3D/home/zah/workdir) the code cpp: int main(int argc, char *argv[]) { int status; pthread_t thread; int err; char *ptr; ptr =3D basename(argv[0]); printf("%s\n",ptr); errno =3D 0; status =3D truncate(ptr, 4096); printf("status:%d\n",status); printf("errno:%d\n",errno); printf("ETXTBSY:%d\n",ETXTBSY); if ((-1 =3D=3D status) && (ETXTBSY =3D=3D errno)) { printf("PASS\n"); return 0; } err =3D errno; printf("err =3D %d\n", err); printf("FAIL\n"); return 1; } I running the test on overlayfs, the result as below: Bus error (core dumped) and running the test on ext4, the result as below: status:-1 errno:26 ETXTBSY:26 PASS I add some log, and I find the inode is not correct on overlayfs, and the inode->i_writecount is not correct also called by vfs_truncate-= > get_write_access(), the log as below: Jun 22 09:50:38 kernel: [131.872920] deny_write_access: inode ino 64104= 618 Jun 22 09:50:38 kernel: [131.873109] deny_write_access: inode ino 64104= 618 Jun 22 09:50:38 kernel: [131.873110] __vma_link_file: inode ino 6410461= 8 Jun 22 09:50:38 kernel: [131.873112] allow_write_access: inode ino 6410= 4618 Jun 22 09:50:38 kernel: [131.873114] deny_write_access: inode ino 64104= 618 Jun 22 09:50:38 kernel: [131.873115] __vma_link_file: inode ino 6410461= 8 Jun 22 09:50:38 kernel: [131.873116] allow_write_access: inode ino 6410= 4618 Jun 22 09:50:38 kernel: [131.873162] allow_write_access: inode ino 6410= 4618 Jun 22 09:50:38 kernel: [131.873947] __vma_link_file: inode ino 6410461= 8 Jun 22 09:50:38 kernel: [131.874039] vfs_truncate: inode ino:24061 before vfs_truncate, the inode is point to upper filesystem(ext4), and in vfs_truncate the inode is point to overlayfs. So, I fix it by geting the real inode via ovl_d_select_inode. Signed-off-by: Aihua Zhang --- fs/open.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/open.c b/fs/open.c index 93ae3cd..43b17d1 100644 --- a/fs/open.c +++ b/fs/open.c @@ -67,10 +67,16 @@ int do_truncate(struct dentry *dentry, loff_t lengt= h, unsigned int time_attrs, long vfs_truncate(const struct path *path, loff_t length) { + struct dentry *dentry =3D path->dentry; struct inode *inode; long error; - inode =3D path->dentry->d_inode; + if (dentry->d_flags & DCACHE_OP_SELECT_INODE) { + inode =3D dentry->d_op->d_select_inode(dentry, O_TRUNC); + if (IS_ERR(inode)) + return PTR_ERR(inode); + } else + inode =3D dentry->d_inode; /* For directories it's -EISDIR, for other non-regulars - -EINVAL */ if (S_ISDIR(inode->i_mode)) @@ -106,7 +112,7 @@ long vfs_truncate(const struct path *path, loff_t l= ength) if (!error) error =3D security_path_truncate(path); if (!error) - error =3D do_truncate(path->dentry, length, 0, NULL); + error =3D do_truncate(dentry, length, 0, NULL); put_write_and_out: put_write_access(inode); --=20 1.7.1 =2E From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Subject: =?UTF-8?Q?retry=ef=bc=9a[PATCH]_fix_error:_a_bin_file_can_truncate_?= =?UTF-8?Q?itself_while_running_on_overlayfs?= References: <1466590388-4914-1-git-send-email-zhangaihua1@huawei.com> To: , , From: Zhang AiHua Message-ID: <57707C2E.2080500@huawei.com> Date: Mon, 27 Jun 2016 09:06:54 +0800 MIME-Version: 1.0 In-Reply-To: <1466590388-4914-1-git-send-email-zhangaihua1@huawei.com> Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: -------- ת������Ϣ -------- ����: [PATCH] fix error: a bin file can truncate itself while running on overlayfs ����: Wed, 22 Jun 2016 18:13:08 +0800 ������: zhangaihua1@huawei.com �ռ���: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-unionfs@vger.kernel.org ����: Aihua Zhang From: Aihua Zhang I wrote a testcase to truncate a bin file while it is running on overlayfs. the mount: /dev/mapper/fedora-home on /home type ext4 (rw,relatime,data=ordered) overlay on /tmp type overlay (rw,relatime,lowerdir=/home/zah/lower, upperdir=/home/zah/upper,workdir=/home/zah/workdir) the code cpp: int main(int argc, char *argv[]) { int status; pthread_t thread; int err; char *ptr; ptr = basename(argv[0]); printf("%s\n",ptr); errno = 0; status = truncate(ptr, 4096); printf("status:%d\n",status); printf("errno:%d\n",errno); printf("ETXTBSY:%d\n",ETXTBSY); if ((-1 == status) && (ETXTBSY == errno)) { printf("PASS\n"); return 0; } err = errno; printf("err = %d\n", err); printf("FAIL\n"); return 1; } I running the test on overlayfs, the result as below: Bus error (core dumped) and running the test on ext4, the result as below: status:-1 errno:26 ETXTBSY:26 PASS I add some log, and I find the inode is not correct on overlayfs, and the inode->i_writecount is not correct also called by vfs_truncate-> get_write_access(), the log as below: Jun 22 09:50:38 kernel: [131.872920] deny_write_access: inode ino 64104618 Jun 22 09:50:38 kernel: [131.873109] deny_write_access: inode ino 64104618 Jun 22 09:50:38 kernel: [131.873110] __vma_link_file: inode ino 64104618 Jun 22 09:50:38 kernel: [131.873112] allow_write_access: inode ino 64104618 Jun 22 09:50:38 kernel: [131.873114] deny_write_access: inode ino 64104618 Jun 22 09:50:38 kernel: [131.873115] __vma_link_file: inode ino 64104618 Jun 22 09:50:38 kernel: [131.873116] allow_write_access: inode ino 64104618 Jun 22 09:50:38 kernel: [131.873162] allow_write_access: inode ino 64104618 Jun 22 09:50:38 kernel: [131.873947] __vma_link_file: inode ino 64104618 Jun 22 09:50:38 kernel: [131.874039] vfs_truncate: inode ino:24061 before vfs_truncate, the inode is point to upper filesystem(ext4), and in vfs_truncate the inode is point to overlayfs. So, I fix it by geting the real inode via ovl_d_select_inode. Signed-off-by: Aihua Zhang --- fs/open.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/open.c b/fs/open.c index 93ae3cd..43b17d1 100644 --- a/fs/open.c +++ b/fs/open.c @@ -67,10 +67,16 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs, long vfs_truncate(const struct path *path, loff_t length) { + struct dentry *dentry = path->dentry; struct inode *inode; long error; - inode = path->dentry->d_inode; + if (dentry->d_flags & DCACHE_OP_SELECT_INODE) { + inode = dentry->d_op->d_select_inode(dentry, O_TRUNC); + if (IS_ERR(inode)) + return PTR_ERR(inode); + } else + inode = dentry->d_inode; /* For directories it's -EISDIR, for other non-regulars - -EINVAL */ if (S_ISDIR(inode->i_mode)) @@ -106,7 +112,7 @@ long vfs_truncate(const struct path *path, loff_t length) if (!error) error = security_path_truncate(path); if (!error) - error = do_truncate(path->dentry, length, 0, NULL); + error = do_truncate(dentry, length, 0, NULL); put_write_and_out: put_write_access(inode); -- 1.7.1 . From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751811AbcF0BJ1 (ORCPT ); Sun, 26 Jun 2016 21:09:27 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:55771 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751554AbcF0BJZ (ORCPT ); Sun, 26 Jun 2016 21:09:25 -0400 Subject: =?UTF-8?Q?retry=ef=bc=9a[PATCH]_fix_error:_a_bin_file_can_truncate_?= =?UTF-8?Q?itself_while_running_on_overlayfs?= References: <1466590388-4914-1-git-send-email-zhangaihua1@huawei.com> To: , , From: Zhang AiHua X-Forwarded-Message-Id: <1466590388-4914-1-git-send-email-zhangaihua1@huawei.com> Message-ID: <57707C2E.2080500@huawei.com> Date: Mon, 27 Jun 2016 09:06:54 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <1466590388-4914-1-git-send-email-zhangaihua1@huawei.com> Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.177.235.62] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020206.57707CC1.0148,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 275fc171d27e3f04307b97a9afbc26c0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org -------- ת·¢µÄÏûÏ¢ -------- Ö÷Ìâ: [PATCH] fix error: a bin file can truncate itself while running on overlayfs ÈÕÆÚ: Wed, 22 Jun 2016 18:13:08 +0800 ·¢¼þÈË: zhangaihua1@huawei.com ÊÕ¼þÈË: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-unionfs@vger.kernel.org ³­ËÍ: Aihua Zhang From: Aihua Zhang I wrote a testcase to truncate a bin file while it is running on overlayfs. the mount: /dev/mapper/fedora-home on /home type ext4 (rw,relatime,data=ordered) overlay on /tmp type overlay (rw,relatime,lowerdir=/home/zah/lower, upperdir=/home/zah/upper,workdir=/home/zah/workdir) the code cpp: int main(int argc, char *argv[]) { int status; pthread_t thread; int err; char *ptr; ptr = basename(argv[0]); printf("%s\n",ptr); errno = 0; status = truncate(ptr, 4096); printf("status:%d\n",status); printf("errno:%d\n",errno); printf("ETXTBSY:%d\n",ETXTBSY); if ((-1 == status) && (ETXTBSY == errno)) { printf("PASS\n"); return 0; } err = errno; printf("err = %d\n", err); printf("FAIL\n"); return 1; } I running the test on overlayfs, the result as below: Bus error (core dumped) and running the test on ext4, the result as below: status:-1 errno:26 ETXTBSY:26 PASS I add some log, and I find the inode is not correct on overlayfs, and the inode->i_writecount is not correct also called by vfs_truncate-> get_write_access(), the log as below: Jun 22 09:50:38 kernel: [131.872920] deny_write_access: inode ino 64104618 Jun 22 09:50:38 kernel: [131.873109] deny_write_access: inode ino 64104618 Jun 22 09:50:38 kernel: [131.873110] __vma_link_file: inode ino 64104618 Jun 22 09:50:38 kernel: [131.873112] allow_write_access: inode ino 64104618 Jun 22 09:50:38 kernel: [131.873114] deny_write_access: inode ino 64104618 Jun 22 09:50:38 kernel: [131.873115] __vma_link_file: inode ino 64104618 Jun 22 09:50:38 kernel: [131.873116] allow_write_access: inode ino 64104618 Jun 22 09:50:38 kernel: [131.873162] allow_write_access: inode ino 64104618 Jun 22 09:50:38 kernel: [131.873947] __vma_link_file: inode ino 64104618 Jun 22 09:50:38 kernel: [131.874039] vfs_truncate: inode ino:24061 before vfs_truncate, the inode is point to upper filesystem(ext4), and in vfs_truncate the inode is point to overlayfs. So, I fix it by geting the real inode via ovl_d_select_inode. Signed-off-by: Aihua Zhang --- fs/open.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/open.c b/fs/open.c index 93ae3cd..43b17d1 100644 --- a/fs/open.c +++ b/fs/open.c @@ -67,10 +67,16 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs, long vfs_truncate(const struct path *path, loff_t length) { + struct dentry *dentry = path->dentry; struct inode *inode; long error; - inode = path->dentry->d_inode; + if (dentry->d_flags & DCACHE_OP_SELECT_INODE) { + inode = dentry->d_op->d_select_inode(dentry, O_TRUNC); + if (IS_ERR(inode)) + return PTR_ERR(inode); + } else + inode = dentry->d_inode; /* For directories it's -EISDIR, for other non-regulars - -EINVAL */ if (S_ISDIR(inode->i_mode)) @@ -106,7 +112,7 @@ long vfs_truncate(const struct path *path, loff_t length) if (!error) error = security_path_truncate(path); if (!error) - error = do_truncate(path->dentry, length, 0, NULL); + error = do_truncate(dentry, length, 0, NULL); put_write_and_out: put_write_access(inode); -- 1.7.1 .