From patchwork Tue Mar 13 04:29:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tycho Andersen X-Patchwork-Id: 10277763 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 8F44D6038F for ; Tue, 13 Mar 2018 04:29:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 953C328C47 for ; Tue, 13 Mar 2018 04:29:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8782828D17; Tue, 13 Mar 2018 04:29:56 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 B706328C47 for ; Tue, 13 Mar 2018 04:29:55 +0000 (UTC) Received: (qmail 3694 invoked by uid 550); 13 Mar 2018 04:29:49 -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 3461 invoked from network); 13 Mar 2018 04:29:47 -0000 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=atclaWlKtx2Otgpu2FtgFnux474MS5g0Vpnh9of4xRbuddBQAwT3xwTc6LQ9Gapwiz PDz739/KflHkzTkYY3P9Mv/qcFwZf10tcczzMDlQDwvl7hnJ5XvYNTTBs+Xcj1yqJzdz 8A8aSZjzhQM4kjVZDiXjN3jR4ROO7AmkQQZnfXlAGsDeT9QszCKyn+C5t2yyntcpD0+o aZvvjI3W1Re4sL9TMiFtahxZllyeQJIKixb+x8RNkLzdsD7Ksc4lte2eTwobAxXWW4dT CgwcCeCqLEASlI8tYWFokeVGnYiGz8Pryoji8D9Ht3v0kWYM2x77u01c5brFh/75uFiu hlhg== X-Gm-Message-State: AElRT7EOHhy19LQJlJYgNyXTYiHPqPgu25b7o2VLG0ZVdZvm5MblPjuU t+fVMTsiSCaQ4zxHMcjaO4jzGw== X-Google-Smtp-Source: AG47ELtJZ9B/T0yan2qWhBrzSYdzyId91nvl3fmB+A6lXOlMzyzXhXbR7omrv1Gdk1FO95DQNab2IA== X-Received: by 10.36.170.6 with SMTP id b6mr11150178itf.148.1520915375204; Mon, 12 Mar 2018 21:29:35 -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> X-Virus-Scanned: ClamAV using ClamSMTP 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" Acked-by: Serge 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);