Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5205534rwd; Tue, 23 May 2023 20:45:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7V8yHcKytT2wPLM9u18mZ79Nx6EUOX2AZrJsC7q0MLLemTGgj4NE1V9N0/9Jq6MejZy9Ic X-Received: by 2002:a05:6a21:328e:b0:10c:edb:3e09 with SMTP id yt14-20020a056a21328e00b0010c0edb3e09mr7307228pzb.25.1684899947086; Tue, 23 May 2023 20:45:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684899947; cv=none; d=google.com; s=arc-20160816; b=xmMEQnFbFjW0I1IN63QevHWf7XubH+EVgEOadJLHJ2JxRhoR7KfoeNENJSUWV/c5qZ TJF1+CHvVUuaL10+d7U5zZV9cHqMQzs7pdAxtOjQ0IqJAMFfG4V4oyn+eH3d3xo51oW+ SLLnF1yJsvgOwzWYaybVuAbNbSKcz/8z1NmSBJf9tMLR1Cajx2+PMLttxHl5wxCiGMyr lm0lZas3t3nGhmy11qrjTpOJGb/8D3Ndx5B+5Pkm5JXB6EVeasvab+KlRa66Fy+kOsj+ BUbJ68g1O8uMG7CdAkw9VDBW+CPETLoWxgLnDRD2q3LDmWX/WcD9MldpelqUPtX7MPuj x0Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=GY7kawMT+HCq8XR1DQye/SfNM+so/SxMvmLN64nRRvE=; b=F5g/PWI1XlxadCJWb0+w0Hu+z8emPUq+sOjQtKlN07CBU2Jt7VftFDkdEVs8P03fXR 8bs0EygTULULEGRETeydOikHCNegpi1ZiSZMkbvKgq5Bel6z0+1B3eOLtKNYEwTl/CJz 4beSF4atPEkiZVkOe1Im2w3HN3LkHbR853K8zGqUTVmtTLxeMEd8f5OJt7d+Br5XcGp5 rzyramUXrFmxWdq2/ymi0xQnHNS2UDW6J5/h9O2nWPkhZzA9uYYL2EKKv1ozbXWKtPst fhBQaSI3Ct9DtkWmyv2NGSdu9w3NmDN1R2+MmSbcNcjIV+2WjUQG3oM333Eii4/9fB+l w/pA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e19-20020aa79813000000b0064f3917aedesi2597076pfl.176.2023.05.23.20.45.34; Tue, 23 May 2023 20:45:47 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238559AbjEXDih (ORCPT + 99 others); Tue, 23 May 2023 23:38:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234535AbjEXDif (ORCPT ); Tue, 23 May 2023 23:38:35 -0400 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C0B3BF for ; Tue, 23 May 2023 20:38:33 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R681e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046059;MF=joseph.qi@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0VjMPeag_1684899508; Received: from 30.221.130.24(mailfrom:joseph.qi@linux.alibaba.com fp:SMTPD_---0VjMPeag_1684899508) by smtp.aliyun-inc.com; Wed, 24 May 2023 11:38:29 +0800 Message-ID: Date: Wed, 24 May 2023 11:38:28 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH v2] ocfs2: fix use-after-free when unmounting read-only filesystem Content-Language: en-US To: =?UTF-8?Q?Lu=c3=ads_Henriques?= , Mark Fasheh , Joel Becker , Heming Zhao , akpm Cc: ocfs2-devel@oss.oracle.com, linux-kernel@vger.kernel.org References: <20230523093310.2628-1-lhenriques@suse.de> From: Joseph Qi In-Reply-To: <20230523093310.2628-1-lhenriques@suse.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL 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 On 5/23/23 5:33 PM, Luís Henriques wrote: > 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 Tested with following procedures: mkfs.ocfs2 -b 4k -C 1M -N 2 --fs-features=usrquota,grpquota /dev/vdc /etc/init.d/o2cb.init online ocfs2cluster mount.ocfs2 -o usrquota,grpquota /dev/vdc /mnt/ocfs2 mount.ocfs2 -o remount,ro,heartbeat=local /dev/vdc /mnt/ocfs2 umount /mnt/ocfs2 > --- > 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