Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1784323imm; Thu, 27 Sep 2018 02:25:24 -0700 (PDT) X-Google-Smtp-Source: ACcGV63PcinOI0dgclZKrX/CeqGjH6v9qbzo20xOGf3PuONr2pSP0rUT95Qhe64vkiYzq8HewO5r X-Received: by 2002:a63:2218:: with SMTP id i24-v6mr9430929pgi.238.1538040324797; Thu, 27 Sep 2018 02:25:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538040324; cv=none; d=google.com; s=arc-20160816; b=aP3B6nAGeJzqyW//AIWMO8xMeFPMykvcxrl6oSoaFm4yInAh5DvahBRs6fo7DHPPVw kT2nszFP00PaL/3Vijpt7avJA9Y2hMVn+wgjDBvGghuYBVPkP8p6QRlShjRRRAVJfMO/ FIn8NDPk5x6FnaLQS680OWrGUin3XrFO+HCVN1kKwH4RQng31cNRo8Ld/JYhknrvSskY oBd3LcD9rjWJ/i1OpWBlc9gx9vog3VS2ucsx7d+ZBlZ7YkOglYTIGY0grskcQlmJMPHB hfbOIVVls3OsnZH11DEufAkicOA0St+9JA0H6ULNp+aQL/9jnAu22wIrlNNbzYqe0/G2 rN0g== 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=XQGOGwD6lTJteGssGP0JxS7ISvXs/s0YKGMnxvz3D3w=; b=pDIHrS6LMUqUqd56VOjM9GmGpS6GFJHYYrZj2Gx3ZuuTF/orVwqaymlEnOwtgRDm3R xj+03DydbeuCReco2O/UHbce0HMk2r6APNZXb1Ak3QSngStuFTjlINaqPtZlGP3z4x++ fQxunUDGIMaDOJUwEMCXnkY6EkOvOgvwh0LPMcDKRaq7DLIZiVFLyzE8lpWha92+GtTV FRPu7Dslocox80fwW/AYaEJnXUR9EIk5DUcMyXapabR1il/xskpPvoBYpbW5I+ogcAFB T2V9lKKWSld0j6dAT6sgCHcksJ5aI/cSVFF0zfWGK28r8tMOdIwWWC+9/6ekvnL4L/7s mNiQ== 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 t19-v6si1777158pfm.152.2018.09.27.02.25.09; Thu, 27 Sep 2018 02:25:24 -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 S1728914AbeI0PmI (ORCPT + 99 others); Thu, 27 Sep 2018 11:42:08 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:56714 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727411AbeI0PmH (ORCPT ); Thu, 27 Sep 2018 11:42:07 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id E55F5111C; Thu, 27 Sep 2018 09:24:46 +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.14 51/64] ext4: check to make sure the rename(2)s destination is not freed Date: Thu, 27 Sep 2018 11:04:08 +0200 Message-Id: <20180927090257.098102014@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180927090249.801943776@linuxfoundation.org> References: <20180927090249.801943776@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.14-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 @@ -3514,6 +3514,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)))