From patchwork Mon Apr 9 13:54:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Salvatore Mesoraca X-Patchwork-Id: 10331395 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 498186037F for ; Mon, 9 Apr 2018 13:56:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3AF9928B59 for ; Mon, 9 Apr 2018 13:56:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E7C728B60; Mon, 9 Apr 2018 13:56:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 50AD728B59 for ; Mon, 9 Apr 2018 13:56:08 +0000 (UTC) Received: (qmail 21634 invoked by uid 550); 9 Apr 2018 13:55:10 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 21514 invoked from network); 9 Apr 2018 13:55:09 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hL2osvmSw3S+5hhTzGihfdv/1tHo1fUxHNZ4oL5PviA=; b=KFkpUjSzjQgGXebvnVEPYSHDP53/vG6b443ENZ+3Ui8QCfHW3V50l8cEzNmD1VglqW sVB0XTwz9aZWvLoCLG91YdDhaiKLZr72O60+xeMNmfhD2iVOy7AVHji/kaEsLXkTSBPG W1cbNUfNafNPge51Kco95K1TeRBJL08Wk0W7ElVgcZ0NvXfyIvLHST/moNK8ZCUk1ia6 BgWQ8jJUZemBvBKP3VT+PLUMmHtPr+ELPBG2Gtx2STiSKVd95de5fLxCwVFDvdF2+ZTF uEFzErAnyrUxC78k+AxPNW1KjVFmQV37T3EFF2DAzsWK0/GgRALx+Qr2XvXedArqk8vR utvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hL2osvmSw3S+5hhTzGihfdv/1tHo1fUxHNZ4oL5PviA=; b=s3CCjunVc5kZcTMR5Qpxd10De9NrbzNSVZD9U7pTduE3BSinLLcNqxQ/AVEh9RZKd2 WxmIRbHOvh+wOSPd8EIbsxZ6PskTsYTxzkWhAtSq3sisea+pvS7MUKtuvvFhDUHMrfiv 5ev7JMd+gzk11YcSavLUAofvOmlFCMlGNI6ZpPAWYeRTcDCOOnzpAaEEjG9s/nnlPs4z 5DTgQll9C1uOl2SSgiq0GlsVJKDRIH1+wZ3k8i0a/Tx6b0tN3RNe2tM3qG+bE5RdUL2U zg+TGbwKPnZ5fOOi6tRn87ZjufDvVuwoXGe9hW881kRxbNJpl8WfOWYUY11yxqNtXwMO PRlQ== X-Gm-Message-State: ALQs6tAhE5QPzzunAyy+xcMnHhNe6lY+2SALPAsGbbiKrXh4I9UM8dl+ Qw5U+4FAfqW0OUwJz0HqSGQ= X-Google-Smtp-Source: AIpwx49RMf5dMMGBARdbopYvkbFUj0BGwIkimUXP15CErVPWsUb080PTgzGOlhBJvFN6Ll4/hL2XKg== X-Received: by 10.28.131.2 with SMTP id f2mr50860wmd.111.1523282098235; Mon, 09 Apr 2018 06:54:58 -0700 (PDT) From: Salvatore Mesoraca To: linux-kernel@vger.kernel.org Cc: kernel-hardening@lists.openwall.com, linux-crypto@vger.kernel.org, "David S. Miller" , Herbert Xu , Kees Cook , Salvatore Mesoraca , Eric Biggers , Laura Abbott Subject: [PATCH v2 1/2] crypto: api - laying defines and checks for statically allocated buffers Date: Mon, 9 Apr 2018 15:54:46 +0200 Message-Id: <1523282087-22128-2-git-send-email-s.mesoraca16@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1523282087-22128-1-git-send-email-s.mesoraca16@gmail.com> References: <1523282087-22128-1-git-send-email-s.mesoraca16@gmail.com> X-Virus-Scanned: ClamAV using ClamSMTP In preparation for the removal of VLAs[1] from crypto code. We create 2 new compile-time constants: all ciphers implemented in Linux have a block size less than or equal to 16 bytes and the most demanding hw require 16 bytes alignment for the block buffer. We also enforce these limits in crypto_check_alg when a new cipher is registered. [1] http://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Signed-off-by: Salvatore Mesoraca --- crypto/algapi.c | 10 ++++++++++ include/crypto/algapi.h | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/crypto/algapi.c b/crypto/algapi.c index 2a0271b..c0755cf 100644 --- a/crypto/algapi.c +++ b/crypto/algapi.c @@ -10,6 +10,7 @@ * */ +#include #include #include #include @@ -59,6 +60,15 @@ static int crypto_check_alg(struct crypto_alg *alg) if (alg->cra_blocksize > PAGE_SIZE / 8) return -EINVAL; + if (!alg->cra_type && (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) == + CRYPTO_ALG_TYPE_CIPHER) { + if (alg->cra_alignmask > MAX_CIPHER_ALIGNMASK) + return -EINVAL; + + if (alg->cra_blocksize > MAX_CIPHER_BLOCKSIZE) + return -EINVAL; + } + if (alg->cra_priority < 0) return -EINVAL; diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index 1aba888..bd5e8cc 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h @@ -17,6 +17,14 @@ #include #include +/* + * Maximum values for blocksize and alignmask, used to allocate + * static buffers that are big enough for any combination of + * ciphers and architectures. + */ +#define MAX_CIPHER_BLOCKSIZE 16 +#define MAX_CIPHER_ALIGNMASK 15 + struct crypto_aead; struct crypto_instance; struct module;