Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp5316901imm; Tue, 26 Jun 2018 09:13:04 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJCgoFieSXwc9nOtvkQgJgFCqGiJsesdBLdnpcfiqhRnsvLrMYfDcjFNSY7bgARJYKi3Y7s X-Received: by 2002:a63:750c:: with SMTP id q12-v6mr1916532pgc.165.1530029584561; Tue, 26 Jun 2018 09:13:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530029584; cv=none; d=google.com; s=arc-20160816; b=hHdQz2k8iEhFTkCO8drOj9vV9oK36FqW0RC2dRimUZJF9ibD028H98/3RHxvdGbyfK 4UL2/htKSXxge147hvCosTv6r2DB8zZ+u0pXPclQqAtnRT1qMYwOufombSKey4yGl1Eh qaoHISikUvTXZ7zkQK63oDn899xKmS5C+ZBVb+t81cb8XPf0heTcg20+8CWgv/6vaNsT dGV5guaeNhd/KvXvUTPKsfDWge3raQ0nhQtA3qDMwsGIosWR7KzWhiv7lF9YeI3766z9 8wmC0VT0UyAYZZ/4hYZ4Y4rXaDj3pXw37P6zRyLNAhdbFnp2yiF1L1uUrc6zaGliMLJA SFtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization:arc-authentication-results; bh=WcpaP/QLX5gxupxvbPIkR9D8XunFjJcAWAGfchzpDdk=; b=rbI3qBqu1b8uAZEJ0hp22LWD451Mhm35595OukztYTr/EirlVeNvhMMc8j+k7g/ZkV cXeUG0tvwyYD/TQaqzHd8+nzF5Nz2Rrh4RnWxhylwF5hcEF8KykrkJeC5Hd8D5l/+Two wc6zTxmMGtckWdVB34ISJ50sqXjXsSXwY7eLfI0ad9KqiyhBB3Iiszr3O4BnHYJlzGns emPa0kTWcfEQiG0JOkNfMPB9iJyBHJUNqDd+QlBzsUcxJu/a9g/0i9TL8Ixzd2ehaGiV DXXWLknbgnAIwcQ749qVqc6VQoNvpJszypa/godjpKGGQWZ5cMg0ftPs7hzpZ3VFtgyJ NShw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a10-v6si1552325pgt.552.2018.06.26.09.12.50; Tue, 26 Jun 2018 09:13:04 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752627AbeFZP7w (ORCPT + 99 others); Tue, 26 Jun 2018 11:59:52 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44758 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752544AbeFZP7u (ORCPT ); Tue, 26 Jun 2018 11:59:50 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DA31B83207; Tue, 26 Jun 2018 15:59:49 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-238.rdu2.redhat.com [10.10.120.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id BEAD72026E0E; Tue, 26 Jun 2018 15:59:47 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 3/3] dh key: fix rounding up KDF output length From: David Howells To: jmorris@namei.org Cc: Tycho Andersen , Kees Cook , Eric Biggers , syzbot+29d17b7898b41ee120a5@syzkaller.appspotmail.com, syzbot+8a608baf8751184ec727@syzkaller.appspotmail.com, linux-kernel@vger.kernel.org, dhowells@redhat.com, linux-security-module@vger.kernel.org, keyrings@vger.kernel.org, syzbot+486f97f892efeb2075a3@syzkaller.appspotmail.com, syzbot+d04e58bd384f1fe0b112@syzkaller.appspotmail.com Date: Tue, 26 Jun 2018 16:59:46 +0100 Message-ID: <153002878692.31726.13651817141660735426.stgit@warthog.procyon.org.uk> In-Reply-To: <153002876741.31726.8580751276453556884.stgit@warthog.procyon.org.uk> References: <153002876741.31726.8580751276453556884.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 26 Jun 2018 15:59:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 26 Jun 2018 15:59:49 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'dhowells@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Biggers Commit 383203eff718 ("dh key: get rid of stack allocated array") changed kdf_ctr() to assume that the length of key material to derive is a multiple of the digest size. The length was supposed to be rounded up accordingly. However, the round_up() macro was used which only gives the correct result on power-of-2 arguments, whereas not all hash algorithms have power-of-2 digest sizes. In some cases this resulted in a write past the end of the 'outbuf' buffer. Fix it by switching to roundup(), which works for non-power-of-2 inputs. Reported-by: syzbot+486f97f892efeb2075a3@syzkaller.appspotmail.com Reported-by: syzbot+29d17b7898b41ee120a5@syzkaller.appspotmail.com Reported-by: syzbot+8a608baf8751184ec727@syzkaller.appspotmail.com Reported-by: syzbot+d04e58bd384f1fe0b112@syzkaller.appspotmail.com Fixes: 383203eff718 ("dh key: get rid of stack allocated array") Signed-off-by: Eric Biggers Acked-by: Kees Cook Acked-by: Tycho Andersen --- security/keys/dh.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/security/keys/dh.c b/security/keys/dh.c index f7403821db7f..b203f7758f97 100644 --- a/security/keys/dh.c +++ b/security/keys/dh.c @@ -142,6 +142,8 @@ static void kdf_dealloc(struct kdf_sdesc *sdesc) * The src pointer is defined as Z || other info where Z is the shared secret * from DH and other info is an arbitrary string (see SP800-56A section * 5.8.1.2). + * + * 'dlen' must be a multiple of the digest size. */ static int kdf_ctr(struct kdf_sdesc *sdesc, const u8 *src, unsigned int slen, u8 *dst, unsigned int dlen, unsigned int zlen) @@ -205,8 +207,8 @@ static int keyctl_dh_compute_kdf(struct kdf_sdesc *sdesc, { uint8_t *outbuf = NULL; int ret; - size_t outbuf_len = round_up(buflen, - crypto_shash_digestsize(sdesc->shash.tfm)); + size_t outbuf_len = roundup(buflen, + crypto_shash_digestsize(sdesc->shash.tfm)); outbuf = kmalloc(outbuf_len, GFP_KERNEL); if (!outbuf) {