Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3783386ybi; Mon, 29 Jul 2019 12:32:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqxbqePgt0KeawsCzUjY12vcC9fLOgAgtUW2aGZxDE5i0YPkC4vpRF0VBbCQPemzJ9dcME6R X-Received: by 2002:a17:902:9041:: with SMTP id w1mr113716238plz.132.1564428758556; Mon, 29 Jul 2019 12:32:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564428758; cv=none; d=google.com; s=arc-20160816; b=vJICKrP5VcQ0weW1vnDX8iV/PCheWgrafMhQan5/9OiY7FUNGsckOAH1yfb0Bi6EQM /j70LmzQrOBzkpC5tJLKGvWKjMQfdxSfQECzCisHaMzHIJUP0JyLvM23iFPV2aJvzkVB ZiV80ld8b9IA+JGhr4LegBwTRqPHQYlL9eJrlMxNlMgvh7dt4dQV/tkb8YWDy9479ui+ /zulPKQZvieSaPNfHfpQbQNVqdT9LJprjehe72TEku6w2PL3PfwU0+RTbpFpv1DTzc0x raGtp18VSgAtVpphjkseTGlzY5VDn/DGvQ+FhUcNWMIlysGP+Kdmig57b1k40IiUC0qZ c0HA== 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=npj+qdN7CrYI2wmBNRdDLTU8vOkVlV120h0TdlkCbX0=; b=uKyqO3CHUmZ96bI0+kvKKJiA3jjEn6Xfa4Og3oI3WzYBp2xoyYk6UCOnoZqJcfoBG6 71TrrnHs33U/jlC4f9aWI0UxcbKy4q4M1PNq6lncEPpE8Jh+73SYCLwIKqao9ElhSaaX JrDa/PiVysUM/oz1a58Hcr8+Pf4q+MxFAm7ocoUO/QmSBFMFC4RGaJL8OudYE2Pi6Xnp zhHdPrOVR/YZrvsP1meJlN0UfrqXki8JrGDJBe/9sh/cSV2vcCLTh8nZ7yAZQHn+32wr jNbpc4iCgE3vbYNaJaCDhBvbw4PCqtv0YZfcaDqO8Jph6y8OlpkrdHyMx1x92DRvbhDs eq1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="e/aOkT4p"; 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 r8si24370872pjq.62.2019.07.29.12.32.23; Mon, 29 Jul 2019 12:32:38 -0700 (PDT) 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="e/aOkT4p"; 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 S1729797AbfG2T0j (ORCPT + 99 others); Mon, 29 Jul 2019 15:26:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:39066 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729230AbfG2T0g (ORCPT ); Mon, 29 Jul 2019 15:26:36 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 02B2721773; Mon, 29 Jul 2019 19:26:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564428396; bh=kgKS+LMdkKPPHCb6GVjY3hWtP1rEuJZq78YZ0Pj86O0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e/aOkT4pNTrKOfvYBIApwqmf2wqFQrXTgb9LMlo734eSyyJbxojW96Cwlqv9x0zNX iaiTA1m3mDEL4TRHnYULahewU1ZOTyQ99OOWkynUwEFhiDUGDWgcoTuw/PMhQXjbEy 5jEgaJ0gMBZzUN4osAYUkrv5h4RAHZ1zDJAf2JrA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chandan Rajendra , Eric Biggers , Sasha Levin Subject: [PATCH 4.14 024/293] fscrypt: clean up some BUG_ON()s in block encryption/decryption Date: Mon, 29 Jul 2019 21:18:35 +0200 Message-Id: <20190729190823.128833624@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190820.321094988@linuxfoundation.org> References: <20190729190820.321094988@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 [ Upstream commit eeacfdc68a104967162dfcba60f53f6f5b62a334 ] Replace some BUG_ON()s with WARN_ON_ONCE() and returning an error code, and move the check for len divisible by FS_CRYPTO_BLOCK_SIZE into fscrypt_crypt_block() so that it's done for both encryption and decryption, not just encryption. Reviewed-by: Chandan Rajendra Signed-off-by: Eric Biggers Signed-off-by: Sasha Levin --- fs/crypto/crypto.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/fs/crypto/crypto.c b/fs/crypto/crypto.c index daf2683f0655..f862ad19c714 100644 --- a/fs/crypto/crypto.c +++ b/fs/crypto/crypto.c @@ -157,7 +157,10 @@ int fscrypt_do_page_crypto(const struct inode *inode, fscrypt_direction_t rw, struct crypto_skcipher *tfm = ci->ci_ctfm; int res = 0; - BUG_ON(len == 0); + if (WARN_ON_ONCE(len <= 0)) + return -EINVAL; + if (WARN_ON_ONCE(len % FS_CRYPTO_BLOCK_SIZE != 0)) + return -EINVAL; BUILD_BUG_ON(sizeof(iv) != FS_IV_SIZE); BUILD_BUG_ON(AES_BLOCK_SIZE != FS_IV_SIZE); @@ -257,8 +260,6 @@ struct page *fscrypt_encrypt_page(const struct inode *inode, struct page *ciphertext_page = page; int err; - BUG_ON(len % FS_CRYPTO_BLOCK_SIZE != 0); - if (inode->i_sb->s_cop->flags & FS_CFLG_OWN_PAGES) { /* with inplace-encryption we just encrypt the page */ err = fscrypt_do_page_crypto(inode, FS_ENCRYPT, lblk_num, page, @@ -270,7 +271,8 @@ struct page *fscrypt_encrypt_page(const struct inode *inode, return ciphertext_page; } - BUG_ON(!PageLocked(page)); + if (WARN_ON_ONCE(!PageLocked(page))) + return ERR_PTR(-EINVAL); ctx = fscrypt_get_ctx(inode, gfp_flags); if (IS_ERR(ctx)) @@ -318,8 +320,9 @@ EXPORT_SYMBOL(fscrypt_encrypt_page); int fscrypt_decrypt_page(const struct inode *inode, struct page *page, unsigned int len, unsigned int offs, u64 lblk_num) { - if (!(inode->i_sb->s_cop->flags & FS_CFLG_OWN_PAGES)) - BUG_ON(!PageLocked(page)); + if (WARN_ON_ONCE(!PageLocked(page) && + !(inode->i_sb->s_cop->flags & FS_CFLG_OWN_PAGES))) + return -EINVAL; return fscrypt_do_page_crypto(inode, FS_DECRYPT, lblk_num, page, page, len, offs, GFP_NOFS); -- 2.20.1