From patchwork Tue Oct 8 20:18:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Massimiliano Pellizzer X-Patchwork-Id: 1994417 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 4XNS606Bv9z1xvT for ; Wed, 9 Oct 2024 07:19:04 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1syGfX-0008SX-Bz; Tue, 08 Oct 2024 20:18:55 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1syGfV-0008S5-IQ for kernel-team@lists.ubuntu.com; Tue, 08 Oct 2024 20:18:53 +0000 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (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-1.canonical.com (Postfix) with ESMTPS id 4F78F3F2F1 for ; Tue, 8 Oct 2024 20:18:53 +0000 (UTC) Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a994cd8089aso238294266b.2 for ; Tue, 08 Oct 2024 13:18:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728418732; x=1729023532; 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=kUKwzrUvkaWlptheegDnJmeoZxX3ixFj+ifjaoaYHKM=; b=hX5M5PCduMD4zjoA9dkhhyS1sacMw4w2urHMaFG1/ObIOjJ75pRMWhhNSMG9uKCqn9 xZCWCVyCp/F8P0ZcY++OGyO3nEkpFWXXCXizSug/hIbLQqYWP4q43bXVwdTW4AL+LFba SLUerlnyvKDrzKEs3lV7JcCDAVHhuEcactO2dGhsLnuntQ5TZvb18HfueU5K5jXHz9RU mTLZfRYGWztg4I4DYbgoDKloqug6mcLaz8J6RiDg4mUczIAWgeIBICARHVqKGqffDyqq q+negrsxqshqCxrZzQddHUF6Mx9rAQNgwi6WCE3ekkO2uArxqjGP/o+20BqTLjNh5oAM CmUg== X-Gm-Message-State: AOJu0YzFlTsNU5SdLKpvdnmDrvkqv0zNs5YdcfG2joZEBrIW8g57Umkw ocEaYgVpcvs8DsFg9i0KXex3b5DT9IL2Xr4bD3dZEJaO6BYysFaBBvxE9TJi3UxSVLt/JY53N3L jp1plM0vWnW3TnxSQn5zTmpAzWQBxLxaBOep5NeJaPaSk9De41I/um2jFCaHuOwOYZIvl5iWpjE QkskSEkA3W5Q== X-Received: by 2002:a17:907:7289:b0:a99:5ad9:b672 with SMTP id a640c23a62f3a-a998d11f816mr238466b.10.1728418732545; Tue, 08 Oct 2024 13:18:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHhvn3IVBG5Sywl1DpG/a39z9egn+hHEOcm1EpQU9n9oskA91CoVyUIjNbB2nG1nciTtuD7hQ== X-Received: by 2002:a17:907:7289:b0:a99:5ad9:b672 with SMTP id a640c23a62f3a-a998d11f816mr237066b.10.1728418732087; Tue, 08 Oct 2024 13:18:52 -0700 (PDT) Received: from localhost.localdomain (net-93-66-98-69.cust.vodafonedsl.it. [93.66.98.69]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a994a1464a1sm402722066b.106.2024.10.08.13.18.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2024 13:18:51 -0700 (PDT) From: Massimiliano Pellizzer To: kernel-team@lists.ubuntu.com Subject: [SRU][J][PATCH 1/1] gfs2: Fix NULL pointer dereference in gfs2_log_flush Date: Tue, 8 Oct 2024 22:18:11 +0200 Message-ID: <20241008201811.72174-2-massimiliano.pellizzer@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241008201811.72174-1-massimiliano.pellizzer@canonical.com> References: <20241008201811.72174-1-massimiliano.pellizzer@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: Andreas Gruenbacher [ Upstream commit 35264909e9d1973ab9aaa2a1b07cda70f12bb828 ] In gfs2_jindex_free(), set sdp->sd_jdesc to NULL under the log flush lock to provide exclusion against gfs2_log_flush(). In gfs2_log_flush(), check if sdp->sd_jdesc is non-NULL before dereferencing it. Otherwise, we could run into a NULL pointer dereference when outstanding glock work races with an unmount (glock_work_func -> run_queue -> do_xmote -> inode_go_sync -> gfs2_log_flush). Signed-off-by: Andreas Gruenbacher Signed-off-by: Sasha Levin (backported from commit 3429ef5f50909cee9e498c50f0c499b9397116ce linux-6.6.y) [mpellizzer: backported solving merge conflicts due to surrounding instructions which do not affect the patch] CVE-2024-42079 Signed-off-by: Massimiliano Pellizzer --- fs/gfs2/log.c | 3 ++- fs/gfs2/super.c | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 9a96842aeab3..e7867b0f6c62 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -1094,7 +1094,8 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags) lops_before_commit(sdp, tr); if (gfs2_withdrawn(sdp)) goto out_withdraw; - gfs2_log_submit_bio(&sdp->sd_jdesc->jd_log_bio, REQ_OP_WRITE); + if (sdp->sd_jdesc) + gfs2_log_submit_bio(&sdp->sd_jdesc->jd_log_bio, REQ_OP_WRITE); if (gfs2_withdrawn(sdp)) goto out_withdraw; diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index 7fcdb1d7396e..637a8c74a5a1 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -67,9 +67,13 @@ void gfs2_jindex_free(struct gfs2_sbd *sdp) sdp->sd_journals = 0; spin_unlock(&sdp->sd_jindex_spin); + down_write(&sdp->sd_log_flush_lock); sdp->sd_jdesc = NULL; + up_write(&sdp->sd_log_flush_lock); + while (!list_empty(&list)) { jd = list_first_entry(&list, struct gfs2_jdesc, jd_list); + BUG_ON(jd->jd_log_bio); gfs2_free_journal_extents(jd); list_del(&jd->jd_list); iput(jd->jd_inode);