Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4029477ioa; Tue, 26 Apr 2022 15:16:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9N6pFMpIx0xk3FPL8ZctDxMoMQxOygWejfp9uB0e57TGMCIF0WNC5rR0jqDQRVbFodoid X-Received: by 2002:a05:6402:1941:b0:413:2b7e:676e with SMTP id f1-20020a056402194100b004132b7e676emr27665272edz.114.1651011412576; Tue, 26 Apr 2022 15:16:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651011412; cv=none; d=google.com; s=arc-20160816; b=ceaP1DDlgspdXR5sfj/XTSe8Yd1SbkB91FKa1HUaghXgnHtgrwR+DKA6qsXv/71z/g b0eplFySfmiq4ve53bmdZwr2/xi6B64WUqNwfaTB7CX7abWgfJBJfEhSG1kzhiy4ungv 2U5HZmXGf6mY/QrImO3ncdRUMGBtjd2cx6655BeqSWapcNupPD1KfTwpoVIfL/RksYzo B1LsUw8Bft1pSWilfJBBllMKtZgRfqi1UFXHNigDQnquhPTP31uU9AXFY7qPzrNAtiBQ vVfnKKH4SXq9mqJ3c+aXjchez5QNt0JT10qz+AtAqDSoXYkPQNZg2Qmrx2RV2VcZmvSJ wBWw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZmDy0MsCYVfY/J14zpuVfnZLIdX/xK7hl4QXkegllEk=; b=CljLhx8nSUUTiK4I08h7FSojGkkQbiuQN17V9eCehIjSa5T7cdouSNCUHLFnL1/K7R +zDIsP6X55CrVx21u7iK+mYjoAutOGHmH/haVbOBjsGevB8a2hT/fmqqJ2C73/24xM14 hHFXFOlsGazE2tgHZkXOCeuUBwvdNMfwvXDtgM8Q6utLpL6NBK9wVANo8/glsFE2DeMC qHEkAmBjhaQYyTjeVXdUM9wkIGzy++vwAWlv+Kielt1Nv8DwzW9CdQOsEgFm994ZA6Oo LHVUpPWLbPjAxFuyBSF1C2ff41tjRVYIYNYaUA1v0ENiLoVi3aPCvOLpX2PyfmjTZx7o PdyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TCtTMfd8; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t2-20020a170906a10200b006df76385bafsi16457227ejy.79.2022.04.26.15.16.25; Tue, 26 Apr 2022 15:16:52 -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=@linuxfoundation.org header.s=korg header.b=TCtTMfd8; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346426AbiDZJAg (ORCPT + 99 others); Tue, 26 Apr 2022 05:00:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346891AbiDZIp2 (ORCPT ); Tue, 26 Apr 2022 04:45:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90F3965DC; Tue, 26 Apr 2022 01:36:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2D440617E7; Tue, 26 Apr 2022 08:36:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 236A3C385A0; Tue, 26 Apr 2022 08:36:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650962177; bh=F9IihVuh+cy8kK9Rt7DkAAR8plTl6SHz8WpoM3/HKzM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TCtTMfd8qH6Mry8nL+vY/wtzFxiPsiHk3BdqPgBZ8esHQRFJlMzCDIKeOMENTydZv 12ZQCNsyqSsc6WTjSHf3wSDOP1Yg5h5zaiiPAbyeXE1cJFHF+pWSWzQgUA55NCnN4A OPf/ZrT/jCfH14NChINhb3Jb8o0H7/yMyNxhKTk4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+c6fd14145e2f62ca0784@syzkaller.appspotmail.com, Bob Peterson , Andreas Gruenbacher Subject: [PATCH 5.15 012/124] gfs2: assign rgrp glock before compute_bitstructs Date: Tue, 26 Apr 2022 10:20:13 +0200 Message-Id: <20220426081747.648707539@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220426081747.286685339@linuxfoundation.org> References: <20220426081747.286685339@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 From: Bob Peterson commit 428f651cb80b227af47fc302e4931791f2fb4741 upstream. Before this patch, function read_rindex_entry called compute_bitstructs before it allocated a glock for the rgrp. But if compute_bitstructs found a problem with the rgrp, it called gfs2_consist_rgrpd, and that called gfs2_dump_glock for rgd->rd_gl which had not yet been assigned. read_rindex_entry compute_bitstructs gfs2_consist_rgrpd gfs2_dump_glock <---------rgd->rd_gl was not set. This patch changes read_rindex_entry so it assigns an rgrp glock before calling compute_bitstructs so gfs2_dump_glock does not reference an unassigned pointer. If an error is discovered, the glock must also be put, so a new goto and label were added. Reported-by: syzbot+c6fd14145e2f62ca0784@syzkaller.appspotmail.com Signed-off-by: Bob Peterson Signed-off-by: Andreas Gruenbacher Signed-off-by: Greg Kroah-Hartman --- fs/gfs2/rgrp.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -923,15 +923,15 @@ static int read_rindex_entry(struct gfs2 spin_lock_init(&rgd->rd_rsspin); mutex_init(&rgd->rd_mutex); - error = compute_bitstructs(rgd); - if (error) - goto fail; - error = gfs2_glock_get(sdp, rgd->rd_addr, &gfs2_rgrp_glops, CREATE, &rgd->rd_gl); if (error) goto fail; + error = compute_bitstructs(rgd); + if (error) + goto fail_glock; + rgd->rd_rgl = (struct gfs2_rgrp_lvb *)rgd->rd_gl->gl_lksb.sb_lvbptr; rgd->rd_flags &= ~(GFS2_RDF_UPTODATE | GFS2_RDF_PREFERRED); if (rgd->rd_data > sdp->sd_max_rg_data) @@ -945,6 +945,7 @@ static int read_rindex_entry(struct gfs2 } error = 0; /* someone else read in the rgrp; free it and ignore it */ +fail_glock: gfs2_glock_put(rgd->rd_gl); fail: