From patchwork Fri Jul 12 01:26:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuxuan Luo X-Patchwork-Id: 1959639 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WKv7x0LDCz1xqc for ; Fri, 12 Jul 2024 11:26:36 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1sS53P-0000MS-9D; Fri, 12 Jul 2024 01:26:31 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1sS53L-0000Kw-FO for kernel-team@lists.ubuntu.com; Fri, 12 Jul 2024 01:26:27 +0000 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 4F58E3F169 for ; Fri, 12 Jul 2024 01:26:27 +0000 (UTC) Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-79efb1181ddso163494685a.1 for ; Thu, 11 Jul 2024 18:26:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720747586; x=1721352386; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TKKRcFgL77u3I52F8NZvlnVSZLQGO9RAzegIoR4uFXY=; b=TqD005U80i6A7iOjamw8Uhplu9wUj0BXNPjujvWWB0TWXypALXLvW5vbQEq62P60TL 6e/hI7c76BbruyZCS5FgSrcb7pSeHdbQOb/sgi8sLBy/ckPZM/JTgZ3v9IGcyn93e8T3 pkq5RlwZpGZwAu8kbbBiuH1GiadRN2Wx2WvuSwf6uzVUud+tdSbrm3sKLjrMUwp679K1 VETnX3NWw8FqdHWfcL4CtQRTPYz51wrTTeyWICDbhmQd45kX2rtJQOSTmyT/tfopSklJ MapJzJhhzz/GwwjnhlCpQlTx1qVAbfT3X2DSlhrHqwWDmcUd75KJOzx5Ap/hDz5+m9Hd QBiA== X-Gm-Message-State: AOJu0Yyuev6NlLDet9wdznxmUkHTtPZIkK3zVV3czw/fX6GjTEYU4NIM fCgc6lWPytWzvs8zO6/i9fXZhOc8gFzD47RNRvt7hIr4UoYuX5mGz4iSC7vCvNaYdS9dub8pPkG y6cktEwy2JDmBlvam1CNWxqciUXGyEho5bJMCnLX0dPnUxHBGyVy5XcYsRIS9DhMQgUMkfsiObD 98K6f1R7MbEw== X-Received: by 2002:a05:620a:1aa4:b0:79d:76c3:5300 with SMTP id af79cd13be357-79f199e5cfbmr1394374885a.15.1720747585759; Thu, 11 Jul 2024 18:26:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH7pmEz9Kr1ZGNw1+C2JC2H1MyFZ8ZCiBJJX+YoGtmZONs3FE3dtyQbLY8c2OFJJLs13cdMwQ== X-Received: by 2002:a05:620a:1aa4:b0:79d:76c3:5300 with SMTP id af79cd13be357-79f199e5cfbmr1394372985a.15.1720747585317; Thu, 11 Jul 2024 18:26:25 -0700 (PDT) Received: from cache-ubuntu.hsd1.nj.comcast.net ([2001:67c:1562:8007::aac:4795]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-447f9b26c9dsm35633861cf.14.2024.07.11.18.26.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 18:26:24 -0700 (PDT) From: Yuxuan Luo To: kernel-team@lists.ubuntu.com Subject: [F][PATCH v2 1/1] gfs2: Fix slab-use-after-free in gfs2_qd_dealloc Date: Thu, 11 Jul 2024 21:26:21 -0400 Message-Id: <20240712012622.2234811-2-yuxuan.luo@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240712012622.2234811-1-yuxuan.luo@canonical.com> References: <20240712012622.2234811-1-yuxuan.luo@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Juntong Deng In gfs2_put_super(), whether withdrawn or not, the quota should be cleaned up by gfs2_quota_cleanup(). Otherwise, struct gfs2_sbd will be freed before gfs2_qd_dealloc (rcu callback) has run for all gfs2_quota_data objects, resulting in use-after-free. Also, gfs2_destroy_threads() and gfs2_quota_cleanup() is already called by gfs2_make_fs_ro(), so in gfs2_put_super(), after calling gfs2_make_fs_ro(), there is no need to call them again. Reported-by: syzbot+29c47e9e51895928698c@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=29c47e9e51895928698c Signed-off-by: Juntong Deng Signed-off-by: Andreas Gruenbacher (backported from commit bdcb8aa434c6d36b5c215d02a9ef07551be25a37) [yuxuan.luo: The fix commit, bdcb8aa434c6 ("gfs2: Fix slab-use-after-free in gfs2_qd_dealloc"), addresses two problems: 1) UAF caused by gfs2_quota_cleanup() not called if not already withdrawn "[otherwise], struct gfs2_sbd will be freed before gfs2_qd_dealloc (rcu callback) has run for all gfs2_quota_data objects". 2) Double-free by calling gfs2_quota_cleanup() twice if in not read-only mode. The second issue is introduced by f66af88e3321 ("gfs2: Stop using gfs2_make_fs_ro for withdraw") and not affecting this kernel while the first one does. To solve the first one, only call the gfs2_quota_cleanup() if the gfs2_make_fs_ro() is not called since gfs2_make_fs_ro() calls gfs2_quota_cleanup() as well. ] CVE-2023-52760 Signed-off-by: Yuxuan Luo --- fs/gfs2/super.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index 15e757f763806..09bb630185952 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -662,6 +662,8 @@ static void gfs2_put_super(struct super_block *sb) error = gfs2_make_fs_ro(sdp); if (error) gfs2_io_error(sdp); + } else { + gfs2_quota_cleanup(sdp); } /* At this point, we're through modifying the disk */