Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9966475ybi; Wed, 24 Jul 2019 13:11:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqyB7y9wKdPs8IQfTguke4EWtFIqbS0ncthNreWDDJQlH0SwoERhMablqMqj9iLmHM1BMGi+ X-Received: by 2002:a17:902:8a94:: with SMTP id p20mr87166819plo.312.1563999119015; Wed, 24 Jul 2019 13:11:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563999119; cv=none; d=google.com; s=arc-20160816; b=aVMr6prtC8XAKjp2i4ksEQYd5f11wixZyCyrjBsvxneG1z/aRsxWwp1hxox71R4caO 0bm4zm7KSo5gw3/CSvVvYf8qI/W8gLUJklcYNkp3nDqv/VIwt/78pzgdty3wxsFNyqG6 QM7tTNo9dt5jmdG4+JorW6x9klgXiKubpywY3CGXEgOLuIUFrK1EdpeSyY5es04PtuR4 JaR4Ni9dnnGdZ2ZgdGpRQGVgNxks7LJFgZvXN9PnHAPtlA5+X4+tfH0DmTsJpu1dLID+ 5l+bUfIO4RChCFNqV1Nxs9mI3ahIxMcSqZkExUu5jcCdjNxCwj5m6Uf1hCPG9dUiBFYT d6rg== 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=ocrERbzIjLsObmFQiFIZiy7UFm2AhHGr9/+NZQxapdE=; b=uPCtt43ju3Gsazfmso1ArgYGMNhLVpoO1lw6q/ppRvNmyXRLbdQECP00Qei1YALYrq 8EkHOwiatkIWTLj3Psw+lIKeMUNGglG7B5L8+JK6wWeC+pFDCMXJ+cfhWhgj5hun8Upd begLb2yUvelDJKj3aY4gpT47HfcFRq78FWu44nw73BHlp7ap00yybhRDVJePp5878PWi 5bPMriaFyquu1jD9xZvZtCAZ98sMlF3QDGlwIzHESDeEo5yJU+HQDULn+DD69I6fTyxU 57sx67hzMDhDJavN520ti0UAHwiz/ZreADpnjmuu9UVCuG0Km7TNoW8E2mXEZIbn8OkU vLFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="z/D0k9a/"; 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 t63si14482601pfb.5.2019.07.24.13.11.44; Wed, 24 Jul 2019 13:11:59 -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="z/D0k9a/"; 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 S2392489AbfGXUI0 (ORCPT + 99 others); Wed, 24 Jul 2019 16:08:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:51980 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405489AbfGXUCV (ORCPT ); Wed, 24 Jul 2019 16:02:21 -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 34D6B214AF; Wed, 24 Jul 2019 20:02:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563998540; bh=n6jo13Xzf1F/u/wDvFxu1/huCHM/JnEWMVmTrCAzpu8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=z/D0k9a/dRqsP/pi+0PfNUCt8mBJVWHesHgmgXh20tYHG+ZdhF0ELl+L+1bPTlQlf /ergPE3OsHzN6KKWxHM9enPj7JGEKWix70KuZYIZm5FnjS8SgSuhx1W7tEInWZM3q5 YoxzW9AQ1mlPAozCvqbXY2c08EcQSYT2TJJp/jwQ= 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.19 029/271] fscrypt: clean up some BUG_ON()s in block encryption/decryption Date: Wed, 24 Jul 2019 21:18:18 +0200 Message-Id: <20190724191657.682862679@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191655.268628197@linuxfoundation.org> References: <20190724191655.268628197@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 0f46cf550907..c83ddff3ff4a 100644 --- a/fs/crypto/crypto.c +++ b/fs/crypto/crypto.c @@ -149,7 +149,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); @@ -241,8 +244,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, @@ -254,7 +255,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)) @@ -302,8 +304,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