Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp622424img; Fri, 22 Mar 2019 05:20:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqyntauJC9rOp686BwIV0YF/cfjM/ftYV424SEMIXNOnF45URMOGPvVySPTIFb9XxGtqI9q5 X-Received: by 2002:a62:e411:: with SMTP id r17mr8824434pfh.127.1553257252844; Fri, 22 Mar 2019 05:20:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553257252; cv=none; d=google.com; s=arc-20160816; b=bSUHkjP5M4eVLKTBfOJVV6KDc1gkWIQ6sOpNw803KQ2BCksC4SgNfslrle1w3w2HIg dmMshVhfzENozozkz4Y3y7+zOnVNYpp4s9l+SM66040r++E9bZBaUFt+2qLMfhLn+8Vf KQd+Zh6F7G9utowcq2X0GiBKOCz9s8G9xe61Q5B1ZZyIylXfGDLuaOX37OSOKM296Mvd jeuaSjpREnFuYRGd/XLGdssBPf0H3SfexkFvjEMThQenuk6MqJni9Kp/2vbHVvb+IgrW 2Jy1xznPkhUCwXibpH4HbzlLrjkPX4WJoXhwGeRTyRi8gX6IGkeQMwUIVQUolynuNNkO X7hg== 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:dkim-signature; bh=HKFB9SGPiv7nMutKWbCvcEXoNSJZvsnSdPWSBAX9gmc=; b=dkohlnSUI8nGcrLpp5nqcYk8n5fht7bg64XKFdTGM0VHFb/Ql9MfU/tthT88eb1+x4 Ki6jRYcKW057yW+q8dAplBNVdKD1fnRSWQx2+Hwq3LTjQtpGV9PLiMHW4HXHAuKCZINI s9eiu037djBltOs2t4vaRyb3FHT2G2HrPb6N1YFlT5tkXufLBqSquzBQKN4dV1vqGWX4 BojM9UwD4ekpxs4RWmei0xYKCDceBQDhyC8OUMv7Oyo3cjeWFi13uCuc84P879LwCtcD KkRKaeH0nyQt/Sy2IEnC43FlgdrSzm/SJ4oK8sVqfWkb5VlrQlaC/e6K3D/9mGOoPmn2 6CMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gthZr2tg; 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 b3si6453401pgq.132.2019.03.22.05.20.37; Fri, 22 Mar 2019 05:20:52 -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; dkim=pass header.i=@kernel.org header.s=default header.b=gthZr2tg; 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 S2390695AbfCVMUF (ORCPT + 99 others); Fri, 22 Mar 2019 08:20:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:59050 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389943AbfCVMUC (ORCPT ); Fri, 22 Mar 2019 08:20:02 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 81EFC218A1; Fri, 22 Mar 2019 12:20:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553257202; bh=VR71bDdq3DNBvWX3u8FZpdzQh9PhPkg8qxy+Cpj0XQ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gthZr2tg5ah2SduMOH0uwSvVtQHsmkKA2apOzvR9X+iWwyZ1OhjUXGFc57RSrkgWR KW91pksxN8IR++HtjpGiFfEvF51wqswCnY4d3WFw4nf/fAIgSATqivbHmuanAstIO4 LhU7DIFvWuvXiZS63sHiV2oY+nx4haKbZxkFeMuk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, yangerkun , Theodore Tso Subject: [PATCH 5.0 122/238] ext4: add mask of ext4 flags to swap Date: Fri, 22 Mar 2019 12:15:41 +0100 Message-Id: <20190322111305.723557203@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111258.383569278@linuxfoundation.org> References: <20190322111258.383569278@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 5.0-stable review patch. If anyone has any objections, please let me know. ------------------ From: yangerkun commit abdc644e8cbac2e9b19763680e5a7cf9bab2bee7 upstream. The reason is that while swapping two inode, we swap the flags too. Some flags such as EXT4_JOURNAL_DATA_FL can really confuse the things since we're not resetting the address operations structure. The simplest way to keep things sane is to restrict the flags that can be swapped. Signed-off-by: yangerkun Signed-off-by: Theodore Ts'o Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/ext4/ext4.h | 3 +++ fs/ext4/ioctl.c | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -426,6 +426,9 @@ struct flex_groups { /* Flags that are appropriate for non-directories/regular files. */ #define EXT4_OTHER_FLMASK (EXT4_NODUMP_FL | EXT4_NOATIME_FL) +/* The only flags that should be swapped */ +#define EXT4_FL_SHOULD_SWAP (EXT4_HUGE_FILE_FL | EXT4_EXTENTS_FL) + /* Mask out flags that are inappropriate for the given type of inode. */ static inline __u32 ext4_mask_flags(umode_t mode, __u32 flags) { --- a/fs/ext4/ioctl.c +++ b/fs/ext4/ioctl.c @@ -63,6 +63,7 @@ static void swap_inode_data(struct inode loff_t isize; struct ext4_inode_info *ei1; struct ext4_inode_info *ei2; + unsigned long tmp; ei1 = EXT4_I(inode1); ei2 = EXT4_I(inode2); @@ -72,7 +73,10 @@ static void swap_inode_data(struct inode swap(inode1->i_mtime, inode2->i_mtime); memswap(ei1->i_data, ei2->i_data, sizeof(ei1->i_data)); - swap(ei1->i_flags, ei2->i_flags); + tmp = ei1->i_flags & EXT4_FL_SHOULD_SWAP; + ei1->i_flags = (ei2->i_flags & EXT4_FL_SHOULD_SWAP) | + (ei1->i_flags & ~EXT4_FL_SHOULD_SWAP); + ei2->i_flags = tmp | (ei2->i_flags & ~EXT4_FL_SHOULD_SWAP); swap(ei1->i_disksize, ei2->i_disksize); ext4_es_remove_extent(inode1, 0, EXT_MAX_BLOCKS); ext4_es_remove_extent(inode2, 0, EXT_MAX_BLOCKS);