From patchwork Mon May 22 10:20:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luis Henriques X-Patchwork-Id: 97239 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1341993vqo; Mon, 22 May 2023 03:28:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6b54ml1+olMTFaPUE3Aa4LLz4FF67iuTwlpApDBvphCiLDb+ADnhVP4fVTOvqJmCm1GyG1 X-Received: by 2002:a05:6a20:8e0b:b0:10a:cbe6:69ef with SMTP id y11-20020a056a208e0b00b0010acbe669efmr8666796pzj.37.1684751289845; Mon, 22 May 2023 03:28:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684751289; cv=none; d=google.com; s=arc-20160816; b=u3hCDyy6C6CX1J+zgWMJSfjici2wF5FuSSG4Z0vNx+gNpFE1PUO8UYzlapY1utduXL FP7QahMJwAGSoRZI8ZgrvxVczmhxJI0zvhjxa59qURIiwjX+3hQjUUKLLZChw/1pT2pg X415+zM1Kn11I2yVOVcakxm0V6qYO0e+N2WssI0RCzlCqytW4BHLvuk3FqSDo70pgHR6 cbvY97tll3MpyUKFZbGeiBnZ4MlgoFxd/bMFhbsjjQ3rlH0STQO2jEhW+xmxpcjO/MJS 1oFfpUXlz/83uBQ1greuIE4l4Mmhl/NPBVMHsNPrUULS4IuvbecDe4GlOSHlPwd11cm4 A8GA== 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=pc3582ZUIme9WMKpSDD8NE/WJtKHtPHXToCAiQuII3ywDBbd1YRBpHJGNatxsiOTiF wwTpQ9H4yNv0V+R6MdxIgoDaYeTioNp0b7+oSt4WnM4LTq72ixAZwOM2w0UiC8YsI+W0 aBveMg6BCrQPvCOgEmRq15gSNIHRyRoM6H3RdKaOkk9A9r1qAD044TG/sXysqbz2ZXjM Lu6+13GzzWH/KmxmN50OfKn0/I/wdZAwqVyJMRBpEVyQkVWxeAVz/fgYUEYCx8JFuqpe qQrpnDy/KDYlo7yY0Bs29rDXNAPFpFCuAygQwifPRxK3tWQcQFjQJ5Ss+b5WIGsgXSEI fhTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=Bvl8LjGn; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=A9h2RgHL; 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 r184-20020a632bc1000000b0052cad187979si4683608pgr.147.2023.05.22.03.27.57; Mon, 22 May 2023 03:28:09 -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=Bvl8LjGn; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=A9h2RgHL; 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 S232528AbjEVKZL (ORCPT + 99 others); Mon, 22 May 2023 06:25:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229890AbjEVKZG (ORCPT ); Mon, 22 May 2023 06:25:06 -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 13363C5; Mon, 22 May 2023 03:25:04 -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 BA96821A34; Mon, 22 May 2023 10:25:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684751102; 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=Bvl8LjGnDdob6XfTE0O/H11rB3dYKccwcJ6uyd1JafLCpggtrml9xk39xpSj5ItgyfMvqk SyYVP7qE0Tvvn3KG8D1vrmLZq24iIInCW/0TLuAbIbmBryVj/Vqn6olLR1nCesBdiXmb6G 2COYy4tGtMqgJ6uqg713Z2FLcqbWxJg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684751102; 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=A9h2RgHLuFWfdKBTk+jbIDMOJUsQzbr5CYAUmlsN7LI5ZoglaxpE8yLh4LJ1ApMCEObDHD pf0HpGp22yxlfuDA== 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 3C7EF13776; Mon, 22 May 2023 10:25:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 0PJ8C/5Ca2TFEgAAMHmgww (envelope-from ); Mon, 22 May 2023 10:25:02 +0000 Received: from localhost (brahms.olymp [local]) by brahms.olymp (OpenSMTPD) with ESMTPA id 00fa7886; Mon, 22 May 2023 10:25:00 +0000 (UTC) From: =?utf-8?q?Lu=C3=ADs_Henriques?= To: Mark Fasheh , Joel Becker , Joseph Qi Cc: ocfs2-devel@oss.oracle.com, linux-kernel@vger.kernel.org, =?utf-8?q?Lu?= =?utf-8?q?=C3=ADs_Henriques?= , stable@vger.kernel.org Subject: [PATCH] ocfs2: fix use-after-free when unmounting read-only filesystem Date: Mon, 22 May 2023 11:20:30 +0100 Message-Id: <20230522102030.8986-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 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?1766589763251925292?= X-GMAIL-MSGID: =?utf-8?q?1766589768203581682?= 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: Signed-off-by: Luís Henriques --- 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