Received: by 10.213.65.68 with SMTP id h4csp130691imn; Mon, 12 Mar 2018 21:31:43 -0700 (PDT) X-Google-Smtp-Source: AG47ELt1z40x5LMDYCFZm6R+cy55a+FTHZSxMriu8yOWwYYTepfaS8pZpPsfRntzoLcbBL5HrEOa X-Received: by 10.99.96.19 with SMTP id u19mr7943713pgb.261.1520915503257; Mon, 12 Mar 2018 21:31:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520915503; cv=none; d=google.com; s=arc-20160816; b=yl6K6k50dYNJ0Wyol0BjXsA0mPfwkL+BMCRk2i97W8XJHn6o3ZNfhUtEI6/ZJnwyH8 gSmQSFLlJi3ff+Umy4zEvGY1aNmIBSJ79aifwDByhKUIpsZhV6dYIiynYaGQGubT6Cw4 SJxN7eJolqVuJMwfwE4xQal9DKNJf+9rcGPEDkPrwlcpanDlrkAGvKShcXejg8lzUnxL Nk13QvUaz/bdKH2IHmgOeBmHx7Cpp0cAXtHmY41u2reytNivHjwFwswqsOyh+xnCpTh0 PIz9vVLkwvMVsUPQPNAK95ODl9sWrMyX+QUpOtKFPVN/iB7oDyz/7WRGq+M/h7G+DtXK qr2Q== 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=7elmkvTp7D2Y1qk9MSRAVsX+pNnrR9P0PXvPX04BVgc=; b=B1neooXgGggDarfAfLdGWGNG1x8bqxt0LeykVtfPqYi5sDgSLlXP/exatzEpNnBEjz o5oi7a4RUyEJPijcnslwwzJuNIoOq0/ZQC8n0/PBt6hGzG8bbtgKwN/LpyRrb8alAq9J DXiqTVzeswxE0GLZLcpJKUkaZ6+b7qweI6Ylq4Nx4q0VSPM12VT8cUL+dGX5TJg2qH+j UXZmJUJiLQDVEm9VVGXjHzM39gXrBcbjOcfojkf+gG9u1lo+S1yklHZSMLDdU4KlquPT Tykeo+6DA7vsM/zEh7IPo6zdYymM6r5CjoVuOFNmicS0s/d26cXjVq87uitzYxW9wTa5 ViZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tycho-ws.20150623.gappssmtp.com header.s=20150623 header.b=EHR72MOv; 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 s71si6851933pfj.396.2018.03.12.21.31.29; Mon, 12 Mar 2018 21:31:43 -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=@tycho-ws.20150623.gappssmtp.com header.s=20150623 header.b=EHR72MOv; 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 S1751360AbeCME35 (ORCPT + 99 others); Tue, 13 Mar 2018 00:29:57 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:53806 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751432AbeCME3g (ORCPT ); Tue, 13 Mar 2018 00:29:36 -0400 Received: by mail-it0-f68.google.com with SMTP id w63so14033571ita.3 for ; Mon, 12 Mar 2018 21:29:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tycho-ws.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7elmkvTp7D2Y1qk9MSRAVsX+pNnrR9P0PXvPX04BVgc=; b=EHR72MOvvWBjSPt+OJVJLDCRVjLwDMAHF8tTAM7Y6/yPECxdMLqyPQqFSeVOHm2LjE Igvor20zc2PuLAl/68p90n+aAdCwW4OuPzmW03g5rmpirUpncJvEk/C/rPZI1znZoz6c Y705AmFlXz9g+ogqxO4BKp32KCPNCxnlgJIyUxR0b+LlrGbo+QL52cZlrUk+rxKH3WTa b8ypwvrDJ6mBSKk4F6JbE8XFpyr/gZ5Sp/Dn+rY3Ccts5kAoTZ4yHXfljyXKIVi7qc8W IBmowcXKfR9Jrkou4bAiM3xd2jaH8JIgVc+V98Mn/L260hD3IcI/ACf9EZlvag8+aak+ 40JQ== 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=7elmkvTp7D2Y1qk9MSRAVsX+pNnrR9P0PXvPX04BVgc=; b=hhb+6QqkQNdJSWxL4teoFT7MpxjewfoHbG9VGqO047wDyKEFn5z0A4rmdqtCtootLl t7slhmvGBqu1kM78+EQJ001dlrVF1Go3UwW/9T8W3YRpNm7Wi+CXqtc/ntEFATWe3oCJ 4sJ18Ncvbrmu0p7EN7d7HWBY7RrvZSpr5tRzmKR8wfcjou6uQwnEBQoHyGWnLZ/ULsOE ptYR6X+AzrsnqWjDwfSdR48Z/XASHbYMXipLoGwoL+TpjG1S4+AB3onQ00g2b0+kqgrS MrPN1tAMz9TJVP867Szpaf012PrV9vUqToD6hwSL6uAa9Q7QhDzUiiRSOCMjT0GkIZXg DUBA== X-Gm-Message-State: AElRT7FDtVZIlaaoTw3lXhrAfhET5jvjdR/k1EYg92JJp0LuzVuHFnsv tUckziZxuidLCJGsLdv6LJb+/Q== X-Received: by 10.36.170.6 with SMTP id b6mr11150178itf.148.1520915375204; Mon, 12 Mar 2018 21:29:35 -0700 (PDT) Received: from localhost.localdomain ([8.24.24.129]) by smtp.gmail.com with ESMTPSA id z67sm6279356ioz.37.2018.03.12.21.29.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Mar 2018 21:29:33 -0700 (PDT) From: Tycho Andersen To: David Howells Cc: keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, Tycho Andersen , James Morris , "Serge E. Hallyn" Subject: [PATCH 2/2] dh key: get rid of stack array allocation Date: Mon, 12 Mar 2018 22:29:07 -0600 Message-Id: <20180313042907.29598-2-tycho@tycho.ws> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180313042907.29598-1-tycho@tycho.ws> References: <20180313042907.29598-1-tycho@tycho.ws> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Similarly to the previous patch, we would like to get rid of stack allocated arrays: https://lkml.org/lkml/2018/3/7/621 In this case, we can also use a malloc style approach to free the temporary buffer, being careful to also use kzfree to free them (indeed, at least one of these has a memzero_explicit, but it seems like maybe they both should?). Signed-off-by: Tycho Andersen CC: David Howells CC: James Morris CC: "Serge E. Hallyn" --- security/keys/dh.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/security/keys/dh.c b/security/keys/dh.c index d1ea9f325f94..f02261b24759 100644 --- a/security/keys/dh.c +++ b/security/keys/dh.c @@ -162,19 +162,27 @@ static int kdf_ctr(struct kdf_sdesc *sdesc, const u8 *src, unsigned int slen, goto err; if (zlen && h) { - u8 tmpbuffer[h]; + u8 *tmpbuffer; size_t chunk = min_t(size_t, zlen, h); - memset(tmpbuffer, 0, chunk); + + err = -ENOMEM; + tmpbuffer = kzalloc(chunk, GFP_KERNEL); + if (!tmpbuffer) + goto err; do { err = crypto_shash_update(desc, tmpbuffer, chunk); - if (err) + if (err) { + kzfree(tmpbuffer); goto err; + } zlen -= chunk; chunk = min_t(size_t, zlen, h); } while (zlen); + + kzfree(tmpbuffer); } if (src && slen) { @@ -184,13 +192,20 @@ static int kdf_ctr(struct kdf_sdesc *sdesc, const u8 *src, unsigned int slen, } if (dlen < h) { - u8 tmpbuffer[h]; + u8 *tmpbuffer; + + err = -ENOMEM; + tmpbuffer = kzalloc(h, GFP_KERNEL); + if (!tmpbuffer) + goto err; err = crypto_shash_final(desc, tmpbuffer); - if (err) + if (err) { + kzfree(tmpbuffer); goto err; + } memcpy(dst, tmpbuffer, dlen); - memzero_explicit(tmpbuffer, h); + kzfree(tmpbuffer); return 0; } else { err = crypto_shash_final(desc, dst); -- 2.15.1