Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp13934343pxu; Mon, 4 Jan 2021 08:19:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJxuCDs/YMQ0DHA9LcQ44NqIi5tyc4ioBRZEzA/6YUEe7Nhg4PYhQZmO85lod2qXlWtePobg X-Received: by 2002:a50:e845:: with SMTP id k5mr37812327edn.35.1609777193535; Mon, 04 Jan 2021 08:19:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609777193; cv=none; d=google.com; s=arc-20160816; b=CRGhF9OGYePuSMu5OUw6q5JI6g+blsw0ugJBWdGwZa9brKVoMXMuXxOA3JyRhEdoIt KkTn3N1S2wnmOvDNKnBc5dq7vREFcEdbIkSoRH80jSEs2JQwr8sPhtYlEIrJQFVorfnM Qh20s5EfzbajNK5I5qRrc3gposYX5i6VIqSEBl0ecLTC8DfrOjFrxnzwvNcCb89fRkwp 1yJhEiakkTkpeknogOYq07UuJjwy2oOAJ9H+930bT6ord5r2HeXwOTQKKZpwwaO1GrSr OqBDnGhiMaPgpchF/60YnAcfykTAmOegb7bs4v/wIbsDWJviyS12zvzBlIl4ZAULGW7g wEEA== 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=AYbyndBmxGvn1CQiLd+6VAA7yw2MjNy3GovjCEIdFNQ=; b=Cw0SjkIlCrtYk6Yt0ERQplHAIyCSKcnDzOr+uhYSeRw5lUazESH2/ABn88PQ1s4V4Y UL7ru62YIA43DiwdEiR6PmOz4a4UpKSRqYH8caeCdFn1SmpraCTaJ3ItXDFudfr/aRka BhZbKozHQyIMlKCoA3tDOUj8GMEM7VOt9GcHemI3wVmvGSWIg44A9gLBBq0+hGrWRgYS mDVJiYo7Xxh+WJS+Yzw5AZxO0XpeonXr8MBC55dMWOb/Or4dpeWjKfjanA1oa8dfMaJK VXCqUE+5qIZCg7Glrf7HIbi9kXdSRCjtLYXckCYt2FZrs4RlWL9mbXjFj8bO3VRbzghU 9Q+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yntCvpQG; 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 q9si31052458edr.98.2021.01.04.08.19.30; Mon, 04 Jan 2021 08:19:53 -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=yntCvpQG; 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 S1727876AbhADP7Z (ORCPT + 99 others); Mon, 4 Jan 2021 10:59:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:36516 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727871AbhADP7Z (ORCPT ); Mon, 4 Jan 2021 10:59:25 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4D5A9224DF; Mon, 4 Jan 2021 15:58:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609775899; bh=gMsNqKJZDuk4ZcuwnLe9zXaIYdpN/cXIbf4pPVDIPbU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yntCvpQGxawuQYt/HrcD7YaYuE8iuGko1pzW64kXBxcR2qWZjFhxRZiUDnPT3fMJd CtFGBRtEhOGJBGdla8AqGGpxr1HA4EnusdavPEUqKRJVugz14Uw53mVWfzDQrBcXq7 YI1xurejWxV9m51JhUhmpdV0Xsd8+chYt3haT1qE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Eric Biggers Subject: [PATCH 4.19 03/35] ext4: prevent creating duplicate encrypted filenames Date: Mon, 4 Jan 2021 16:57:06 +0100 Message-Id: <20210104155703.551280253@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210104155703.375788488@linuxfoundation.org> References: <20210104155703.375788488@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 @@ -2106,6 +2106,9 @@ static int ext4_add_entry(handle_t *hand if (!dentry->d_name.len) return -EINVAL; + if (fscrypt_is_nokey_name(dentry)) + return -ENOKEY; + retval = ext4_fname_setup_filename(dir, &dentry->d_name, 0, &fname); if (retval) return retval;