Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3030119imu; Sun, 9 Dec 2018 15:33:17 -0800 (PST) X-Google-Smtp-Source: AFSGD/XatKuDGFlRJ0yZXkz5vDjKASQqz6M/vPb90YbC58v+wjrMHjd+vXnoB8LvCOjfaIdwjLTR X-Received: by 2002:a17:902:6b84:: with SMTP id p4mr10240235plk.282.1544398397769; Sun, 09 Dec 2018 15:33:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544398397; cv=none; d=google.com; s=arc-20160816; b=H2J4Ov5PrZ942RgMM/QyVHpVY/h0m02+GjzXSdQGhgY62s5E6jshEla21Sslir5JIc Z4zfVzBX9zzbDp5Ghlyq81+h2CoSPUwlxmOV2GfGwHRNHj9LyPh53BdaDjhug00hTDNE hikV2TxY/z02Y6QX2UhMWbBZ7f03LCM/aWhiWvjRZ6vkLve2+eEXeP7qCFx7lR2MysIX cH0XBEd2NzCD+3rdYutvvJ4CRyRA5/AtpTWYsyn773n557sZ776HkXd1XtSn+R6C0DaT 6PKPhdg+8iQSDFm/AxzjTQY240XU2tCW11UlDmRo5/rSIhsLobPNHv+eLSjLGE7X5a/1 1CtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=yyBE7zDP67w3iN/8XzOpl2h4PnZFq2gEIwVNffp9z3k=; b=PolAtZ9eB7wFsJvqzqtuh4vjB7wTRYJT8/aO+ZMs6r06SHeBhDlgtcWncnkj5avCZO slL2wb1SnUTOoLa0RPRHdkDIF4iRGnVZC9xZ8gDEpPWkrI5TfmueXbzg0vQ8tEo3L9hH /QmwhdHX03G+7L0EfNcIbCS7pxhP1KfPBWU1n7T31q7cmXZDFDWDwvr1CThVjNIrcqga lcq0iIL+IZgLBltp99bCTKIgeKawRNi+yGXwDIYUUvpMpyF8n+Q2qFCB8EaeOWhmq/ab OaS6juo7pn82x9OgH8lWseIlqFBYcF8n3fX+RoZkWUl2w9g2lMoXuL0q9Sa1v+ftq4c2 HOWQ== 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 w31si8871677pla.308.2018.12.09.15.33.01; Sun, 09 Dec 2018 15:33:17 -0800 (PST) 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 S1728694AbeLIWYt (ORCPT + 99 others); Sun, 9 Dec 2018 17:24:49 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:34968 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726467AbeLIVzR (ORCPT ); Sun, 9 Dec 2018 16:55:17 -0500 Received: from pub.yeoldevic.com ([81.174.156.145] helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gW72h-0002pr-AO; Sun, 09 Dec 2018 21:55:15 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gW72e-0003RN-Ew; Sun, 09 Dec 2018 21:55:12 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Wen Xu" , "Theodore Ts'o" Date: Sun, 09 Dec 2018 21:50:33 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 163/328] ext4: check to make sure the rename(2)'s destination is not freed In-Reply-To: X-SA-Exim-Connect-IP: 81.174.156.145 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.62-rc1 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 [bwh: Backported to 3.16: - Return -EIO on error - Adjust context] Signed-off-by: Ben Hutchings --- fs/ext4/namei.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -3211,6 +3211,12 @@ static int ext4_rename(struct inode *old int force_reread; int retval; + if (new.inode && new.inode->i_nlink == 0) { + EXT4_ERROR_INODE(new.inode, + "target of rename is already freed"); + return -EIO; + } + dquot_initialize(old.dir); dquot_initialize(new.dir);