From patchwork Wed Jun 20 19:04:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10478527 X-Patchwork-Delegate: snitzer@redhat.com 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 8E77A60230 for ; Wed, 20 Jun 2018 19:05:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7EC9D28DE2 for ; Wed, 20 Jun 2018 19:05:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 70AE828DE6; Wed, 20 Jun 2018 19:05: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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 140AB28DE7 for ; Wed, 20 Jun 2018 19:05:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4C2B3369D2; Wed, 20 Jun 2018 19:05:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 21CA17555D; Wed, 20 Jun 2018 19:05:07 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 76DEB180053B; Wed, 20 Jun 2018 19:05:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w5KJ4VGB023592 for ; Wed, 20 Jun 2018 15:04:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6CC537554C; Wed, 20 Jun 2018 19:04:31 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 65C2C6C21A for ; Wed, 20 Jun 2018 19:04:31 +0000 (UTC) Received: from mail-pf0-f193.google.com (mail-pf0-f193.google.com [209.85.192.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 784313082A38 for ; Wed, 20 Jun 2018 19:04:30 +0000 (UTC) Received: by mail-pf0-f193.google.com with SMTP id z24-v6so254148pfe.7 for ; Wed, 20 Jun 2018 12:04:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=TKyIVRr8+ICLpC4JInXUgLaGQojITv7p61XOFNO0BZU=; b=XoJKT0hS5T9iQ/8KrBq9m0KJmPh49hioryUDDy+cFEEWOiYt6MpLpXOWoNsAPMjiN8 +A+lP5/nWCMTAdTmtzFu1oN0O6Fafw09tmZggXjvzHgNHfATilDVKQRIvnhk0hEJ8jvK etYQqc7EulfIXJA/7rTwZWqXG3kH7YOLCBD1A= 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=TKyIVRr8+ICLpC4JInXUgLaGQojITv7p61XOFNO0BZU=; b=L+mmPqpffQF/L4kf6j6k4MURb+tnvJeknBCDchadOBc6Ic2SS6q1s65IRBfPZBqW+2 69ntDx2T5EIO6ttbdGUmT0ice1FS97RgR6fqbGmyCYsgl3J3dKDkKNbf7TP8jPJLKngc dy1VtBlBG2PNh/ocJobR3tAwGZ5cVoA6c7IFA17DsmpTlndd4+cvqqi8nenxRVpbQBM8 01Hnv6suYq/1ZBi1yfL4bML2ZpVM6SXo1hB8Ij8Oi9vx9WYg50kXRqVGI/ZXEJtGEhNw B0pvPX/W+Rd+NZuios+BWjZAQRWiPdcGrhtLQkkNkYEqrGpXVZ0W80xSb5fJJ10xRU/a vCyQ== X-Gm-Message-State: APt69E28Czq8Dv36yCwNfwQmmxad3qHr1aBM3+pI2RJO8ushor8/+80U 1xIB9zekO6dXvA2BpXUJqgU8SA== X-Google-Smtp-Source: ADUXVKLcenlKNcmHVjLubCj/4A8sqsyfH+EHc8VkMCQQEIfCdxY+O0RqOM2GoF0ySoDxxigs00b6Ug== X-Received: by 2002:a62:8a83:: with SMTP id o3-v6mr24265418pfk.12.1529521469756; Wed, 20 Jun 2018 12:04:29 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id x2-v6sm4589892pgq.33.2018.06.20.12.04.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Jun 2018 12:04:27 -0700 (PDT) From: Kees Cook To: Herbert Xu Date: Wed, 20 Jun 2018 12:04:08 -0700 Message-Id: <20180620190408.45104-12-keescook@chromium.org> In-Reply-To: <20180620190408.45104-1-keescook@chromium.org> References: <20180620190408.45104-1-keescook@chromium.org> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 20 Jun 2018 19:04:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 20 Jun 2018 19:04:30 +0000 (UTC) for IP:'209.85.192.193' DOMAIN:'mail-pf0-f193.google.com' HELO:'mail-pf0-f193.google.com' FROM:'keescook@chromium.org' RCPT:'' X-RedHat-Spam-Score: -0.112 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS) 209.85.192.193 mail-pf0-f193.google.com 209.85.192.193 mail-pf0-f193.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.45 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: dm-devel@redhat.com Cc: Giovanni Cabiddu , Kees Cook , Arnd Bergmann , Eric Biggers , Mike Snitzer , "Gustavo A. R. Silva" , qat-linux@intel.com, linux-kernel@vger.kernel.org, dm-devel@redhat.com, linux-crypto@vger.kernel.org, Lars Persson , Tim Chen , "David S. Miller" , Alasdair Kergon , Rabin Vincent Subject: [dm-devel] [PATCH 11/11] crypto: skcipher: Remove VLA usage for SKCIPHER_REQUEST_ON_STACK X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 20 Jun 2018 19:05:08 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP In the quest to remove all stack VLA usage from the kernel[1], this caps the skcipher request size similar to other limits and adds a sanity check at registration. [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Signed-off-by: Kees Cook --- include/crypto/internal/skcipher.h | 1 + include/crypto/skcipher.h | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/crypto/internal/skcipher.h b/include/crypto/internal/skcipher.h index e42f7063f245..5035482cbe68 100644 --- a/include/crypto/internal/skcipher.h +++ b/include/crypto/internal/skcipher.h @@ -130,6 +130,7 @@ static inline struct crypto_skcipher *crypto_spawn_skcipher( static inline void crypto_skcipher_set_reqsize( struct crypto_skcipher *skcipher, unsigned int reqsize) { + BUG_ON(reqsize > SKCIPHER_MAX_REQSIZE); skcipher->reqsize = reqsize; } diff --git a/include/crypto/skcipher.h b/include/crypto/skcipher.h index 2f327f090c3e..25294d0089b2 100644 --- a/include/crypto/skcipher.h +++ b/include/crypto/skcipher.h @@ -139,9 +139,11 @@ struct skcipher_alg { struct crypto_alg base; }; +#define SKCIPHER_MAX_REQSIZE (PAGE_SIZE / 8) + #define SKCIPHER_REQUEST_ON_STACK(name, tfm) \ char __##name##_desc[sizeof(struct skcipher_request) + \ - crypto_skcipher_reqsize(tfm)] CRYPTO_MINALIGN_ATTR; \ + SKCIPHER_MAX_REQSIZE] CRYPTO_MINALIGN_ATTR; \ struct skcipher_request *name = (void *)__##name##_desc /**