From patchwork Tue May 23 09:33:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luis Henriques X-Patchwork-Id: 97936 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2010386vqo; Tue, 23 May 2023 02:39:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6zS0iL6Klncq1+JIUKdXNCDdz9ryGQRiC8RHSPEShMBVSUxSh8MzecE5mySgx8yRG21kCb X-Received: by 2002:a05:6a00:891:b0:63b:8afe:a4dc with SMTP id q17-20020a056a00089100b0063b8afea4dcmr15785651pfj.30.1684834746862; Tue, 23 May 2023 02:39:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684834746; cv=none; d=google.com; s=arc-20160816; b=xTtKQfO1KeMzuU62MnTJe+il1PFqZz3tfEGYV6VQY0gFoa+iAQ5Mw/qqA0csgGelX6 uFiBL3Ye/alszTMpRThta64py0x/FdjzwcGehm/vBtDO8rgAa7tFK1S5CAdeb6n+t+4W fIezZOuCs9Krb5bRojiZAnJldq2ybnxK3Ft7tucQgKPAeuYJdyhM2hCOSlhINVRBS+wy +raiqV6ArVWV+WT2vaPf799QlzKGCs74mbvI+hz8ay0Bnll1FrK150wColb7kivvW0xL 5CGulE2tVujQ55eBzdBT7oLKitDQeHxLwVKEko5r7Vi7S79++pB4hs2HOTAAIuZDVBpd K+gg== 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 :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=/lOsj+GiEHTCgI/sii2dYOxPg7fwJmqfZ38JOxtYg30=; b=S//vuUN/GhZcMaaX6L/MCKBe49tO6SuRQkETTOP4NjxtpDdZNcz6s9ATsnH/2CmsL0 ycVmhtl2IBwRQblHUAUcQi5Qj70QB378v25x/2UOkGCnNgTnmPgwV0UvrfK63xyvq+Wm AESkANAAl1gCWnQPTUEAwqfyqzb1HSJSanm4W6nNl7PCL5pQW5pU1f7ypQSXMAPqvKuS V5Jsl2XExSHDLPpvDdZetSuZsP6QWr13G66IBxQSbLlQVJ+fwATwQgBj0jt9Kztejx3D LjwKUoPbDL8yyc0IfLRqyLBaz2XlVvkdQVKSMymmxERXoI9NAhgaTNpI6Z2O3p20Ap69 U/ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=MrAQpfWL; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l11-20020a633e0b000000b005369f4111b1si440205pga.658.2023.05.23.02.38.54; Tue, 23 May 2023 02:39:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=MrAQpfWL; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236045AbjEWJd1 (ORCPT + 99 others); Tue, 23 May 2023 05:33:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235864AbjEWJdU (ORCPT ); Tue, 23 May 2023 05:33:20 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3ADB31BB for ; Tue, 23 May 2023 02:33:14 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D04A32288F; Tue, 23 May 2023 09:33:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684834391; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/lOsj+GiEHTCgI/sii2dYOxPg7fwJmqfZ38JOxtYg30=; b=MrAQpfWLUi8IpVF/ihwJRsY81cRa/l0ICrSmRAiXdf0bw6F/jxlB/xcG75ZZYbt+i/w+tE 4U0Gak5572dT/I9Awv/hOLzFw0Pq3mou8ftOdQWICeKYkAqO0l9fBeMcsNdEZXzJLHGe1H /9W813DNmhVFkCQSRASut1VGW0HPlVg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684834391; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/lOsj+GiEHTCgI/sii2dYOxPg7fwJmqfZ38JOxtYg30=; b=hQaqF6vIDr8I6gzKDszU8Yir1ZU20woRIgODrQOtMrUjacCbU11TEWx1y9MWXcd1vReh3u VGSCYvIRftLAkxDg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4EC7C13588; Tue, 23 May 2023 09:33:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id l0XoD1eIbGTMVwAAMHmgww (envelope-from ); Tue, 23 May 2023 09:33:11 +0000 Received: from localhost (brahms.olymp [local]) by brahms.olymp (OpenSMTPD) with ESMTPA id 906670e4; Tue, 23 May 2023 09:33:10 +0000 (UTC) From: =?utf-8?q?Lu=C3=ADs_Henriques?= To: Mark Fasheh , Joel Becker , Joseph Qi , Heming Zhao Cc: ocfs2-devel@oss.oracle.com, linux-kernel@vger.kernel.org, =?utf-8?q?Lu?= =?utf-8?q?=C3=ADs_Henriques?= Subject: [PATCH v2] ocfs2: fix use-after-free when unmounting read-only filesystem Date: Tue, 23 May 2023 10:33:10 +0100 Message-Id: <20230523093310.2628-1-lhenriques@suse.de> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766677279090243192?= X-GMAIL-MSGID: =?utf-8?q?1766677279090243192?= It's trivial to trigger a use-after-free bug in the ocfs2 quotas code using fstest generic/452. After a read-only remount, quotas are suspended and ocfs2_mem_dqinfo is freed through ->ocfs2_local_free_info(). When unmounting the filesystem, an UAF access to the oinfo will eventually cause a crash. BUG: KASAN: slab-use-after-free in timer_delete+0x54/0xc0 Read of size 8 at addr ffff8880389a8208 by task umount/669 ... Call Trace: ... timer_delete+0x54/0xc0 try_to_grab_pending+0x31/0x230 __cancel_work_timer+0x6c/0x270 ocfs2_disable_quotas.isra.0+0x3e/0xf0 [ocfs2] ocfs2_dismount_volume+0xdd/0x450 [ocfs2] generic_shutdown_super+0xaa/0x280 kill_block_super+0x46/0x70 deactivate_locked_super+0x4d/0xb0 cleanup_mnt+0x135/0x1f0 ... Allocated by task 632: kasan_save_stack+0x1c/0x40 kasan_set_track+0x21/0x30 __kasan_kmalloc+0x8b/0x90 ocfs2_local_read_info+0xe3/0x9a0 [ocfs2] dquot_load_quota_sb+0x34b/0x680 dquot_load_quota_inode+0xfe/0x1a0 ocfs2_enable_quotas+0x190/0x2f0 [ocfs2] ocfs2_fill_super+0x14ef/0x2120 [ocfs2] mount_bdev+0x1be/0x200 legacy_get_tree+0x6c/0xb0 vfs_get_tree+0x3e/0x110 path_mount+0xa90/0xe10 __x64_sys_mount+0x16f/0x1a0 do_syscall_64+0x43/0x90 entry_SYSCALL_64_after_hwframe+0x72/0xdc Freed by task 650: kasan_save_stack+0x1c/0x40 kasan_set_track+0x21/0x30 kasan_save_free_info+0x2a/0x50 __kasan_slab_free+0xf9/0x150 __kmem_cache_free+0x89/0x180 ocfs2_local_free_info+0x2ba/0x3f0 [ocfs2] dquot_disable+0x35f/0xa70 ocfs2_susp_quotas.isra.0+0x159/0x1a0 [ocfs2] ocfs2_remount+0x150/0x580 [ocfs2] reconfigure_super+0x1a5/0x3a0 path_mount+0xc8a/0xe10 __x64_sys_mount+0x16f/0x1a0 do_syscall_64+0x43/0x90 entry_SYSCALL_64_after_hwframe+0x72/0xdc Cc: Signed-off-by: Luís Henriques Reviewed-by: Joseph Qi Tested-by: Joseph Qi --- Changes since v1: - Fixed changelog to explicitly state 'read-only remount' - Added KASAN splat to changelog fs/ocfs2/super.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c index 0b0e6a132101..988d1c076861 100644 --- a/fs/ocfs2/super.c +++ b/fs/ocfs2/super.c @@ -952,8 +952,10 @@ static void ocfs2_disable_quotas(struct ocfs2_super *osb) for (type = 0; type < OCFS2_MAXQUOTAS; type++) { if (!sb_has_quota_loaded(sb, type)) continue; - oinfo = sb_dqinfo(sb, type)->dqi_priv; - cancel_delayed_work_sync(&oinfo->dqi_sync_work); + if (!sb_has_quota_suspended(sb, type)) { + oinfo = sb_dqinfo(sb, type)->dqi_priv; + cancel_delayed_work_sync(&oinfo->dqi_sync_work); + } inode = igrab(sb->s_dquot.files[type]); /* Turn off quotas. This will remove all dquot structures from * memory and so they will be automatically synced to global