Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp479072pxx; Wed, 28 Oct 2020 09:15:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7EQKJyDbmYKUSzD2UzpwX1XDqTOxmVV5ut6nHr54rnt75ijdEvIZ9WNwSvjTnZZ8OuPIV X-Received: by 2002:a50:950e:: with SMTP id u14mr8485953eda.260.1603901701565; Wed, 28 Oct 2020 09:15:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603901701; cv=none; d=google.com; s=arc-20160816; b=zayvLCrXdbGcBucjNxYb7vNq8nGJodaR5ESj1xJKRvZEFXhS9Xe6nzxBH95zZ+Vkb7 +uk74m3gEDGxZcWiQiQWrY13GKT1oSlMqw50b7LBSSLS5/pbNGgFDCRCuwHK9NfK2ZVh hN0wp3hyvxc4YbwWR/Q5YTDmWIbAH+LuM5W6hyzqIDD/qizVRRqfZ7BW4QhtytW0bvUJ pvfeqwlrP5qCL5OIIIux5ssAYBbrwKmac4Sw2Jtr5sHIe7Um7s1GO6Pwi5rLWzVORMcU 7pp7OGJgpJ9UcK+w/10qvAfMBU7WV86ns54fyl4DXyQbB89utezbrA8oYMIgPSi8f1eX awfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MMkLzwJeNjuXOcRftYEhZx0XYjKIYLAUZtQVYHFYME0=; b=lUd/SVFkQia4zzPJkMjJmV4OVI/89zQppg26GvcXeNGQwi9+aLoHyk1x/i9Tnc2BmK ERvN2vEwOExTk+1psX+7ZgAoUOwyO581QwLDxZuo6HREb53qcXDwc9XDSLIqgYDlicYU dHe0fhmtIiN0yHMcYxkWn0xyKsFg+lLmCODGLvHbr8Wdhxf+ezKMeJwc4ltqBNyNh3iX dH2Zili9u1Ft559evqjlEp2pfl0z+LvWi27k4OvkAJ44VBzfnAtiMe0K4HpD6+WG/xeh A7C1NoiXZJW93rylSGhrl+ecvb48EY7raw+Vlk1ECC1ztcsNSah5dNcy6A3Qyh3ih3a1 vEpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="P/5EcdMH"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cd2si3818422ejb.215.2020.10.28.09.14.38; Wed, 28 Oct 2020 09:15:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="P/5EcdMH"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1815536AbgJ0RC7 (ORCPT + 99 others); Tue, 27 Oct 2020 13:02:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:42528 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1793660AbgJ0PHm (ORCPT ); Tue, 27 Oct 2020 11:07:42 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BD2D22072E; Tue, 27 Oct 2020 15:07:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603811260; bh=v8J1bSH27clyu/wnF1u4TowpQt3lPBYqNj9HUjrYVDY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P/5EcdMHtinabxmM7H+k8gXefLAwzL+c+I5lqj1uPexEQQ/4lvXSgjNiKy4MQU2z4 BDtqo8VXaskPuHUiqelnfmbtnrxD1+lCMzWHUupIXlAGCWHd/aRiibTyqLtIgSUpeO cIXtYJm39ktURCsdMGxryoXKU9CzoZVn6x0Lpw38= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jaegeuk Kim , Chao Yu , Jamie Iles , Chao Yu , Sasha Levin Subject: [PATCH 5.8 413/633] f2fs: wait for sysfs kobject removal before freeing f2fs_sb_info Date: Tue, 27 Oct 2020 14:52:36 +0100 Message-Id: <20201027135542.096527194@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jamie Iles [ Upstream commit ae284d87abade58c8db7760c808f311ef1ce693c ] syzkaller found that with CONFIG_DEBUG_KOBJECT_RELEASE=y, unmounting an f2fs filesystem could result in the following splat: kobject: 'loop5' ((____ptrval____)): kobject_release, parent 0000000000000000 (delayed 250) kobject: 'f2fs_xattr_entry-7:5' ((____ptrval____)): kobject_release, parent 0000000000000000 (delayed 750) ------------[ cut here ]------------ ODEBUG: free active (active state 0) object type: timer_list hint: delayed_work_timer_fn+0x0/0x98 WARNING: CPU: 0 PID: 699 at lib/debugobjects.c:485 debug_print_object+0x180/0x240 Kernel panic - not syncing: panic_on_warn set ... CPU: 0 PID: 699 Comm: syz-executor.5 Tainted: G S 5.9.0-rc8+ #101 Hardware name: linux,dummy-virt (DT) Call trace: dump_backtrace+0x0/0x4d8 show_stack+0x34/0x48 dump_stack+0x174/0x1f8 panic+0x360/0x7a0 __warn+0x244/0x2ec report_bug+0x240/0x398 bug_handler+0x50/0xc0 call_break_hook+0x160/0x1d8 brk_handler+0x30/0xc0 do_debug_exception+0x184/0x340 el1_dbg+0x48/0xb0 el1_sync_handler+0x170/0x1c8 el1_sync+0x80/0x100 debug_print_object+0x180/0x240 debug_check_no_obj_freed+0x200/0x430 slab_free_freelist_hook+0x190/0x210 kfree+0x13c/0x460 f2fs_put_super+0x624/0xa58 generic_shutdown_super+0x120/0x300 kill_block_super+0x94/0xf8 kill_f2fs_super+0x244/0x308 deactivate_locked_super+0x104/0x150 deactivate_super+0x118/0x148 cleanup_mnt+0x27c/0x3c0 __cleanup_mnt+0x28/0x38 task_work_run+0x10c/0x248 do_notify_resume+0x9d4/0x1188 work_pending+0x8/0x34c Like the error handling for f2fs_register_sysfs(), we need to wait for the kobject to be destroyed before returning to prevent a potential use-after-free. Fixes: bf9e697ecd42 ("f2fs: expose features to sysfs entry") Cc: Jaegeuk Kim Cc: Chao Yu Signed-off-by: Jamie Iles Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/sysfs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index c5e32ceb94827..e186d3af61368 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c @@ -964,4 +964,5 @@ void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi) } kobject_del(&sbi->s_kobj); kobject_put(&sbi->s_kobj); + wait_for_completion(&sbi->s_kobj_unregister); } -- 2.25.1