Skip to contentSkip to conversation

ecryptfs: release inode on error path in ecryptfs_lookup_interpose

PATCH In review Alexander Mikhalitsyn 2 participants 3 messages Nov 24 – Nov 25

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ecryptfs: release inode on error path in ecryptfs_lookup_interpose

Currently, when ecryptfs_i_size_read() fails we only do make_bad_inode() which only removes the inode from a hash. So it's not getting released and on umount we get "VFS: Busy inodes after unmount of ecryptfs" (see below).

Let's fix it by using iget_failed() when inode is I_NEW and iput() when it's not.

This was accidentally found while working on SB_I_PSEUDO fix.

------------[ cut here ]------------
VFS: Busy inodes after unmount of ecryptfs (ecryptfs)
WARNING: fs/super.c:731 at generic_shutdown_super+0x117/0x1a0, CPU#11: umount/402
Modules linked in:
CPU: 11 UID: 0 PID: 402 Comm: umount Not tainted 7.4.0-rc1-virtme #9 PREEMPT(lazy)
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
RIP: 0010:generic_shutdown_super+0x125/0x1a0
Code: 5d 5d c3 cc cc cc cc e8 19 d0 f3 ff 48 8b bb 18 01 00 00 eb d7 48 8d 3d a9 93 d1 01 48 8b 43 50 48 8d b3 d8 03 00 00 48 8b 10 <67> 48 0f b9 3a 4c 8d ab 40 05 00 00 4c 89 ef e8 17 6c b0 00 48 8b
RSP: 0018:ffffccc0406bbcf8 EFLAGS: 00010283
RAX: ffffffff87d54a20 RBX: ffff8a7bc2358800 RCX: 00000000000000b5
RDX: ffffffff873e7853 RSI: ffff8a7bc2358bd8 RDI: ffffffff87e52550
RBP: ffffccc0406bbd10 R08: ffff8a7bc235d408 R09: fffff12a00000000
R10: ffffccc0406bbcf0 R11: ffffffff87d209d8 R12: ffff8a7bc2358d48
R13: ffff8a7bc2388824 R14: 0000000000000000 R15: 0000000000000000
FS:  00007fd846e02840(0000) GS:ffff8a7c76af9000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fd84716e8e0 CR3: 00000000037d8000 CR4: 0000000000350eb0
Call Trace:
 <TASK>
 kill_anon_super+0x1c/0x80
 ecryptfs_kill_block_super+0x1a/0x50
 deactivate_locked_super+0x39/0xc0
 deactivate_super+0x47/0x60
 cleanup_mnt+0x3b/0x80
 __cleanup_mnt+0x16/0x20
 task_work_run+0x64/0x90
 exit_to_user_mode_loop+0x177/0x570
 do_syscall_64+0x352/0x410
 ? up_read+0x1f/0xe0
 ? schedule+0x27/0xb0
 ? schedule+0x27/0xb0
 ? schedule+0x27/0xb0
 ? trace_preempt_on+0x28/0x80
 ? schedule+0x38/0xb0
 ? preempt_count_sub+0x4d/0x70
 ? irqentry_exit+0x2e1/0x700
 ? exc_page_fault+0x8d/0x170
 ? do_syscall_64+0x33/0x410
 entry_SYSCALL_64_after_hwframe+0x76/0x7e
RIP: 0033:0x7fd84705c1d7
Code: 0d 00 f7 d8 64 89 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 31 f6 e9 09 00 00 00 66 0f 1f 84 00 00 00 00 00 b8 a6 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 01 c3 48 8b 15 09 3c 0d 00 f7 d8 64 89 02 b8
RSP: 002b:00007ffd3839fae8 EFLAGS: 00000246 ORIG_RAX: 00000000000000a6
RAX: 0000000000000000 RBX: 000055b7f819dbf8 RCX: 00007fd84705c1d7
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 000055b7f819df30
RBP: 0000000000000000 R08: 00007ffd3839e8d0 R09: 00000000ffffffff
R10: 0000000000000103 R11: 0000000000000246 R12: 00007fd8471ba26c
R13: 000055b7f819df30 R14: 0000000000000000 R15: 000055b7f819daf0
 </TASK>
---[ end trace 0000000000000000 ]---
Fixes 3b06b3ebf441 ("eCryptfs: Fix new inode race condition")
---
 fs/ecryptfs/inode.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/ecryptfs/inode.c +4 -1
