stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <Alexander.Levin@microsoft.com>
To: "stable@vger.kernel.org" <stable@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Jake Daryll Obina <jake.obina@gmail.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Sasha Levin <Alexander.Levin@microsoft.com>
Subject: [PATCH AUTOSEL for 3.18 080/101] jffs2: Fix use-after-free bug in jffs2_iget()'s error handling path
Date: Mon, 9 Apr 2018 00:41:38 +0000	[thread overview]
Message-ID: <20180409004042.164920-30-alexander.levin@microsoft.com> (raw)
In-Reply-To: <20180409004042.164920-1-alexander.levin@microsoft.com>

From: Jake Daryll Obina <jake.obina@gmail.com>

[ Upstream commit 5bdd0c6f89fba430e18d636493398389dadc3b17 ]

If jffs2_iget() fails for a newly-allocated inode, jffs2_do_clear_inode()
can get called twice in the error handling path, the first call in
jffs2_iget() itself and the second through iget_failed(). This can result
to a use-after-free error in the second jffs2_do_clear_inode() call, such
as shown by the oops below wherein the second jffs2_do_clear_inode() call
was trying to free node fragments that were already freed in the first
jffs2_do_clear_inode() call.

[   78.178860] jffs2: error: (1904) jffs2_do_read_inode_internal: CRC failed for read_inode of inode 24 at physical location 0x1fc00c
[   78.178914] Unable to handle kernel paging request at virtual address 6b6b6b6b6b6b6b7b
[   78.185871] pgd = ffffffc03a567000
[   78.188794] [6b6b6b6b6b6b6b7b] *pgd=0000000000000000, *pud=0000000000000000
[   78.194968] Internal error: Oops: 96000004 [#1] PREEMPT SMP
...
[   78.513147] PC is at rb_first_postorder+0xc/0x28
[   78.516503] LR is at jffs2_kill_fragtree+0x28/0x90 [jffs2]
[   78.520672] pc : [<ffffff8008323d28>] lr : [<ffffff8000eb1cc8>] pstate: 60000105
[   78.526757] sp : ffffff800cea38f0
[   78.528753] x29: ffffff800cea38f0 x28: ffffffc01f3f8e80
[   78.532754] x27: 0000000000000000 x26: ffffff800cea3c70
[   78.536756] x25: 00000000dc67c8ae x24: ffffffc033d6945d
[   78.540759] x23: ffffffc036811740 x22: ffffff800891a5b8
[   78.544760] x21: 0000000000000000 x20: 0000000000000000
[   78.548762] x19: ffffffc037d48910 x18: ffffff800891a588
[   78.552764] x17: 0000000000000800 x16: 0000000000000c00
[   78.556766] x15: 0000000000000010 x14: 6f2065646f6e695f
[   78.560767] x13: 6461657220726f66 x12: 2064656c69616620
[   78.564769] x11: 435243203a6c616e x10: 7265746e695f6564
[   78.568771] x9 : 6f6e695f64616572 x8 : ffffffc037974038
[   78.572774] x7 : bbbbbbbbbbbbbbbb x6 : 0000000000000008
[   78.576775] x5 : 002f91d85bd44a2f x4 : 0000000000000000
[   78.580777] x3 : 0000000000000000 x2 : 000000403755e000
[   78.584779] x1 : 6b6b6b6b6b6b6b6b x0 : 6b6b6b6b6b6b6b6b
...
[   79.038551] [<ffffff8008323d28>] rb_first_postorder+0xc/0x28
[   79.042962] [<ffffff8000eb5578>] jffs2_do_clear_inode+0x88/0x100 [jffs2]
[   79.048395] [<ffffff8000eb9ddc>] jffs2_evict_inode+0x3c/0x48 [jffs2]
[   79.053443] [<ffffff8008201ca8>] evict+0xb0/0x168
[   79.056835] [<ffffff8008202650>] iput+0x1c0/0x200
[   79.060228] [<ffffff800820408c>] iget_failed+0x30/0x3c
[   79.064097] [<ffffff8000eba0c0>] jffs2_iget+0x2d8/0x360 [jffs2]
[   79.068740] [<ffffff8000eb0a60>] jffs2_lookup+0xe8/0x130 [jffs2]
[   79.073434] [<ffffff80081f1a28>] lookup_slow+0x118/0x190
[   79.077435] [<ffffff80081f4708>] walk_component+0xfc/0x28c
[   79.081610] [<ffffff80081f4dd0>] path_lookupat+0x84/0x108
[   79.085699] [<ffffff80081f5578>] filename_lookup+0x88/0x100
[   79.089960] [<ffffff80081f572c>] user_path_at_empty+0x58/0x6c
[   79.094396] [<ffffff80081ebe14>] vfs_statx+0xa4/0x114
[   79.098138] [<ffffff80081ec44c>] SyS_newfstatat+0x58/0x98
[   79.102227] [<ffffff800808354c>] __sys_trace_return+0x0/0x4
[   79.106489] Code: d65f03c0 f9400001 b40000e1 aa0103e0 (f9400821)

The jffs2_do_clear_inode() call in jffs2_iget() is unnecessary since
iget_failed() will eventually call jffs2_do_clear_inode() if needed, so
just remove it.

Fixes: 5451f79f5f81 ("iget: stop JFFS2 from using iget() and read_inode()")
Reviewed-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Jake Daryll Obina <jake.obina@gmail.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
---
 fs/jffs2/fs.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c
index 601afd1afddf..c0ff490974a6 100644
--- a/fs/jffs2/fs.c
+++ b/fs/jffs2/fs.c
@@ -363,7 +363,6 @@ error_io:
 	ret = -EIO;
 error:
 	mutex_unlock(&f->sem);
-	jffs2_do_clear_inode(c, f);
 	iget_failed(inode);
 	return ERR_PTR(ret);
 }
