Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3759496pxk; Tue, 29 Sep 2020 05:42:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyg7uv6y2dkVdFWk0ZsVCWaP59IqPeLuS2qSp2ID8U3clxfJpiC9h8ABgLSbfpbEh7vOblU X-Received: by 2002:a50:e79c:: with SMTP id b28mr3069166edn.371.1601383366350; Tue, 29 Sep 2020 05:42:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601383366; cv=none; d=google.com; s=arc-20160816; b=DDP6ZXW3DgU7Zdbizuh1bSPlBpHSyQM4cdewr0Xqm3pg+Rs11cBU05qtLTYGbU6QEQ s2McdsanfZ9m4SLB61FVWMfKSawrNk2/wY95/Td5a5UK6R2NQTpcnhSM2urGbaw8TVte qM6mr5VluQkIiuB+LkdmmXGUE/bvd5TpOUI/hH9WcZLuHy6Lv6x65COEjOhXZQ9oVoIw 3NHfUAxNfOGvc4bs3HeOsLY1YNPd9Xd0tE+dIRpkTZJaLjZ3p1n3MJYQjwIg1cmVNXcB gKqLxf6tqu8FcWjnmF6tPSwc4RG3tx8yB8Xxzz5s5V6NyCgzx67Jn+JRHMGgJrachpXz h7GQ== 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=6ZEsL7UjI/EQK1rxxGmkGdL5br0CXOw4e5Dtp+ZHSUQ=; b=VEnIIPX/B+leTw0lm5p86zZJhmY0ta85F0FYnoOzC+igJQmJsxwmZq3P8UsZOYaZCo hhAY8lluFInfOawjxxB7s+ZnFhADz3W0kdB135DAuHPwe5unHEX5m7rR5mb6FSsKXfXo aLyB0/e8WI0GOqfLazU8F5h+qN7ydskDMoXOusZczt54TcvQML7+MBVtO+w77Q17qmof CQngWalSKQidf+5UW2gadaNKt5sOc72K32p568IsvuZHNhnN2O29V6sGPrqZtbonUJx0 sfgILziBcOVIopqrM8kEvmO2tG7ZKYVTGEfb34FG3JEJ4KPrMgyHrwIhNWJt9D5m/eny cNGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="QwaGKZZ/"; 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 j26si348656edq.316.2020.09.29.05.42.23; Tue, 29 Sep 2020 05:42:46 -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="QwaGKZZ/"; 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 S1733308AbgI2MlQ (ORCPT + 99 others); Tue, 29 Sep 2020 08:41:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:56562 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729042AbgI2LN4 (ORCPT ); Tue, 29 Sep 2020 07:13:56 -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 C575B20848; Tue, 29 Sep 2020 11:13:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601378035; bh=/Ur/AHfdi2HwL9ObGWhbAWHLlQfDJ1kO2xqdU/FGjJ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QwaGKZZ/fq15ogAV8eY7RaI1ui+8IMIl98EpMCqMIxFfnrf7D+hmAa8HvuHjfGY+k T6Vt9yYQudwrcTLDg4xJwM0dKbWKyISXqJjmgGVx1596Te4bBtVHJSXeza9bZMniEQ QzahMq1azDvh4BpMfB4es0p1dfC9w8gzuBUPMBTU= 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 4.14 039/166] gfs2: clean up iopen glock mess in gfs2_create_inode Date: Tue, 29 Sep 2020 12:59:11 +0200 Message-Id: <20200929105937.158099758@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929105935.184737111@linuxfoundation.org> References: <20200929105935.184737111@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 6c6401084d3d8..e893b1fbde98b 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c @@ -714,7 +714,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; @@ -725,7 +725,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)); @@ -734,7 +734,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); @@ -767,6 +766,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) { *opened |= FILE_CREATED; error = finish_open(file, dentry, gfs2_open_common, opened); @@ -774,15 +775,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