Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3707473ybv; Mon, 10 Feb 2020 05:05:06 -0800 (PST) X-Google-Smtp-Source: APXvYqziyb8LAXWbMSwyqDrKUAsk8eRlxOm3FyTwlM84deUlT5jbKiYUqn/OrWXaAMegkcckmQXB X-Received: by 2002:aca:5f87:: with SMTP id t129mr774717oib.36.1581339906252; Mon, 10 Feb 2020 05:05:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581339906; cv=none; d=google.com; s=arc-20160816; b=hxMn1Klf9r1fDMRycEWi1INJxNbCNvLz+QU1Dnoew2j1C4ryl2JFmExX5UytJxECtD rSFLgeM3SsUwGbe66h0gF4n+WiD1ek9yaeExUoxMzY0z1qYsbT5zGV4E2+5KptkvbFZL XE7XbRoUXbymyqed0c8N46RvBkDRHWZz0vk4Dr65uoSS8CEiQytHqR/Dr4M/0k3dAIT1 Oaa5NA4wryLragRk8mwc28/PpsUiojHFoWnnobm/II8IWszgQmwyGPiqaI77Z6KIoru7 xHftw24rdXaGdeHdhCZfjM8w7YMKOsPRQoFh5zhO0DPTX0vsXCm/52xbFDds7/xx8XQA 0kcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TtDw8ze4imArk+4100DZsNPSxbVjXKgwKnQmjw6/7d0=; b=Jdup0lzL+vX977c7TJEEr7ATj6A0LHRqqq/ABjKclVD4VoHPOQ4HO9YcbK6IGDEnRj uNvDXq8rkZz6C6/ChFdCW94Kx6CFguN1wjlsVzmq1VhDEfR4YmyZSkmQ6D5PXGvJ8LAk Pfy/avgPQcGgqlq9/ovpAFNtfa2uxrB/+JD0CgSsD4s9tSuJy18irk8iPgChjxt0W31s 3dbyyEIIoGtrQRqfeS5KRahGfomQcb0SvbU4ygYuYEtQ+uTz/vPWAwXzbDffRxZFuxPU aKvmhGQh/vtYBdXtuYZaItMI3/8KhTUqawqjw07IZsCfrlndg9Wy85SYlnWvaNnuJoVr 2ONg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1MoA4DZd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z14si132006oih.89.2020.02.10.05.04.54; Mon, 10 Feb 2020 05:05:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1MoA4DZd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730230AbgBJND2 (ORCPT + 99 others); Mon, 10 Feb 2020 08:03:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:40392 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729721AbgBJMkY (ORCPT ); Mon, 10 Feb 2020 07:40:24 -0500 Received: from localhost (unknown [209.37.97.194]) (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 DE0D020838; Mon, 10 Feb 2020 12:40:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338424; bh=On/b13BkslPuTXAbYJbp7a7hdtDg7ESrC7NRhPdErqw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1MoA4DZdtqN0UWRSHUI0spxoIhwkFeLvBixjUybGjSehpL44pa8vCena/oloh6M9U cQd9W6qdD7119Lphno4Npe0kt9oWYLLB/rhfSO+NdFmP7+68yG1nhk+HLxMvx7a0qi dVE3UbpsHV2O5Ge+8hbceDUZXU3f9F+znLcaUCok= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jerad Simpson , Milan Broz , Mike Snitzer Subject: [PATCH 5.5 144/367] dm crypt: fix benbi IV constructor crash if used in authenticated mode Date: Mon, 10 Feb 2020 04:30:57 -0800 Message-Id: <20200210122438.140222754@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210122423.695146547@linuxfoundation.org> References: <20200210122423.695146547@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Milan Broz commit 4ea9471fbd1addb25a4d269991dc724e200ca5b5 upstream. If benbi IV is used in AEAD construction, for example: cryptsetup luksFormat --cipher twofish-xts-benbi --key-size 512 --integrity=hmac-sha256 the constructor uses wrong skcipher function and crashes: BUG: kernel NULL pointer dereference, address: 00000014 ... EIP: crypt_iv_benbi_ctr+0x15/0x70 [dm_crypt] Call Trace: ? crypt_subkey_size+0x20/0x20 [dm_crypt] crypt_ctr+0x567/0xfc0 [dm_crypt] dm_table_add_target+0x15f/0x340 [dm_mod] Fix this by properly using crypt_aead_blocksize() in this case. Fixes: ef43aa38063a6 ("dm crypt: add cryptographic data integrity protection (authenticated encryption)") Cc: stable@vger.kernel.org # v4.12+ Link: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=941051 Reported-by: Jerad Simpson Signed-off-by: Milan Broz Signed-off-by: Mike Snitzer Signed-off-by: Greg Kroah-Hartman --- drivers/md/dm-crypt.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -331,8 +331,14 @@ static int crypt_iv_essiv_gen(struct cry static int crypt_iv_benbi_ctr(struct crypt_config *cc, struct dm_target *ti, const char *opts) { - unsigned bs = crypto_skcipher_blocksize(any_tfm(cc)); - int log = ilog2(bs); + unsigned bs; + int log; + + if (test_bit(CRYPT_MODE_INTEGRITY_AEAD, &cc->cipher_flags)) + bs = crypto_aead_blocksize(any_tfm_aead(cc)); + else + bs = crypto_skcipher_blocksize(any_tfm(cc)); + log = ilog2(bs); /* we need to calculate how far we must shift the sector count * to get the cipher block count, we use this shift in _gen */