From patchwork Tue Oct 27 13:47:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 307146 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC5F0C55179 for ; Tue, 27 Oct 2020 17:24:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 99BD72076B for ; Tue, 27 Oct 2020 17:24:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603819459; bh=I155zozoECyCRDse1vjaFFlaWx71oqPdXbTz5mWzBEM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=lKoqe1z8WcD2Vl0LpQCBhMn2Iswu7lNp48yEkSpxKdB0bnwzRKCETd1+3iIq22UH3 pUuCSSJ+PT0u49XxTlRCrsf3JCP/uiaRUhffSwd07CbCG4RYXk44a0CoETxFz5fhdz wi3J14uOifz1GRd/F97VcmHzPj71lhZGXYh3nN2o= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2900805AbgJ0RYS (ORCPT ); Tue, 27 Oct 2020 13:24:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:54646 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2900787AbgJ0OyO (ORCPT ); Tue, 27 Oct 2020 10:54:14 -0400 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 662F920679; Tue, 27 Oct 2020 14:54:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603810454; bh=I155zozoECyCRDse1vjaFFlaWx71oqPdXbTz5mWzBEM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=djqzhHS5RaJ6zPFvrAWrnhToFQ9rQlaFEVBchKkrQIPqdQSX03BF7k6/OM2x5Kt2S wacqnVhdJPX4mDFZPQPs+o6y2+5qs02BoaPMQIkq9Y/udCnEiLtsIhzneAWOkyGTGo Affokkk7xS70lb0HmdUsp7uA+dD8qaC6pplPJYU0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jeff Layton , Eric Biggers , Sasha Levin Subject: [PATCH 5.8 114/633] fscrypt: restrict IV_INO_LBLK_32 to ino_bits <= 32 Date: Tue, 27 Oct 2020 14:47:37 +0100 Message-Id: <20201027135528.042711735@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Eric Biggers [ Upstream commit 5e895bd4d5233cb054447d0491d4e63c8496d419 ] When an encryption policy has the IV_INO_LBLK_32 flag set, the IV generation method involves hashing the inode number. This is different from fscrypt's other IV generation methods, where the inode number is either not used at all or is included directly in the IVs. Therefore, in principle IV_INO_LBLK_32 can work with any length inode number. However, currently fscrypt gets the inode number from inode::i_ino, which is 'unsigned long'. So currently the implementation limit is actually 32 bits (like IV_INO_LBLK_64), since longer inode numbers will have been truncated by the VFS on 32-bit platforms. Fix fscrypt_supported_v2_policy() to enforce the correct limit. This doesn't actually matter currently, since only ext4 and f2fs support IV_INO_LBLK_32, and they both only support 32-bit inode numbers. But we might as well fix it in case it matters in the future. Ideally inode::i_ino would instead be made 64-bit, but for now it's not needed. (Note, this limit does *not* prevent filesystems with 64-bit inode numbers from adding fscrypt support, since IV_INO_LBLK_* support is optional and is useful only on certain hardware.) Fixes: e3b1078bedd3 ("fscrypt: add support for IV_INO_LBLK_32 policies") Reported-by: Jeff Layton Link: https://lore.kernel.org/r/20200824203841.1707847-1-ebiggers@kernel.org Signed-off-by: Eric Biggers Signed-off-by: Sasha Levin --- fs/crypto/policy.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/crypto/policy.c b/fs/crypto/policy.c index d23ff162c78bc..0b32c64eb4053 100644 --- a/fs/crypto/policy.c +++ b/fs/crypto/policy.c @@ -178,10 +178,15 @@ static bool fscrypt_supported_v2_policy(const struct fscrypt_policy_v2 *policy, 32, 32)) return false; + /* + * IV_INO_LBLK_32 hashes the inode number, so in principle it can + * support any ino_bits. However, currently the inode number is gotten + * from inode::i_ino which is 'unsigned long'. So for now the + * implementation limit is 32 bits. + */ if ((policy->flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32) && - /* This uses hashed inode numbers, so ino_bits doesn't matter. */ !supported_iv_ino_lblk_policy(policy, inode, "IV_INO_LBLK_32", - INT_MAX, 32)) + 32, 32)) return false; if (memchr_inv(policy->__reserved, 0, sizeof(policy->__reserved))) {