From patchwork Fri Apr 7 17:58:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 9670069 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D00946021C for ; Fri, 7 Apr 2017 18:01:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8EA828609 for ; Fri, 7 Apr 2017 18:01:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD7222862E; Fri, 7 Apr 2017 18:01:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6750728609 for ; Fri, 7 Apr 2017 18:01:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932127AbdDGSBH (ORCPT ); Fri, 7 Apr 2017 14:01:07 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:36152 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934660AbdDGSBE (ORCPT ); Fri, 7 Apr 2017 14:01:04 -0400 Received: by mail-pg0-f67.google.com with SMTP id 81so17033509pgh.3; Fri, 07 Apr 2017 11:01:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AXzGRKQ1wvoBvIbIew+J8L/PR4cGNtztvUxyWqlD2Gg=; b=A9GOKP2dCbJPr0Z7NAUJYjJUFh33SJ5l+ZUa7kGaYUhaCn1LRhob3qfSngzCKGNoD5 qz2907lpTL+YWoixVOwLomhGVclZV05qV8h2Ch5qY92DkgSrxndYBfjRKPh82ouURlV1 5UlGb+qAtkFOw6akTtXCSeWlv/TwsG8hZTzh6Cd3cw+PECoXoxD0I9As8Zxu98PVEjQp o2f/vY5N5fvZNvO65ziMm9xonp1LRx/q41Aubj/l4fpK8+//b9VMqJBAFTRtkBZoDegv rMdMUqKOFAmoxiUMoxjD0jJJhnocPOU3jv18GyWdIlX6GrEzcEM28m2z/Rgm3N8c4oso vXbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AXzGRKQ1wvoBvIbIew+J8L/PR4cGNtztvUxyWqlD2Gg=; b=VR7QpcI45VTXcHZi4Vg+rYXTlesRq2jPRFbuZ/Bc3ElomUqe1R//szxvfDxMGwmil+ d9Jg/LgTa+1iCCWk2Xq3WFbpyvaP4kZ1B0ibVE6qJijSupU3YQ9uXN7hVhQvkJF5Jsem VzSsy+6PNtJ3wP+BYhD6Y+aB/Bv0RAzhUDUcK95X7gnjniUYmaedlqDL6BBKx5ieYM/p qvNBuPimPIPrPFJkXsmiJY33/+/iBymVlmodOx5DejIgKNQmwK+jApy1k8G6WddBF4+8 QhhLGpoC3UwwiWTzYg10i7W4Eacz0ucfy/sihvK0wSFOG0qBSuzW2zpHui/BKIissjLm agTg== X-Gm-Message-State: AFeK/H1m/NuuQigFqjkOmvOuxxGiNGP98VOwajbmhMAdNkOkuMQUMCL2oy6LEB4cbFVuhA== X-Received: by 10.99.125.18 with SMTP id y18mr42749387pgc.229.1491588063108; Fri, 07 Apr 2017 11:01:03 -0700 (PDT) Received: from ebiggers-linuxstation.kir.corp.google.com ([100.119.30.131]) by smtp.gmail.com with ESMTPSA id c64sm4747146pfa.110.2017.04.07.11.01.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 07 Apr 2017 11:01:02 -0700 (PDT) From: Eric Biggers To: linux-fscrypt@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, "Theodore Y . Ts'o" , Jaegeuk Kim , Richard Weinberger , Michael Halcrow , Eric Biggers Subject: [PATCH 4/4] ubifs: check for consistent encryption contexts in ubifs_lookup() Date: Fri, 7 Apr 2017 10:58:40 -0700 Message-Id: <20170407175840.95740-5-ebiggers3@gmail.com> X-Mailer: git-send-email 2.12.2.715.g7642488e1d-goog In-Reply-To: <20170407175840.95740-1-ebiggers3@gmail.com> References: <20170407175840.95740-1-ebiggers3@gmail.com> Sender: linux-fscrypt-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fscrypt@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers As ext4 and f2fs do, ubifs should check for consistent encryption contexts during ->lookup() in an encrypted directory. This protects certain users of filesystem encryption against certain types of offline attacks. Signed-off-by: Eric Biggers --- fs/ubifs/dir.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c index 30825d882aa9..bbe2b346a94f 100644 --- a/fs/ubifs/dir.c +++ b/fs/ubifs/dir.c @@ -285,6 +285,15 @@ static struct dentry *ubifs_lookup(struct inode *dir, struct dentry *dentry, goto out_dent; } + if (ubifs_crypt_is_encrypted(dir) && + (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) && + !fscrypt_has_permitted_context(dir, inode)) { + ubifs_warn(c, "Inconsistent encryption contexts: %lu/%lu", + dir->i_ino, inode->i_ino); + err = -EPERM; + goto out_inode; + } + done: kfree(dent); fscrypt_free_filename(&nm); @@ -295,6 +304,8 @@ static struct dentry *ubifs_lookup(struct inode *dir, struct dentry *dentry, d_add(dentry, inode); return NULL; +out_inode: + iput(inode); out_dent: kfree(dent); out_fname: