Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2870544imm; Tue, 4 Sep 2018 11:18:03 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZ23GQ3fQ+bz6DW15chmK6BKk3K8f9tCryCDkMPWvyyuhIoaik8lUaeYaJkgo6hAPqIbuDU X-Received: by 2002:a62:51c6:: with SMTP id f189-v6mr36372827pfb.7.1536085083929; Tue, 04 Sep 2018 11:18:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536085083; cv=none; d=google.com; s=arc-20160816; b=jhO4QRHrcDEc1Dlie/BgpDCsyB/+N2Ac/Xv7Ywo5A1Ivbu8DDzfoAFi/9siP8L4Or1 dNl6Dlh2mPl92QeamujebPF/vFTukgA98/BFbkouoifwcaMcy/hf/KCdvcUPXpdjGpsd 52xOGxsAWGTWmlkh2W7bQNMn3slsIjerzI5BCKbBmPaoSYoxrCAw9VQkP/z027ShiTBr PbXAmuEEZhSp2shkyX8qPw/FzM4JvGcIlsxOyaLAZMqve1XYZOom8+KrbRPAZjkXlUJ0 TvYd5BzHZ7oT5tEeOqGLpMhyE9RFEjZ1Dk3iqHHO9nWSb2B+YA90nVPMStwI8GKWka06 ut2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Grbq2zQ3A4RhONhGOZUwbxnQrSQ434BRDzK8+t1CT3o=; b=DVaQMlhUlJ3USTUHBn/fflZrbcypxnlGXqXujUYlVk4SMjIeXhdDPy7QV11yIihlNO 7EBFH/obfoQ02W9vh/j+Br7R81ztaLkmT5OpJWbw8eul+QxVyk+T8qicT/M3TB6cuxgy EoKB4L+V4IF4Cc68j1v778viIf930Y855hRK63PXuKHch54MWz7JFF924bofnPN2KnlX 4Ev66nSyaaIYxZv/4JJHP9A2+fAr/X4qxC5tJMXLmOeOrGHYEV6S+O/XQdyoPjP1Qhyh Rbj4O1gpjZjTTOcbnGgt7qcFLw04JnAFSiVPYHmrZ+OnfeB79Y2LAQXdx0hnQ/DQj5s0 M7JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ThtCkZ2Y; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r12-v6si20258180plo.105.2018.09.04.11.17.49; Tue, 04 Sep 2018 11:18:03 -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=@chromium.org header.s=google header.b=ThtCkZ2Y; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727447AbeIDWmt (ORCPT + 99 others); Tue, 4 Sep 2018 18:42:49 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:44247 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726961AbeIDWmt (ORCPT ); Tue, 4 Sep 2018 18:42:49 -0400 Received: by mail-pl1-f193.google.com with SMTP id ba4-v6so1998341plb.11 for ; Tue, 04 Sep 2018 11:16:34 -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=Grbq2zQ3A4RhONhGOZUwbxnQrSQ434BRDzK8+t1CT3o=; b=ThtCkZ2YkCZaLcEhmQ/Zr23+uw5rXcjk2HmjnCpWaiQIvxg13hkLbzdjgfEhbUn/VS KesgmKVo6v/JS1wbMSP6olTM9AOJEW9OnZQ1IzyfkVU9izj1FA/euGHLuooSpp6UR0if EN8fIByydxDx3Gu6VCAzBFpe2qp/cwtkiFyd0= 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=Grbq2zQ3A4RhONhGOZUwbxnQrSQ434BRDzK8+t1CT3o=; b=oJdcOppQ/lbUr+rFu4+JLYB0vca7AxbCY5AmpDQKjPoHth/Lqtf7ExqZLhEwuuUSuR Tjkthl3IR0cZGQYKAmlFmsPHcgJ5yAJxqGSPobQxhK/JmH2KoCVDyeg6ifJ1ANj43tks +jyMQdDZQ24ondjBQggyX0tLgFT8V1Qw2Nj7rMGXnD2na5KODiLHVrbxrmFY6nWKYESr KUoy1q/6g7nYADm+yz4J0R6wkqK+hGfa35kw2J8HjanWkqm4e0hQn5DTQg+N+NrDXFv1 woOW+FXOUwb9L5OJ6mHaBArXlRQQEgV3z+S+g1XabLlQUbwVDg8+ZinseTU1+t/wGq0R MT6g== X-Gm-Message-State: APzg51CuHakbGA0rQGTSPcM0YMF3wf1mtuxNesSveIjhefsyxes/rgNn cFIsBUJgabBbNZxEZNrRe797GA== X-Received: by 2002:a17:902:8a92:: with SMTP id p18-v6mr34176720plo.148.1536084994102; Tue, 04 Sep 2018 11:16:34 -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 r205-v6sm61545336pgr.11.2018.09.04.11.16.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Sep 2018 11:16:32 -0700 (PDT) From: Kees Cook To: Herbert Xu Cc: Kees Cook , Eric Biggers , Ard Biesheuvel , Gilad Ben-Yossef , Antoine Tenart , Boris Brezillon , Arnaud Ebalard , Corentin Labbe , Maxime Ripard , Chen-Yu Tsai , Christian Lamparter , Philippe Ombredanne , Jonathan Cameron , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/2] crypto: skcipher: Remove VLA usage for SKCIPHER_REQUEST_ON_STACK Date: Tue, 4 Sep 2018 11:16:29 -0700 Message-Id: <20180904181629.20712-3-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180904181629.20712-1-keescook@chromium.org> References: <20180904181629.20712-1-keescook@chromium.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Looking at instrumented tcrypt output, the largest is for lrw: crypt: testing lrw(aes) crypto_skcipher_set_reqsize: 8 crypto_skcipher_set_reqsize: 88 crypto_skcipher_set_reqsize: 472 [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Signed-off-by: Kees Cook --- include/crypto/internal/skcipher.h | 3 +++ include/crypto/skcipher.h | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/crypto/internal/skcipher.h b/include/crypto/internal/skcipher.h index d2926ecae2ac..6da811c0747e 100644 --- a/include/crypto/internal/skcipher.h +++ b/include/crypto/internal/skcipher.h @@ -130,6 +130,9 @@ static inline struct crypto_skcipher *crypto_spawn_skcipher( static inline int crypto_skcipher_set_reqsize( struct crypto_skcipher *skcipher, unsigned int reqsize) { + if (WARN_ON(reqsize > SKCIPHER_MAX_REQSIZE)) + return -EINVAL; + skcipher->reqsize = reqsize; return 0; diff --git a/include/crypto/skcipher.h b/include/crypto/skcipher.h index 2f327f090c3e..c48e194438cf 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 472 + #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 /** -- 2.17.1