Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3742926pxk; Tue, 29 Sep 2020 05:18:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFbbAtfe+NTfeThKXc5OhK+pp19A5HO8blzx/Krxl6/WcC31PZoS+UHC3MdSp+9WcFD/8i X-Received: by 2002:aa7:c545:: with SMTP id s5mr2944801edr.10.1601381881423; Tue, 29 Sep 2020 05:18:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601381881; cv=none; d=google.com; s=arc-20160816; b=cLz7qM3wegFUWi4JkDUKqSNQctw+RsasExPK2pRXwcVqEXTco+tjKoRbg1oWoCIBUB I6pfkyR6JMZSBlUg9S5/Lz65FmnhyrvXZa/GWTdHsnZMPQsGo6wiIOOK0aazglB1GJ94 W12NApJABEeqZHJYeohhb1w6cCS/voQI1N4PCH8D+OghwXpf7rpoqYcuhhlezGIyTMgE JDKa9JAWZFOa+lDveGxEdCyKeo+riNZo/jDvUpMSiNMpVUBp4btUevov9KlHhpyigaYh 1KM5EnmzIP5c9G9in+HNZ8zBEt1XzVvZIFK7py1VD5M8XW793lLmDbn9dJIYveExMs1H uO4g== 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=ow8zvbd0/K3PpMq5043ROku0CYyRijnphYcZLTgRYQ0=; b=g9phpAa6+rgR+i6yPSnDFL255cCwsuTNooWuhT3e9+mKpuvHD1TCnxRG0K7Smv181p Cv4gQdiM41RmrWkbCKl9oUoW6dYUXTerpkQ2eUtpkZW856wlDRFuabi+Ux7gXZ/Fcrnw 71fS98Cq0iOjQH7QVDC5AWOeEAMMAJHosNhj3PJLY6gOcVo3gV5xOjFnsah0TvcVviS3 KP4u/fm7MW6hQOr8kcPIUFbcrm+RGesfrwqbaVkZzG6k2i6CyuX52A8m/Ee6uPNGFALZ VZkQCvHNA1JbexkvUdYLgqMIVtKR4Wmm7KTnJO6JnYmwiySsW+tuQ3s+1MBvn8EmV9ms IJzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Flgxldrc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v15si2725544ede.489.2020.09.29.05.17.37; Tue, 29 Sep 2020 05:18:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Flgxldrc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732103AbgI2MOm (ORCPT + 99 others); Tue, 29 Sep 2020 08:14:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:53444 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730085AbgI2Lh2 (ORCPT ); Tue, 29 Sep 2020 07:37:28 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4361D2311C; Tue, 29 Sep 2020 11:33:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601379194; bh=OLESydZQ4gmgfkoqbmc/SAbiZeY7XhikeW9o0UcETjA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FlgxldrcCTYllZVgJVGwZR5qRM/+b6ux07LycuCg6MRsA+egERIUFK/i6Ue9Mq0LY XsNoensKrVw2d/LvoK7qzTbefY5RacIVlFEGZScHrj3tXhtb872qYfpAEAjMuNWU5X CiNVvWWI8c52963slw4k33k0aqfagCIqPx1TrcMY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bob Peterson , Andreas Gruenbacher , Sasha Levin Subject: [PATCH 5.4 053/388] gfs2: clean up iopen glock mess in gfs2_create_inode Date: Tue, 29 Sep 2020 12:56:24 +0200 Message-Id: <20200929110013.062556528@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929110010.467764689@linuxfoundation.org> References: <20200929110010.467764689@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bob Peterson [ Upstream commit 2c47c1be51fbded1f7baa2ceaed90f97932f79be ] Before this patch, gfs2_create_inode had a use-after-free for the iopen glock in some error paths because it did this: gfs2_glock_put(io_gl); fail_gunlock2: if (io_gl) clear_bit(GLF_INODE_CREATING, &io_gl->gl_flags); In some cases, the io_gl was used for create and only had one reference, so the glock might be freed before the clear_bit(). This patch tries to straighten it out by only jumping to the error paths where iopen is properly set, and moving the gfs2_glock_put after the clear_bit. Signed-off-by: Bob Peterson Signed-off-by: Andreas Gruenbacher Signed-off-by: Sasha Levin --- fs/gfs2/inode.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 8466166f22e3d..988bb7b17ed8f 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -712,7 +712,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry, error = gfs2_trans_begin(sdp, blocks, 0); if (error) - goto fail_gunlock2; + goto fail_free_inode; if (blocks > 1) { ip->i_eattr = ip->i_no_addr + 1; @@ -723,7 +723,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry, error = gfs2_glock_get(sdp, ip->i_no_addr, &gfs2_iopen_glops, CREATE, &io_gl); if (error) - goto fail_gunlock2; + goto fail_free_inode; BUG_ON(test_and_set_bit(GLF_INODE_CREATING, &io_gl->gl_flags)); @@ -732,7 +732,6 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry, goto fail_gunlock2; glock_set_object(ip->i_iopen_gh.gh_gl, ip); - gfs2_glock_put(io_gl); gfs2_set_iop(inode); insert_inode_hash(inode); @@ -765,6 +764,8 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry, mark_inode_dirty(inode); d_instantiate(dentry, inode); + /* After instantiate, errors should result in evict which will destroy + * both inode and iopen glocks properly. */ if (file) { file->f_mode |= FMODE_CREATED; error = finish_open(file, dentry, gfs2_open_common); @@ -772,15 +773,15 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry, gfs2_glock_dq_uninit(ghs); gfs2_glock_dq_uninit(ghs + 1); clear_bit(GLF_INODE_CREATING, &io_gl->gl_flags); + gfs2_glock_put(io_gl); return error; fail_gunlock3: glock_clear_object(io_gl, ip); gfs2_glock_dq_uninit(&ip->i_iopen_gh); - gfs2_glock_put(io_gl); fail_gunlock2: - if (io_gl) - clear_bit(GLF_INODE_CREATING, &io_gl->gl_flags); + clear_bit(GLF_INODE_CREATING, &io_gl->gl_flags); + gfs2_glock_put(io_gl); fail_free_inode: if (ip->i_gl) { glock_clear_object(ip->i_gl, ip); -- 2.25.1