From patchwork Mon May 22 10:24:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luis Henriques X-Patchwork-Id: 97238 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1341968vqo; Mon, 22 May 2023 03:28:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5t7A2hj7zSMj5cLQp07tHOEjQAxzEdEmVGN4WpIxIW6yaE80Z2ZaPqd3MGj3B/us21Acl3 X-Received: by 2002:a17:902:b78b:b0:1ac:85e9:3cab with SMTP id e11-20020a170902b78b00b001ac85e93cabmr11067783pls.56.1684751285153; Mon, 22 May 2023 03:28:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684751285; cv=none; d=google.com; s=arc-20160816; b=EMq5cwwS2Rdn/nIjpTHzMKgDiD6TDKr5KNLm6D1w3snqpXniDvmQ96o/8RCGP9MqRu vJfYt3xS5DradLUOwp2oTrkXsaXq9ttoXUPIDSV7Y/fh6FPFvu5uy6URlKI94s42KZ0Y 9VnKEGO0b1bEMfeQ2BP5y5C8PpJbavKdQ7WNMungcgWqfO5VdI7wxljj7cyGJgM4rnp0 UEtN716/0C98unNNWcx509WuhYWmWP0FI9PWveGpAyKPzY7ClJRZBamPxAwiBATo9UrS n4gTDuyX4YojsM53J1o49QF054h2ajl8SqKrDpTqWg7y6CdhBZd/rK5ZjyZ4mJvWiLih 62zA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=UWemZErlloMTCdVWorQ4/wn7rdudTuYoPoEblvyctGQ=; b=jHFcylNJyp0EcL1lpAginHFRGSRoxB7GPBY6KGDrK9m4j0+4RzflQdoxrkO/D2rsnm mNTThVYBXxbeXRCVhHP++yu5tr57tDI6ql1FMphgJvPsSzwrnG+4Hiwq4HgpTAp8UcKk w8aDEVc4/aen9tSpceZ0uPEGLpfzXBKXECrDhALTf9T4baXgxqq8WkiITFK4awWBXTO3 IcqJZ1miMnHk0tL2603p1i4nzvEua7jJHbUQO43Kj0oJA0FJRFzijtmdDH9gq5Qh5X+S mBy/V984I6qVaYY6Zy2jRQgiN9kUFMt6EqEudkt6Aw+VT7FkJgAck1fxHB93/Seafytv dt/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=QQTjL4QD; 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 iz11-20020a170902ef8b00b001a511254836si2177268plb.89.2023.05.22.03.27.52; Mon, 22 May 2023 03:28:05 -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=QQTjL4QD; 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 S232660AbjEVKZR (ORCPT + 99 others); Mon, 22 May 2023 06:25:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232018AbjEVKZH (ORCPT ); Mon, 22 May 2023 06:25:07 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91505D2 for ; 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-out2.suse.de (Postfix) with ESMTPS id 4C72A1FDFE; Mon, 22 May 2023 10:25:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684751103; 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=UWemZErlloMTCdVWorQ4/wn7rdudTuYoPoEblvyctGQ=; b=QQTjL4QDyHtniL9u0v5PF8UzTIRq7/2LV3NUcAlGu/utAasoDij+m+nFVURh1xBnqorVd8 ysZmNiYmRm9FS1NmCKPmtC3YG6qH2l+dNyEepXb+jjVvN93Sb/G9X2TvM0Kz87glOyh3iy HYwTSyTpxMk2fpUNei4hWJ7dVdxif5U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684751103; 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=UWemZErlloMTCdVWorQ4/wn7rdudTuYoPoEblvyctGQ=; b=wKRzbRx5iZD1HrstnU5oYyYMA/Ubp7dh32DxMCfkugTTSs1Zldo3NqmRwC7Vs/W4c6Flok P4Dku6mur3JKrECw== 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 D143F13776; 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 iJzYL/5Ca2TFEgAAMHmgww (envelope-from ); Mon, 22 May 2023 10:25:02 +0000 Received: from localhost (brahms.olymp [local]) by brahms.olymp (OpenSMTPD) with ESMTPA id 6dd15e18; Mon, 22 May 2023 10:25:00 +0000 (UTC) Date: Mon, 22 May 2023 11:24:34 +0100 From: =?iso-8859-1?q?Lu=EDs?= Henriques To: Mark Fasheh , Joel Becker , Joseph Qi Cc: ocfs2-devel@oss.oracle.com, linux-kernel@vger.kernel.org, =?iso-8859-1?q?Lu=EDs?= Henriques Subject: [PATCH] ocfs2: fix use-after-free when unmounting read-only filesystem Message-ID: MIME-Version: 1.0 Content-Disposition: inline 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?1766589763251925292?= 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(-) Cheers, -- Luís 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