Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp13930891pxu; Mon, 4 Jan 2021 08:15:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJwaQcLbdFY+ctjy0W7chmKn69qRfjYxeIKE5VMdkM1iIteL97oRWkH0ga5reqmZy0Onz8Af X-Received: by 2002:a17:906:a106:: with SMTP id t6mr27797977ejy.63.1609776902354; Mon, 04 Jan 2021 08:15:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609776902; cv=none; d=google.com; s=arc-20160816; b=jkOYoccIYsNaIS4DSg08RaDkxxkdB+EPJ3e4POBoZshc+EsXoYOCEdcwNBZNPJr4i1 zGidzzZdaiXe0+0NR3jFNxPyBDwxN2dWZ8jR/n5XI7vUwp6DnjnXqdbgpp9tQxUciFPk kTedL1pof82qAngrqU9gQb8EqAPB4nJKKsOSU1CP0ZyQHPptYKYduTgLP5E8c6lgPXw1 jFgrtWlaANF8VWGZXwxxszlkmS1FfagZ0EG0pPqozB5+34WXhi8P9Q66jG2xZzDipKka lXyPdaY/N+JmEuGgReP1b3x4Gjn+ggNam3ssD58DpT0WMIxjSojLUxazdqCBnehuqxRg Qaaw== 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=poQk1i9pERwr81tBYi+Mr1ZVc72aySaKrrWs5lErtdE=; b=x//vtTiTnAqcNzkPIZ6Wmmy5PjHQz/X5i0xZnv6mUlD2ndtzB6D6NPRMRm3078mSmD RdVbyBsflXXhs6E5x4uyP4ZRgVihWaheWbLiBqt1FzFt78KiVxNDmOyCBvJx+Hv1j+OQ 1m1y+jbvFUyiv1q4M7mqIb8QRjYdOdR/CLOakf5RcnvqYWQhK3Fc7vWw+2IFKHQJoqq9 dJJyviU4TXRBOy4viuDGg4GibCOQlpxRID3qxbMqC6S+vUGbrwSxI+9c1NringxOc4Fm xkW51JEIcNV61/Felaq4pmV3aND9G8HxclWL/k5qMtLM0ZbfWIe4ZkBGyuLkiHaZzux/ 2rTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SPS6jW7p; 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=pass (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 f10si33206918edc.491.2021.01.04.08.14.38; Mon, 04 Jan 2021 08:15:02 -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=@linuxfoundation.org header.s=korg header.b=SPS6jW7p; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729713AbhADQMS (ORCPT + 99 others); Mon, 4 Jan 2021 11:12:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:36582 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728185AbhADQAD (ORCPT ); Mon, 4 Jan 2021 11:00:03 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id A0DF222509; Mon, 4 Jan 2021 15:59:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609775977; bh=hYv88ZhcQDYxxkPWVVQs8IfCZIWBUefAj4Juajj6/HY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SPS6jW7pLES0Z3b5A1J9tTdjwIn6blPEetZb1OWdxGCWso99VDCCN/9qr4SDc65RE Fqg4fvEEcG7Bq8898/Rl7ITjOVza5fdYyZkh8gQw4UjuNq1mocMCHcCY1Z+WccKuif to48GPwiRQi3zF2VTzHfe0LA0M59ZCVoctk8ahNY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Eric Biggers Subject: [PATCH 5.4 04/47] ext4: prevent creating duplicate encrypted filenames Date: Mon, 4 Jan 2021 16:57:03 +0100 Message-Id: <20210104155705.961484814@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210104155705.740576914@linuxfoundation.org> References: <20210104155705.740576914@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 75d18cd1868c2aee43553723872c35d7908f240f upstream. As described in "fscrypt: add fscrypt_is_nokey_name()", it's possible to create a duplicate filename in an encrypted directory by creating a file concurrently with adding the directory's encryption key. Fix this bug on ext4 by rejecting no-key dentries in ext4_add_entry(). Note that the duplicate check in ext4_find_dest_de() sometimes prevented this bug. However in many cases it didn't, since ext4_find_dest_de() doesn't examine every dentry. Fixes: 4461471107b7 ("ext4 crypto: enable filename encryption") Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20201118075609.120337-3-ebiggers@kernel.org Signed-off-by: Eric Biggers Signed-off-by: Greg Kroah-Hartman --- fs/ext4/namei.c | 3 +++ 1 file changed, 3 insertions(+) --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -2192,6 +2192,9 @@ static int ext4_add_entry(handle_t *hand if (!dentry->d_name.len) return -EINVAL; + if (fscrypt_is_nokey_name(dentry)) + return -ENOKEY; + #ifdef CONFIG_UNICODE if (ext4_has_strict_mode(sbi) && IS_CASEFOLDED(dir) && sbi->s_encoding && utf8_validate(sbi->s_encoding, &dentry->d_name))