-- 
2.15.1

  parent reply	other threads:[~2018-04-09  0:41 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-09  0:41 [PATCH AUTOSEL for 3.18 051/101] scsi: sun_esp: fix device reference leaks Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 052/101] powerpc/fadump: avoid duplicates in crash memory ranges Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 053/101] libertas: Fix lbs_prb_rsp_limit_set() Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 054/101] PCI: Enable ECRC only if device supports it Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 055/101] MIPS: CPS: Prevent multi-core with dcache aliasing Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 056/101] MIPS: Handle tlbex-tlbp race condition Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 057/101] arm64: ptrace: Avoid setting compat FP[SC]R to garbage if get_user fails Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 058/101] arm64: ptrace: Fix incorrect get_user() use in compat_vfp_set() Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 059/101] x86/um: thin archives build fix Sasha Levin
2018-04-09  4:29   ` Nicholas Piggin
2018-04-15 15:02     ` Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 060/101] fs: warn in case userspace lied about modprobe return Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 061/101] ext4: change fast symlink test to not rely on i_blocks Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 062/101] irqchip/gic-v3: Honor forced affinity setting Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 064/101] firewire-ohci: work around oversized DMA reads on JMicron controllers Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 063/101] vmlfb: Fix error handling in cr_pll_init() Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 065/101] ASoC: au1x: Fix timeout tests in au1xac97c_ac97_read() Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 066/101] kvm: x86: fix KVM_XEN_HVM_CONFIG ioctl Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 067/101] tracing/hrtimer: Fix tracing bugs by taking all clock bases and modes into account Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 068/101] PCI: Add function 1 DMA alias quirk for Marvell 9128 Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 070/101] dm thin: fix documentation relative to low water mark threshold Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 069/101] tools lib traceevent: Fix get_field_str() for dynamic strings Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 071/101] nfs: Do not convert nfs_idmap_cache_timeout to jiffies Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 073/101] kconfig: Don't leak main menus during parsing Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 072/101] watchdog: sp5100_tco: Fix watchdog disable bit Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 074/101] kconfig: Fix automatic menu creation mem leak Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 075/101] kconfig: Fix expr_free() E_NOT leak Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 076/101] btrfs: Fix out of bounds access in btrfs_search_slot Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 077/101] scsi: devinfo: fix format of the device list Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 078/101] scsi: fas216: fix sense buffer initialization Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 079/101] HID: roccat: prevent an out of bounds read in kovaplus_profile_activated() Sasha Levin
2018-04-09  0:41 ` Sasha Levin [this message]
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 081/101] RDMA/mlx5: Avoid memory leak in case of XRCD dealloc failure Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 082/101] ocfs2: return -EROFS to mount.ocfs2 if inode block is invalid Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 083/101] ocfs2/acl: use 'ip_xattr_sem' to protect getting extended attribute Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 084/101] mm/mempolicy: fix the check of nodemask from user Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 085/101] mm/mempolicy: add nodes_empty check in SYSC_migrate_pages Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 086/101] asm-generic: provide generic_pmdp_establish() Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 087/101] mm: pin address_space before dereferencing it while isolating an LRU page Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 088/101] IB/ipoib: Fix for potential no-carrier state Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 089/101] x86/power: Fix swsusp_arch_resume prototype Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 091/101] ACPI: processor_perflib: Do not send _PPC change notification if not ready Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 090/101] firmware: dmi_scan: Fix handling of empty DMI strings Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 092/101] MIPS: TXx9: use IS_BUILTIN() for CONFIG_LEDS_CLASS Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 093/101] xen/grant-table: Use put_page instead of free_page Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 094/101] proc: fix /proc/*/map_files lookup Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 095/101] cifs: silence compiler warnings showing up with gcc-8.0.0 Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 096/101] bcache: properly set task state in bch_writeback_thread() Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 098/101] bcache: fix for data collapse after re-attaching an attached device Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 097/101] bcache: fix for allocator and register thread race Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 099/101] bcache: return attach error when no cache set exist Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 100/101] nfsd: return RESOURCE not GARBAGE_ARGS on too many ops Sasha Levin
2018-04-09  0:41 ` [PATCH AUTOSEL for 3.18 101/101] irqchip/gic-v3: Change pr_debug message to pr_devel Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180409004042.164920-30-alexander.levin@microsoft.com \
    --to=alexander.levin@microsoft.com \
    --cc=jake.obina@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).