Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp516022pxx; Wed, 28 Oct 2020 10:05:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYZDt6oiHx5OpOZtYKwwL8Fv+zQQNbFfx5taowbvUifnAI99gcjwMsK06WHScgya4lAXih X-Received: by 2002:a50:e881:: with SMTP id f1mr8887574edn.58.1603904745080; Wed, 28 Oct 2020 10:05:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603904745; cv=none; d=google.com; s=arc-20160816; b=Uswa/Xq1fdbWfmjPY8PqGjjGagwgv70RXdRy2naHXC8QnMcaRR41OdZto+ljWbXwyS 2OQvnAh6T1Pxp0d63L2ULLIlVYRRCqnaaQ9asxTJLsTCY4sSXrxD2QiTRaMU8Cw5nmGx lY+4B60JCeVPRCMhYP8e3bzb/WLMRGdQVtjoFcv1/cbGArXrCFR8nS32OC/dFGIEoouW QnU/zPiBnYTV8DImziKdAiKmdojTZ1absQUHFV//pGZoHLrxGBDkjOjoc09D+fQQ4pa8 JT7rlcApTdDCPDZI/jbP4OKvsiR9ZTR4VE77AgTs1uZnmFLbVKscph8yibnLayTDbCgc qRiA== 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=iRLhSctIoxEkgPn1Nb3X7tsF9KlYrpFMrG+oo8ud3tM=; b=tvSGM+pJuqDY2w4byHZXF0CpYqhVNmzZRkBjviowNDm8dvfmRZz9HAFkgtNAt08Pb+ mqgT5U4IbfpfEvLk3sb2pC18NYmTeIOYx6DgNFw1nnnOC9CJ7kuX+W2vqHpUFVIF+a4V d3roUoUWY5bHIs8NdHISD9agFCKW7tOFJCDHm0dTopiEphgTghd2rH/ohmrMlHXtNPuT U9yDsgDAiinNPPyZvIilJ/qXEbkrTH8jr/VZsvrQ0mXcaBvjuk9lGEMS+rpWRpdaruIc 9A2sIG9rxiWikFdU/bybScB27bm2b7QJ3707fuBQqtZtAoC8bBuMfsh7lpv6RqpqOj8k RO/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bRS1IJ3T; 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 bu23si3659073ejb.83.2020.10.28.10.05.11; Wed, 28 Oct 2020 10:05:45 -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=bRS1IJ3T; 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 S1820056AbgJ0Rcb (ORCPT + 99 others); Tue, 27 Oct 2020 13:32:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:40588 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1762197AbgJ0Ol0 (ORCPT ); Tue, 27 Oct 2020 10:41:26 -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 C52BA207BB; Tue, 27 Oct 2020 14:41:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809685; bh=cXy6+26ePzReBMf/5wBOpAdSF2gtRECGNpeHu9LTGDk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bRS1IJ3TLarTWj066qXrNSl5/0Bz/zCGMvwWVtmR638gO3nwzQlaIxcNzpCqrJNQb 4oaMNHKx1rmRAr3If68ARZdSCzNQZTs5fL0TrUM4+n/Yp3jjY7qJIihZlBFpgjmy9w HE9vmrehGaesc/q7KE1F9Jje4j5T54mgmLInEsR4= 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.4 252/408] f2fs: wait for sysfs kobject removal before freeing f2fs_sb_info Date: Tue, 27 Oct 2020 14:53:10 +0100 Message-Id: <20201027135506.734206214@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@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 170934430d7d7..029e693e201cf 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c @@ -788,4 +788,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