Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp13951288pxu; Mon, 4 Jan 2021 08:48:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJy67yCGgKQwwSdGFF7sJu5XTpve4ADHG4mypYQL77JiR4DeH90wTBhDqkZd2zEJS645Eq8o X-Received: by 2002:a17:906:2b50:: with SMTP id b16mr65826833ejg.255.1609778918127; Mon, 04 Jan 2021 08:48:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609778918; cv=none; d=google.com; s=arc-20160816; b=w8HBvo2bi1GsCY2glNyiDQamt2Tp4E2CocBHBxzFc224As0NgK4y3Y89sUaPdrhPM3 N24jjVQUaJNgC0GtaLYTcuhsOTcpKtJL0vcpIurp8bUnIGxjQBQVsh6fR/QdyqVcaSzv 4UnNT0FknGLDhqNBCsbLJAo5qhrD/a/lyZPAE8/nSCrp+5HGvTXHqJTwYB0m+h7Bpqo+ oBGhbrLGRiPQ6AEXQid2C90oqj34LPVH4njbH814MyrAFdIA6OgsLu6a/RJLgu1S6eDO o8lwym31mVtOIWLQbaES0Ve/ZiG22tMT01W8I/S5hhxazEU0cmGY7zpshvTDJCeWCRki QpUQ== 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=/F3aC3QoRi35cnjlgM4A8bxNXhaX5HJEDHqtjA9C7OI=; b=OvU6+oEXnORTWi/VRnI7OmLrAGjD95Oif/2FZmAHOUA4IXYAci1evW09H7HV19pRAG 7cahfY51V/XYB7DIDc1gfbVVqpFJTmqsKZYjDobfq5h16pxVcMzV4FLF76wUoIzNFPA9 cwGZAvr7zZ5OvlXFN7eAL8G2CR7FV2kwWvTuYs3POxRLI9ddF6QIgr+5+7GgfVAssaww pufdoSs0iPGQEl1sQRODeH9SpFVDU/frgyi2E0EPCD9oQQFe3mTRU/dAASw/0Iz5X92I AmnNZtiBTGffxK/SwB1itS2057hFlO4GxYUH+tQ6oFURTsMFe8htH9DOyoTTCoVzNile YOZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Bzlo989+; 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 gb7si26211972ejc.460.2021.01.04.08.48.14; Mon, 04 Jan 2021 08:48:38 -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=Bzlo989+; 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 S1728245AbhADQAL (ORCPT + 99 others); Mon, 4 Jan 2021 11:00:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:36580 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728190AbhADQAE (ORCPT ); Mon, 4 Jan 2021 11:00:04 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id EAF702250E; Mon, 4 Jan 2021 15:59:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609775979; bh=BgeNQdmkgpkJZC347Vao4KQP4a/gxWQMI42B7T6bj4k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bzlo989+BX+K7LfpDlmY7Moy2lctN8iN9/6tdp4e0iQY0eKaS0eAwpJXtPuJE1CLY qAWUd60Up+btwicP4lWxnxKusq5CqrYe9XMbjnOVrNq/2Kii8yvubwsJHDBzuBvYkS XievafPqtzqeU+2Ij7H2wJISLnmldmV13GofDaKw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Eric Biggers Subject: [PATCH 5.4 05/47] ubifs: prevent creating duplicate encrypted filenames Date: Mon, 4 Jan 2021 16:57:04 +0100 Message-Id: <20210104155706.010260573@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 76786a0f083473de31678bdb259a3d4167cf756d 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 ubifs by rejecting no-key dentries in ubifs_create(), ubifs_mkdir(), ubifs_mknod(), and ubifs_symlink(). Note that ubifs doesn't actually report the duplicate filenames from readdir, but rather it seems to replace the original dentry with a new one (which is still wrong, just a different effect from ext4). On ubifs, this fixes xfstest generic/595 as well as the new xfstest I wrote specifically for this bug. Fixes: f4f61d2cc6d8 ("ubifs: Implement encrypted filenames") Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20201118075609.120337-5-ebiggers@kernel.org Signed-off-by: Eric Biggers Signed-off-by: Greg Kroah-Hartman --- fs/ubifs/dir.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) --- a/fs/ubifs/dir.c +++ b/fs/ubifs/dir.c @@ -278,6 +278,15 @@ done: return d_splice_alias(inode, dentry); } +static int ubifs_prepare_create(struct inode *dir, struct dentry *dentry, + struct fscrypt_name *nm) +{ + if (fscrypt_is_nokey_name(dentry)) + return -ENOKEY; + + return fscrypt_setup_filename(dir, &dentry->d_name, 0, nm); +} + static int ubifs_create(struct inode *dir, struct dentry *dentry, umode_t mode, bool excl) { @@ -301,7 +310,7 @@ static int ubifs_create(struct inode *di if (err) return err; - err = fscrypt_setup_filename(dir, &dentry->d_name, 0, &nm); + err = ubifs_prepare_create(dir, dentry, &nm); if (err) goto out_budg; @@ -961,7 +970,7 @@ static int ubifs_mkdir(struct inode *dir if (err) return err; - err = fscrypt_setup_filename(dir, &dentry->d_name, 0, &nm); + err = ubifs_prepare_create(dir, dentry, &nm); if (err) goto out_budg; @@ -1046,7 +1055,7 @@ static int ubifs_mknod(struct inode *dir return err; } - err = fscrypt_setup_filename(dir, &dentry->d_name, 0, &nm); + err = ubifs_prepare_create(dir, dentry, &nm); if (err) { kfree(dev); goto out_budg; @@ -1130,7 +1139,7 @@ static int ubifs_symlink(struct inode *d if (err) return err; - err = fscrypt_setup_filename(dir, &dentry->d_name, 0, &nm); + err = ubifs_prepare_create(dir, dentry, &nm); if (err) goto out_budg;