Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2724557rwd; Mon, 22 May 2023 03:28:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4kTB1f7JW8pv76IwxyfYscJFshHU298e9IZFHNDS7pU/kKa8zBPXPRcMcVrrrgxiqWTnxI X-Received: by 2002:a05:6a00:c88:b0:639:a518:3842 with SMTP id a8-20020a056a000c8800b00639a5183842mr15891640pfv.7.1684751296217; Mon, 22 May 2023 03:28:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684751296; cv=none; d=google.com; s=arc-20160816; b=hlcUGxkui+OLdP+Foq9vsYOiSCz5AixZJrMrTGwtHH+5SKp8t+RTPjsmRYn3PWVJeU eahwFjkn9/UgVjL5L/lO12wYjpvwtDQScFBJmHLUi/RYZnXJ/5Y5JO2Bv+QbysSZTJhr +wI2muwIkD9RWpGKi2prV3UHUCHBnUL4H1rrHOZPysxLDDnmex/CB5LmTIESKTHDJo4w EbakJVdGx0IpfJSpxyHvMMoo4d2JVj07Xqg81IqhunDf24NZhVw5paNZ7VYbfiS9p6ad 9C2R5oXlF/xEn+dhVWxD93cozSLOTStaScakSjM7wsp7T7RMCQTDE3E24dkKQ7MTp/J3 sP/g== 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=B8gTN4GLSEy/NbGKEiNoFjsoyzuU77c/yflVyECgeHAOvWqIRredldQFe/5cRZ855M RV59hbzHyYxlagLTe4oNhhK1Ct7P68XMJYnwyAxFCAtkTflO0mVg3x9Oej3wwt2RW3lB cqgbMX4K75ZsZlcy7CFhbet26xeO8Boxxw+g9B1ZkPxy5QaIW6RM9MA58QbKvMc+rTpV mz9G2y44K7oTgggOFzJkkd31uoJATGZCIksLSX5AqTUd/7NBBuyyjU5ZgJdDvZnp9czr 1J95KsitIxTsmu9TD+AW4MYxCcll7HtQmJyl9zrAqsHt2XhSI+aWON+jr5B9CuzN9T72 PLAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=RUIDfgjG; dkim=neutral (no key) header.i=@suse.de; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w29-20020a63af1d000000b005348cc20de6si4611729pge.851.2023.05.22.03.28.03; Mon, 22 May 2023 03:28:16 -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=RUIDfgjG; dkim=neutral (no key) header.i=@suse.de; 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 S230313AbjEVKZH (ORCPT + 99 others); Mon, 22 May 2023 06:25:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229518AbjEVKZF (ORCPT ); Mon, 22 May 2023 06:25:05 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 790B2A0; Mon, 22 May 2023 03:25:03 -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-out2.suse.de (Postfix) with ESMTPS id 30D391FDFD; 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=RUIDfgjGdB4roKiq70eIUUi4e42W+sJEtM6HEElpYci2XV8365hLC9TaGOzbzgp6oaoA3/ mhYqHF2tnmdf1CrQvjo0TCC3Mlg9tE89h7KFtRWK214d+gsULzaVbUbmaE0kR4OgAfC1gQ omSr7NgcELAvIlk0N470BHg4DsVmGds= 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=Prfnr9peCZaBiM7Mx6W9w43JlGHOIAF9CKFEufQgAMYetD0nyeDCAD69Ng0HaY+NjRmp/6 2JKKMbKSywdc96AQ== 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 994D813776; Mon, 22 May 2023 10:25:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ECE3Iv1Ca2TFEgAAMHmgww (envelope-from ); Mon, 22 May 2023 10:25:01 +0000 Received: from localhost (brahms.olymp [local]) by brahms.olymp (OpenSMTPD) with ESMTPA id b8cd2673; Mon, 22 May 2023 10:25:00 +0000 (UTC) From: =?UTF-8?q?Lu=C3=ADs=20Henriques?= To: Mark Fasheh , Joel Becker , Joseph Qi Cc: ocfs2-devel@oss.oracle.com, linux-kernel@vger.kernel.org, =?UTF-8?q?Lu=C3=ADs=20Henriques?= , stable@vger.kernel.org Subject: [PATCH] ocfs2: fix use-after-free when unmounting read-only filesystem Date: Mon, 22 May 2023 11:21:12 +0100 Message-Id: <20230522102112.9031-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: X-Mailing-List: linux-kernel@vger.kernel.org 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