Message ID | 20230522102506.9205-1-lhenriques@suse.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1342250vqo; Mon, 22 May 2023 03:28:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5RX9IRDyRzlOOzZ7/9DnYDg4ztLgnYp2rEOdQgbgcY6OrywO9/Hq+Y2yTrRQX1c8PXxkOv X-Received: by 2002:a05:6a00:10c1:b0:638:edbc:74ca with SMTP id d1-20020a056a0010c100b00638edbc74camr13939106pfu.0.1684751322220; Mon, 22 May 2023 03:28:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684751322; cv=none; d=google.com; s=arc-20160816; b=Y+4drymDDV68q3bo4sG7rA2M7C4TY4rx/U2xuJ+XtUgn0engWOKy9sUfd8h91FYH8o mCuIFY3jNk+lB+HmvOlwyHp+ysuP7GkSApQ3YEf/xDqSjLDpiNEUBYp2XHoLZ8DOb3AI aMRhsqmIioqpyFZ88b71vhrYisX2pP7Gi5XUw58Hjssd6xbZnCdleXE2HpnjoqlRvE22 +Chd5alj5xnZsIf/tMwt/SIvR2mFbwR3l5zQpfs33lb7DJIpko87LKYaqFP93K+9eaSW nPFvIYPB3Oa1Ib651tNV9Ihn+MmWaz0zrBTpJYns7Yrc4Rn0pKUe4zvU+JZWc2vv21u1 n8SA== 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=dK4c6jVfMYUnhpgqtCzFKqCJo27Q90EX9O3znFNrfJ8=; b=myHVS/64Fd9RhfvhBtVY4aSfpW1qNM3WNhnPFBIgURNx7xrGneDfiRciW0eNI0TCqh jidlZjv2zlu1csUigCQLiZaBpR7IOunUar248Os/ESKbbZXGHawV20ARWPt75OQZlOmv 0DDm/DfVK/e0tnp4qiMAUcxQijmeXq2fk24POHL0Ic6twYBbqTwYX1jQoG/10K5GE43q 33z+Sin/GoQI2xhzNAhz1VUcKkqharS64Ua7UqQMB0/d3BUPfERBJ4iPGXlGjDoXJGAp ERfs7iXS+cL6HVw6n5QSkYSQRp4tIRSsk+HW4kfF4DUxy3jSVyNm2CznoJmJ8/1as12k WraA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=wEBufNxl; 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 f7-20020aa79d87000000b0064caa26723bsi1265717pfq.318.2023.05.22.03.28.29; Mon, 22 May 2023 03:28:42 -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=wEBufNxl; 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 S232730AbjEVKZW (ORCPT <rfc822;cscallsign@gmail.com> + 99 others); Mon, 22 May 2023 06:25:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232554AbjEVKZM (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 22 May 2023 06:25:12 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E547E0; Mon, 22 May 2023 03:25:11 -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 E503321A35; Mon, 22 May 2023 10:25:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684751109; 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=dK4c6jVfMYUnhpgqtCzFKqCJo27Q90EX9O3znFNrfJ8=; b=wEBufNxlikTs6keMhFbzLqyvC+LK1HS76vxpZ2H8ggbtYTxUhfzHxMS0mzrxESky9yqZb2 Q5CvaAUuYK7zjXE/J7JpbYT/Gxy7KBiR0LHD+YKr4MIPhHgYlhpoaxa2vPPfEXI2uCPGry fevet/40ohb/eWLtuAcYffVLgr/tLOE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684751109; 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=dK4c6jVfMYUnhpgqtCzFKqCJo27Q90EX9O3znFNrfJ8=; b=+uD1Et6uHQ5IseYpE/pB3y5xzjN5jILiOJghc5Ccw1zTevgYKlW5ZAk9UMChPLLo2HhIH/ 90Sl0h6U0Z9vHZBQ== 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 65BE213776; Mon, 22 May 2023 10:25:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id aLiSFQVDa2TFEgAAMHmgww (envelope-from <lhenriques@suse.de>); Mon, 22 May 2023 10:25:09 +0000 Received: from localhost (brahms.olymp [local]) by brahms.olymp (OpenSMTPD) with ESMTPA id 4c24018e; Mon, 22 May 2023 10:25:08 +0000 (UTC) From: =?utf-8?q?Lu=C3=ADs_Henriques?= <lhenriques@suse.de> To: Mark Fasheh <mark@fasheh.com>, Joel Becker <jlbec@evilplan.org>, Joseph Qi <joseph.qi@linux.alibaba.com> Cc: ocfs2-devel@oss.oracle.com, linux-kernel@vger.kernel.org, =?utf-8?q?Lu?= =?utf-8?q?=C3=ADs_Henriques?= <lhenriques@suse.de>, stable@vger.kernel.org Subject: [PATCH] ocfs2: fix use-after-free when unmounting read-only filesystem Date: Mon, 22 May 2023 11:25:06 +0100 Message-Id: <20230522102506.9205-1-lhenriques@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766589763251925292?= X-GMAIL-MSGID: =?utf-8?q?1766589802606993428?= |
Series |
ocfs2: fix use-after-free when unmounting read-only filesystem
|
|
Commit Message
Luis Henriques
May 22, 2023, 10:25 a.m. UTC
It's trivial to trigger a use-after-free bug in the ocfs2 quotas code using
fstest generic/452. After mounting a filesystem as read-only, 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.
Cc: <stable@vger.kernel.org>
Signed-off-by: Luís Henriques <lhenriques@suse.de>
---
fs/ocfs2/super.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
Comments
On 5/22/23 6:25 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 mounting a filesystem as read-only, quotas are generic/452 is for testing ext4 mounted with dax and ro. But ocfs2 doesn't support dax yet. > 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. In ocfs2_fill_super(), it won't enable quota if is a readonly mount. Do you mean remount as readonly? Thanks, Joseph > > Cc: <stable@vger.kernel.org> > Signed-off-by: Luís Henriques <lhenriques@suse.de> > --- > 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
Joseph Qi <joseph.qi@linux.alibaba.com> writes: > On 5/22/23 6:25 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 mounting a filesystem as read-only, quotas are > > generic/452 is for testing ext4 mounted with dax and ro. > But ocfs2 doesn't support dax yet. Right, but I think it's still useful to run the 'generic' test-suite in a filesystem. We can always find issues in the test itself or, in this case, a bug in the filesystem. >> 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. > > In ocfs2_fill_super(), it won't enable quota if is a readonly mount. > Do you mean remount as readonly? Yes, sorry. Instead of "mounting", the patch changelog should say "After remounting a filesystem as read-only..." Cheers,
On Mon, May 22, 2023 at 01:23:07PM +0100, Luís Henriques wrote: > Joseph Qi <joseph.qi@linux.alibaba.com> writes: > > > On 5/22/23 6:25 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 mounting a filesystem as read-only, quotas are > > > > generic/452 is for testing ext4 mounted with dax and ro. > > But ocfs2 doesn't support dax yet. > > Right, but I think it's still useful to run the 'generic' test-suite in a > filesystem. We can always find issues in the test itself or, in this > case, a bug in the filesystem. It looks you did some special steps for 452. In my env, without changing anything, I could pass this case successfully. - Heming > > >> 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. > > > > In ocfs2_fill_super(), it won't enable quota if is a readonly mount. > > Do you mean remount as readonly? > > Yes, sorry. Instead of "mounting", the patch changelog should say > > "After remounting a filesystem as read-only..." > > Cheers, > -- > Luís > > > > > Thanks, > > Joseph > > > >> > >> Cc: <stable@vger.kernel.org> > >> Signed-off-by: Luís Henriques <lhenriques@suse.de> > >> --- > >> 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 >
Heming Zhao <heming.zhao@suse.com> writes: > On Mon, May 22, 2023 at 01:23:07PM +0100, Luís Henriques wrote: >> Joseph Qi <joseph.qi@linux.alibaba.com> writes: >> >> > On 5/22/23 6:25 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 mounting a filesystem as read-only, quotas are >> > >> > generic/452 is for testing ext4 mounted with dax and ro. >> > But ocfs2 doesn't support dax yet. >> >> Right, but I think it's still useful to run the 'generic' test-suite in a >> filesystem. We can always find issues in the test itself or, in this >> case, a bug in the filesystem. > > It looks you did some special steps for 452. In my env, without changing > anything, I could pass this case successfully. No, I haven't changed anything to the test. I just make sure there's a scratch device to be used. Maybe you can try to enable KASAN to catch the UAF. I've found the bug without KASAN (i.e. I saw a NULL pointer panic), but enabling it also detects the issue -- see below. Cheers,
On 5/22/23 8:23 PM, Luís Henriques wrote: > Joseph Qi <joseph.qi@linux.alibaba.com> writes: > >> On 5/22/23 6:25 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 mounting a filesystem as read-only, quotas are >> >> generic/452 is for testing ext4 mounted with dax and ro. >> But ocfs2 doesn't support dax yet. > > Right, but I think it's still useful to run the 'generic' test-suite in a > filesystem. We can always find issues in the test itself or, in this > case, a bug in the filesystem. > >>> 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. >> >> In ocfs2_fill_super(), it won't enable quota if is a readonly mount. >> Do you mean remount as readonly? > > Yes, sorry. Instead of "mounting", the patch changelog should say > > "After remounting a filesystem as read-only..." > > Cheers, Okay, look into the code flow, it does have problem when remount with read-only. BTW, it seems that we can't call into quota_disable() again, which will call free_file_info(). Thanks, Joseph
On 5/22/23 9:22 PM, Luís Henriques wrote: > Heming Zhao <heming.zhao@suse.com> writes: > >> On Mon, May 22, 2023 at 01:23:07PM +0100, Luís Henriques wrote: >>> Joseph Qi <joseph.qi@linux.alibaba.com> writes: >>> >>>> On 5/22/23 6:25 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 mounting a filesystem as read-only, quotas are >>>> >>>> generic/452 is for testing ext4 mounted with dax and ro. >>>> But ocfs2 doesn't support dax yet. >>> >>> Right, but I think it's still useful to run the 'generic' test-suite in a >>> filesystem. We can always find issues in the test itself or, in this >>> case, a bug in the filesystem. >> >> It looks you did some special steps for 452. In my env, without changing >> anything, I could pass this case successfully. > > No, I haven't changed anything to the test. I just make sure there's a > scratch device to be used. > > Maybe you can try to enable KASAN to catch the UAF. I've found the bug > without KASAN (i.e. I saw a NULL pointer panic), but enabling it also > detects the issue -- see below. > > Cheers, We'd better append panic dmesg to patch description as well. Thanks, Joseph
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