index 48e520960d66..3a966348a578 100644
@@ -362,7 +362,10 @@ static struct dentry *ecryptfs_lookup_interpose(struct dentry *dentry,
 	if (S_ISREG(inode->i_mode)) {
 		rc = ecryptfs_i_size_read(dentry, inode);
 		if (rc) {
-			make_bad_inode(inode);
+			if (inode_state_read_once(inode) & I_NEW)
+				iget_failed(inode);
+			else
+				iput(inode);
 			return ERR_PTR(rc);
 		}
 	}
Signature · 1 line
2.47.3
reviewer
#1 lore raw
Quoted 58 lines · Alexander Mikhalitsyn

Currently, when ecryptfs_i_size_read() fails we only do make_bad_inode() which only removes the inode from a hash. So it's not getting released and on umount we get "VFS: Busy inodes after unmount of ecryptfs" (see below).

Let's fix it by using iget_failed() when inode is I_NEW and iput() when it's not.

This was accidentally found while working on SB_I_PSEUDO fix.

------------[ cut here ]------------
VFS: Busy inodes after unmount of ecryptfs (ecryptfs)
WARNING: fs/super.c:731 at generic_shutdown_super+0x117/0x1a0, CPU#11: umount/402
Modules linked in:
CPU: 11 UID: 0 PID: 402 Comm: umount Not tainted 7.4.0-rc1-virtme #9 PREEMPT(lazy)
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
RIP: 0010:generic_shutdown_super+0x125/0x1a0
Code: 5d 5d c3 cc cc cc cc e8 19 d0 f3 ff 48 8b bb 18 01 00 00 eb d7 48 8d 3d a9 93 d1 01 48 8b 43 50 48 8d b3 d8 03 00 00 48 8b 10 <67> 48 0f b9 3a 4c 8d ab 40 05 00 00 4c 89 ef e8 17 6c b0 00 48 8b
RSP: 0018:ffffccc0406bbcf8 EFLAGS: 00010283
RAX: ffffffff87d54a20 RBX: ffff8a7bc2358800 RCX: 00000000000000b5
RDX: ffffffff873e7853 RSI: ffff8a7bc2358bd8 RDI: ffffffff87e52550
RBP: ffffccc0406bbd10 R08: ffff8a7bc235d408 R09: fffff12a00000000
R10: ffffccc0406bbcf0 R11: ffffffff87d209d8 R12: ffff8a7bc2358d48
R13: ffff8a7bc2388824 R14: 0000000000000000 R15: 0000000000000000
FS:  00007fd846e02840(0000) GS:ffff8a7c76af9000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fd84716e8e0 CR3: 00000000037d8000 CR4: 0000000000350eb0
Call Trace:
 <TASK>
 kill_anon_super+0x1c/0x80
 ecryptfs_kill_block_super+0x1a/0x50
 deactivate_locked_super+0x39/0xc0
 deactivate_super+0x47/0x60
 cleanup_mnt+0x3b/0x80
 __cleanup_mnt+0x16/0x20
 task_work_run+0x64/0x90
 exit_to_user_mode_loop+0x177/0x570
 do_syscall_64+0x352/0x410
 ? up_read+0x1f/0xe0
 ? schedule+0x27/0xb0
 ? schedule+0x27/0xb0
 ? schedule+0x27/0xb0
 ? trace_preempt_on+0x28/0x80
 ? schedule+0x38/0xb0
 ? preempt_count_sub+0x4d/0x70
 ? irqentry_exit+0x2e1/0x700
 ? exc_page_fault+0x8d/0x170
 ? do_syscall_64+0x33/0x410
 entry_SYSCALL_64_after_hwframe+0x76/0x7e
RIP: 0033:0x7fd84705c1d7
Code: 0d 00 f7 d8 64 89 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 31 f6 e9 09 00 00 00 66 0f 1f 84 00 00 00 00 00 b8 a6 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 01 c3 48 8b 15 09 3c 0d 00 f7 d8 64 89 02 b8
RSP: 002b:00007ffd3839fae8 EFLAGS: 00000246 ORIG_RAX: 00000000000000a6
RAX: 0000000000000000 RBX: 000055b7f819dbf8 RCX: 00007fd84705c1d7
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 000055b7f819df30
RBP: 0000000000000000 R08: 00007ffd3839e8d0 R09: 00000000ffffffff
R10: 0000000000000103 R11: 0000000000000246 R12: 00007fd8471ba26c
R13: 000055b7f819df30 R14: 0000000000000000 R15: 000055b7f819daf0
 </TASK>
---[ end trace 0000000000000000 ]---
Quoted 2 lines
Fixes 3b06b3ebf441 ("eCryptfs: Fix new inode race condition")

I can see this fix already in vfs.git as b793b0bfa631 ("ecryptfs: don't leak the inode when a lookup can't open the lower file").

Honza

Quoted 23 lines
---
 fs/ecryptfs/inode.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/ecryptfs/inode.c +4 -1
index 48e520960d66..3a966348a578 100644
@@ -362,7 +362,10 @@ static struct dentry *ecryptfs_lookup_interpose(struct dentry *dentry,
 	if (S_ISREG(inode->i_mode)) {
 		rc = ecryptfs_i_size_read(dentry, inode);
 		if (rc) {
-			make_bad_inode(inode);
+			if (inode_state_read_once(inode) & I_NEW)
+				iget_failed(inode);
+			else
+				iput(inode);
 			return ERR_PTR(rc);
 		}
 	}
Signature · 1 line
2.47.3
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#2 lore raw
Quoted 60 lines · Jan Kara
Quoted 58 lines · Alexander Mikhalitsyn

Currently, when ecryptfs_i_size_read() fails we only do make_bad_inode() which only removes the inode from a hash. So it's not getting released and on umount we get "VFS: Busy inodes after unmount of ecryptfs" (see below).

Let's fix it by using iget_failed() when inode is I_NEW and iput() when it's not.

This was accidentally found while working on SB_I_PSEUDO fix.

------------[ cut here ]------------
VFS: Busy inodes after unmount of ecryptfs (ecryptfs)
WARNING: fs/super.c:731 at generic_shutdown_super+0x117/0x1a0, CPU#11: umount/402
Modules linked in:
CPU: 11 UID: 0 PID: 402 Comm: umount Not tainted 7.4.0-rc1-virtme #9 PREEMPT(lazy)
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
RIP: 0010:generic_shutdown_super+0x125/0x1a0
Code: 5d 5d c3 cc cc cc cc e8 19 d0 f3 ff 48 8b bb 18 01 00 00 eb d7 48 8d 3d a9 93 d1 01 48 8b 43 50 48 8d b3 d8 03 00 00 48 8b 10 <67> 48 0f b9 3a 4c 8d ab 40 05 00 00 4c 89 ef e8 17 6c b0 00 48 8b
RSP: 0018:ffffccc0406bbcf8 EFLAGS: 00010283
RAX: ffffffff87d54a20 RBX: ffff8a7bc2358800 RCX: 00000000000000b5
RDX: ffffffff873e7853 RSI: ffff8a7bc2358bd8 RDI: ffffffff87e52550
RBP: ffffccc0406bbd10 R08: ffff8a7bc235d408 R09: fffff12a00000000
R10: ffffccc0406bbcf0 R11: ffffffff87d209d8 R12: ffff8a7bc2358d48
R13: ffff8a7bc2388824 R14: 0000000000000000 R15: 0000000000000000
FS:  00007fd846e02840(0000) GS:ffff8a7c76af9000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fd84716e8e0 CR3: 00000000037d8000 CR4: 0000000000350eb0
Call Trace:
 <TASK>
 kill_anon_super+0x1c/0x80
 ecryptfs_kill_block_super+0x1a/0x50
 deactivate_locked_super+0x39/0xc0
 deactivate_super+0x47/0x60
 cleanup_mnt+0x3b/0x80
 __cleanup_mnt+0x16/0x20
 task_work_run+0x64/0x90
 exit_to_user_mode_loop+0x177/0x570
 do_syscall_64+0x352/0x410
 ? up_read+0x1f/0xe0
 ? schedule+0x27/0xb0
 ? schedule+0x27/0xb0
 ? schedule+0x27/0xb0
 ? trace_preempt_on+0x28/0x80
 ? schedule+0x38/0xb0
 ? preempt_count_sub+0x4d/0x70
 ? irqentry_exit+0x2e1/0x700
 ? exc_page_fault+0x8d/0x170
 ? do_syscall_64+0x33/0x410
 entry_SYSCALL_64_after_hwframe+0x76/0x7e
RIP: 0033:0x7fd84705c1d7
Code: 0d 00 f7 d8 64 89 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 31 f6 e9 09 00 00 00 66 0f 1f 84 00 00 00 00 00 b8 a6 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 01 c3 48 8b 15 09 3c 0d 00 f7 d8 64 89 02 b8
RSP: 002b:00007ffd3839fae8 EFLAGS: 00000246 ORIG_RAX: 00000000000000a6
RAX: 0000000000000000 RBX: 000055b7f819dbf8 RCX: 00007fd84705c1d7
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 000055b7f819df30
RBP: 0000000000000000 R08: 00007ffd3839e8d0 R09: 00000000ffffffff
R10: 0000000000000103 R11: 0000000000000246 R12: 00007fd8471ba26c
R13: 000055b7f819df30 R14: 0000000000000000 R15: 000055b7f819daf0
 </TASK>
---[ end trace 0000000000000000 ]---
Quoted 2 lines
Quoted 2 lines
Fixes 3b06b3ebf441 ("eCryptfs: Fix new inode race condition")

Dear Jan,

Quoted 3 lines

I can see this fix already in vfs.git as b793b0bfa631 ("ecryptfs: don't leak the inode when a lookup can't open the lower file").

Ugh, my bad. I've checked a next branch for ecryptfs and quickly looked on the mailing list and didn't find it.

Sorry for the noise.

Kind regards,
Alex

Quoted 29 lines

Honza

Quoted 21 lines
---
 fs/ecryptfs/inode.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/ecryptfs/inode.c +4 -2
index 48e520960d66..3a966348a578 100644
@@ -362,7 +362,10 @@ static struct dentry *ecryptfs_lookup_interpose(struct dentry *dentry,
      if (S_ISREG(inode->i_mode)) {
              rc = ecryptfs_i_size_read(dentry, inode);
              if (rc) {
-                     make_bad_inode(inode);
+                     if (inode_state_read_once(inode) & I_NEW)
+                             iget_failed(inode);
+                     else
+                             iput(inode);
                      return ERR_PTR(rc);
              }
      }
--
Quoted 2 lines

2.47.3

--
Jan Kara <[email protected]>
SUSE Labs, CR