From patchwork Fri Jul 12 01:26:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuxuan Luo X-Patchwork-Id: 1959638 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 4WKv7v3Twbz20MX for ; Fri, 12 Jul 2024 11:26:35 +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 1sS53O-0000LX-2T; Fri, 12 Jul 2024 01:26:30 +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 1sS53M-0000L3-DO for kernel-team@lists.ubuntu.com; Fri, 12 Jul 2024 01:26:28 +0000 Received: from mail-yw1-f197.google.com (mail-yw1-f197.google.com [209.85.128.197]) (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 419F13F169 for ; Fri, 12 Jul 2024 01:26:28 +0000 (UTC) Received: by mail-yw1-f197.google.com with SMTP id 00721157ae682-6522c6e5ed9so29900627b3.0 for ; Thu, 11 Jul 2024 18:26:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720747587; x=1721352387; 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=AoDXf8altNwhcb1V9SM1zccNBxTg0MuEkVnRjhq99As=; b=nWp/+ojilojyFKMIHd37/BKfZLhO1pJo9LzWf2s8X5Ey6hUNwt071+yyj1v5mDZIce EmSlG5wmZ0wKlzeynscK868piXBPStSWDfy6cPXJKrtZBXIbrNTNbGXbfrkWE86OU7HE sF/PKYdmi0usudl5sugL8IbdQvm4KxzDkC/UsMAGd8qkLAnzcxxo1h2D0LPTsGNr7Hvd jCMapaHPVhc6Dmk6IL6a6vszq/oWTmkc9WKlxUZuqho4/fPKkwpYbtWvslIVhoJ9kZgk XUZ39re/kvXqYcD3VQbGvcdhVmyVxjNtU4bLZKhkqUsI7/NHyb3Z/+KBcUOfTytwW3hL icoQ== X-Gm-Message-State: AOJu0YxcZTnzOM94g0v+Z3Hp7qDvWvyV4S6bBp9/De/mBWUjqDGrTYMH qtfVl0RT5OhixZ28XQ5v5aBhpryfnzaq1ISV0uqCFSn8TblQNAKkSfn7OGaFZGloFBPUsAayFN1 E/yzPsswkzlndiv+eAXokmOLhMVsReUjsO6OOhNqWSQqBK0wqeCzmaJappLMzMuTPKvU0/auUwS HrrZ/HElGaaA== X-Received: by 2002:a05:690c:dd3:b0:62f:b04c:2442 with SMTP id 00721157ae682-658ee7912d5mr126861287b3.7.1720747586810; Thu, 11 Jul 2024 18:26:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH83HmOXG6naM3sPVQlJtVHG5bEYfD0pKGTsypxN/YOkedKPMQC1Dv/hnGLfQoUSInhq0qH8A== X-Received: by 2002:a05:690c:dd3:b0:62f:b04c:2442 with SMTP id 00721157ae682-658ee7912d5mr126861027b3.7.1720747586381; Thu, 11 Jul 2024 18:26:26 -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.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 18:26:25 -0700 (PDT) From: Yuxuan Luo To: kernel-team@lists.ubuntu.com Subject: [J][PATCH v2 1/1] gfs2: Fix slab-use-after-free in gfs2_qd_dealloc Date: Thu, 11 Jul 2024 21:26:22 -0400 Message-Id: <20240712012622.2234811-3-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 268651ac9fc84..98158559893f4 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -590,6 +590,8 @@ static void gfs2_put_super(struct super_block *sb) if (!sb_rdonly(sb)) { gfs2_make_fs_ro(sdp); + } else { + gfs2_quota_cleanup(sdp); } WARN_ON(gfs2_withdrawing(sdp));