Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp820874pxb; Tue, 3 Nov 2020 13:29:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJxW89MwBBMFL9Vhbe47Y+4gRvmepWcId70vu/BSJpbQ53RAa7T6faItwVnyWSXbbXQcyS2o X-Received: by 2002:a17:906:2490:: with SMTP id e16mr21555648ejb.17.1604438981386; Tue, 03 Nov 2020 13:29:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604438981; cv=none; d=google.com; s=arc-20160816; b=qqJ71wUsM2cMS3K6dlf3GJQrmcxhy0hTi+8hnnrHGKX5JZJnBu2KorDS7RJuXxBRVh Dd31E8o0K0K36h2vslAPizAhCRQqt+Y/t83etE528W+A4EID1Pl0uyx2zc0kU9Lw+Pc2 JlriiiHbBH4TAyJtS5R8zgbGkpJyOBKajsFZ05sCZ+TJ7wFESbMcQCRLYo3pWkXBWffB 8+7m4XkhhHej0ZolK27JMQjCydWnnDnoNmVjEdxVCGSJPsS8VGapM++RVZLEHW74K2/Q fb6tfGxx/ugZuYhL5wA8K6gsQlmysms9m0COn1YmBzFdy42YgALwxJ9cY3VBbQAdVsL5 w5aw== 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=SPYQPTzQQWp/x+5JBgw975wKmJj1+0InC9H1uumnsNM=; b=ejqaJidveV8mWkfttIe0p9UtvpQDVN++mKieRoZcxIeuh1utNF7e0G3NOPIIcRBGNp EtUqQsEsRO+NYsCTgTCm2oxHaHNl6rb3OypSRqxVyZI4e86vVVchDBI+EkpoiPbaml1I Oach/VYyiO7n4h+bWRDMJCyIQER54xVvxpyqgxTGy+Hl5/i4MUgDTJ+3y+Os1UZPUqcD qC2HsaNX//mTYEci2+nWPb2OlEx2a2mDBNaDgQYcx8XyfA7kZJ7Pcfj+95MDH84EVhj+ qiQDnY4nAK3zgKWNToi29kyKZ4zINjgpJocnoyrNiJq87GaNlxJArWMU67qaq9F9BpT/ 91Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NQltznUz; 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 z22si6531ejx.130.2020.11.03.13.29.18; Tue, 03 Nov 2020 13:29:41 -0800 (PST) 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=NQltznUz; 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 S2387620AbgKCVCV (ORCPT + 99 others); Tue, 3 Nov 2020 16:02:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:39238 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732120AbgKCVCQ (ORCPT ); Tue, 3 Nov 2020 16:02:16 -0500 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 2201020658; Tue, 3 Nov 2020 21:02:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437335; bh=GXn9SUQ/vYrUY9YRnVP4GX2jDPIuBGR1SZxsAW7cmqk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NQltznUzBHSlRXiwGhVQag5y9AGYX+hjAWNEP1jxYO7pRf2OtaXQNW01lFowvz4jE FgIFP818Ey34PXzeFMyzOcACgyhTF/kGZ29R6UJZHNT/QvRAVbfuHO/gFcQbYlNRoR qDLKWZyUgID1bJZkK8CYM/zyHikcxhpybNqjkdQY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Sarthak Kukreti , Eric Biggers , Theodore Tso Subject: [PATCH 4.19 032/191] fs, fscrypt: clear DCACHE_ENCRYPTED_NAME when unaliasing directory Date: Tue, 3 Nov 2020 21:35:24 +0100 Message-Id: <20201103203236.879284047@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203232.656475008@linuxfoundation.org> References: <20201103203232.656475008@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: Eric Biggers commit 0bf3d5c1604ecbbd4e49e9f5b3c79152b87adb0d upstream. Make __d_move() clear DCACHE_ENCRYPTED_NAME on the source dentry. This is needed for when d_splice_alias() moves a directory's encrypted alias to its decrypted alias as a result of the encryption key being added. Otherwise, the decrypted alias will incorrectly be invalidated on the next lookup, causing problems such as unmounting a mount the user just mount()ed there. Note that we don't have to support arbitrary moves of this flag because fscrypt doesn't allow dentries with DCACHE_ENCRYPTED_NAME to be the source or target of a rename(). Fixes: 28b4c263961c ("ext4 crypto: revalidate dentry after adding or removing the key") Reported-by: Sarthak Kukreti Signed-off-by: Eric Biggers Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/dcache.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) --- a/fs/dcache.c +++ b/fs/dcache.c @@ -2713,6 +2713,20 @@ static void copy_name(struct dentry *den } /* + * When d_splice_alias() moves a directory's encrypted alias to its decrypted + * alias as a result of the encryption key being added, DCACHE_ENCRYPTED_NAME + * must be cleared. Note that we don't have to support arbitrary moves of this + * flag because fscrypt doesn't allow encrypted aliases to be the source or + * target of a rename(). + */ +static inline void fscrypt_handle_d_move(struct dentry *dentry) +{ +#if IS_ENABLED(CONFIG_FS_ENCRYPTION) + dentry->d_flags &= ~DCACHE_ENCRYPTED_NAME; +#endif +} + +/* * __d_move - move a dentry * @dentry: entry to move * @target: new dentry @@ -2787,6 +2801,7 @@ static void __d_move(struct dentry *dent list_move(&dentry->d_child, &dentry->d_parent->d_subdirs); __d_rehash(dentry); fsnotify_update_flags(dentry); + fscrypt_handle_d_move(dentry); write_seqcount_end(&target->d_seq); write_seqcount_end(&dentry->d_seq);