Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9988277ybi; Wed, 24 Jul 2019 13:38:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqxwg7HctZxRDA9qx2adFmtkJm4a+04TOp+GacAbiobR5qiHrU0xPBvjINjqtMkEwoQO6sKd X-Received: by 2002:a17:902:a413:: with SMTP id p19mr88197428plq.134.1564000689583; Wed, 24 Jul 2019 13:38:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564000689; cv=none; d=google.com; s=arc-20160816; b=oBuQkT8tFrxKSlD9tODOtweDD1IUAHAZICB3hn3cbNDchnn9/Pq+yhyMMCYx7Tdspr uRng6woP+eHl/gWfFmLv6SJJDKJ8dT6Evecf9epBto6eUSXgPwyCPeewi6EsO+PZ9gFz kDMiVoAqk4WTkWn/tgx9vLjJFeMtt5xMaCjCCkx5fd2P7Bl1mLJSDValfVPatf3ZC9fs 9BFaqkw4IEolZ/ru+aPeszDN9BMNx2oKjhxBGdyWb2iy3zFGvPhGDvuvoWPCb+cWWjCc DJ3STf1r5AVrDf0XLbM5+jkSCP9r9DK/aiiGCyxgztHFrEIrIr9DbCKMdIF6xf7Jfa16 S42w== 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=Q+7IsbR0RD1iZdIED2CvbrHSZvmHLFuXuyNyzA5ZY14=; b=F+pfh5oEbAN+dSQoN4cvdLuc/7TES2Rz9kI0HPjcOiz7KYIV7VvXwT6otD9NnwRvyO VPXMsYxbibIGQaKDpUbRqQpaZQFKmF0CmIP7spQ3mo0qeavuWOIuXE28cEhmr/PUWE5C 89QOpAGSBFeZBE3ak1lwkI1up0d9w0B6NE+tgHmnkO66n9aBpTM0gbbnWNNDQazZgbok NrWIGHdK867bt4tyAyNKoeGK/0rpPwx9Yv/JvWSkyf85zB1MSAa2ayXhv24KqC7DsAtu EaH+C5L77yrzjcHzN4DimUlZV5+e2/AxK3g974tOd+VxTa5nL8c29QVtueiuiz5jmhh9 bFIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0mFnHh71; 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 q7si17077019pgk.456.2019.07.24.13.37.55; Wed, 24 Jul 2019 13:38:09 -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=0mFnHh71; 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 S1729122AbfGXTYm (ORCPT + 99 others); Wed, 24 Jul 2019 15:24:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:41062 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729113AbfGXTYk (ORCPT ); Wed, 24 Jul 2019 15:24:40 -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 07D2F21951; Wed, 24 Jul 2019 19:24:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563996279; bh=YdVFeD9iwBhlfqUWMHkADc9hdkdRNv754zqUD2b93yY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0mFnHh71ZPz+vcTCYegYBnX9KjOeRhvMnOTwOMEf3fc5qlXKCcfueIdOntgwVoUtg UdWGdpSUwgmhwusYlNOedH6AFKbF2RBGMXJk/iLmrxP0K94NH98Ie1W2gydTt28qmC zb3RsltSRj9eM/SHndrMyam40yS9qRsi/LWNhSbw= 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 5.2 043/413] fscrypt: clean up some BUG_ON()s in block encryption/decryption Date: Wed, 24 Jul 2019 21:15:34 +0200 Message-Id: <20190724191738.663016470@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@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 335a362ee446..6f753198eeef 100644 --- a/fs/crypto/crypto.c +++ b/fs/crypto/crypto.c @@ -154,7 +154,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; fscrypt_generate_iv(&iv, lblk_num, ci); @@ -238,8 +241,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, @@ -251,7 +252,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(gfp_flags); if (IS_ERR(ctx)) @@ -299,8 +301,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