Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1776649imm; Thu, 27 Sep 2018 02:16:50 -0700 (PDT) X-Google-Smtp-Source: ACcGV60+sY6Fr++sOZgDQ3LMuBL61jhuR6/3RHQm23rYEc4bcw8h4Xmz5n6J/tCLM97MwrMJZNVm X-Received: by 2002:a63:d84a:: with SMTP id k10-v6mr35901pgj.314.1538039810126; Thu, 27 Sep 2018 02:16:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538039810; cv=none; d=google.com; s=arc-20160816; b=KAQtKn9+lDknB1YbxSV1oczrv4m/IfB+dyuGsksdkC8oE2ereFUDeUrPKsgXuFruT8 4uSQukMj/1VuNXD9qENvpSeUpvEDJfYkhBadens72rJss1S+cTWI3srGQYAu5hrnhrKc lIkDOMb/sYA0sBXUJZtdbeVx8sSVx/ZtGA1kq9MJycA5Uhu6wJA+wXHZpsPVEJlCdzeI 8mXUawtM9gyG12VQvmWS6Q87lhRPnXa76xbNjUq/MjQv5omj1rY6SCyzSDfP/8VCX0xd 8xb07ibNirEh+p4UBkc8vh3UKRynvHhYEf0pU3ZnTldYIRWlVgCUXilljK7cYedpic7o gaUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=AFB6q0L+vT7Ogqkiw1yacA8p/QyadFnV7WIt7lVHrFA=; b=zoweiinX5OvVSV1x9iZmhwY3Q4ZZ+dyiPKadyczAPQRaW3UVH2bOjux36d7uTiLAEI wj+54yGG+eYEOr5dWjbEGYEa2HbghZlcy1NKsxuTphYdVyPSQlO3r2lDYCO7oK8WqgQE 4rWMnuphuwEuR4vAUrqUEN0DIhax+XcyDLAU16gsGtgD3HZYf62j1abLnOQI62/8bqc2 qnt316uDrugxHVH02WkBnugNcr73Oat3LzFQxC20UYnJK0wV37OQJBPGuauBO8JWUMoA c2HfN9WZruBnKxGJs06+NYFpc1Byiyuz19hhn82QrE7v8NtJKby+A+ceCr3mCaMr7KCW 5HZA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q15-v6si1611620pfj.260.2018.09.27.02.16.34; Thu, 27 Sep 2018 02:16:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727368AbeI0Pbh (ORCPT + 99 others); Thu, 27 Sep 2018 11:31:37 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:55510 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726991AbeI0Pbh (ORCPT ); Thu, 27 Sep 2018 11:31:37 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 857CB1117; Thu, 27 Sep 2018 09:14:20 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso , Wen Xu Subject: [PATCH 4.18 76/88] ext4: check to make sure the rename(2)s destination is not freed Date: Thu, 27 Sep 2018 11:03:57 +0200 Message-Id: <20180927090309.838008301@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180927090300.631426620@linuxfoundation.org> References: <20180927090300.631426620@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Theodore Ts'o commit b50282f3241acee880514212d88b6049fb5039c8 upstream. If the destination of the rename(2) system call exists, the inode's link count (i_nlinks) must be non-zero. If it is, the inode can end up on the orphan list prematurely, leading to all sorts of hilarity, including a use-after-free. https://bugzilla.kernel.org/show_bug.cgi?id=200931 Signed-off-by: Theodore Ts'o Reported-by: Wen Xu Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/ext4/namei.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -3478,6 +3478,12 @@ static int ext4_rename(struct inode *old int credits; u8 old_file_type; + if (new.inode && new.inode->i_nlink == 0) { + EXT4_ERROR_INODE(new.inode, + "target of rename is already freed"); + return -EFSCORRUPTED; + } + if ((ext4_test_inode_flag(new_dir, EXT4_INODE_PROJINHERIT)) && (!projid_eq(EXT4_I(new_dir)->i_projid, EXT4_I(old_dentry->d_inode)->i_projid)))