Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1215204pxx; Tue, 27 Oct 2020 10:54:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTY0ZpN+Oa2h72TdaZA5nVCONjU7A4Ps/r0W4MDB94RE0rUkYaICjbPFjADB5sReA9qXTk X-Received: by 2002:a05:6402:1586:: with SMTP id c6mr3597031edv.84.1603821298371; Tue, 27 Oct 2020 10:54:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603821298; cv=none; d=google.com; s=arc-20160816; b=aujklcQP3U4SqxahLOBxx1PY/VPhbuzmudGkaccza9pPwYwDLOHIO2yHBayB/Kx0nx g67AZLpR08lBKNlFPTxN4KbQP7ynOInY7x1EK2iVN+w7wTG+FGWzjw6/T2hs1eGg7kmg 9dTfG4k+q+3h6GDmPmzAZqjeIciGDhNA3fKKgDU163AAobL7o4leXhTPRv5OGtY/iyIX c89ULr6E/c/M+QAA7gkhXSzvRXpAQ93GKivzNrgxDVWEvMPV53cH81EQ37+7Qc8smXqC Bf+rtwl9iTR9acsLjrRIm0hBiqxx4Yye/E+F+Zok3xlMulVfc5gDXPJM/Sd1dRoMMTUj tMtg== 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=ylvrD2NymIaDLBDUFl4Jc0Z2wiKwT5HOBK6Uibmgwk4=; b=ElcJfBX95PWUMMMpM6c+C9AHy40Dl1FdsR9HCZEqPhvLpAWzXoVrlb/30ufB91h9+/ WTmAlR2S65phtSrZlmE8ZapTkSwMCbtsYIk9KAMGNXc3q8JJNyPFPHgx5xAWxkq7yEfu w2LWE6MgWQEE0aaeVbonTPyUqbdGw9yBknFVViyN3/zfrxINjog/LTWe7QEXIOPQQyJV yvw48RpcE/f041uIt2TjBMIuTig/GWnr8HzI159DKxUoFP9OFVqkE/+CBieg8+aGe1CR aQpe2V7mfI+jimnt3ITVKgYo1VXLPGRUP5iAYIhdFgwACtxTrUTEkPF/C5Yy4fGyBD2N Uhyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=djqzhHS5; 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=fail (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 g1si1917592edn.177.2020.10.27.10.54.36; Tue, 27 Oct 2020 10:54:58 -0700 (PDT) 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=@kernel.org header.s=default header.b=djqzhHS5; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1818857AbgJ0RYT (ORCPT + 99 others); Tue, 27 Oct 2020 13:24:19 -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 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 [ 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))) { -- 2.25.1