Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2546800imm; Thu, 7 Jun 2018 12:30:29 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLK47xCACYGsWlWLIjP7PRhUiEBBe3l4RRlQVGUkg/zR1SzqpD1XIbBEi3iBy7MZC1zFPnr X-Received: by 2002:a17:902:aa01:: with SMTP id be1-v6mr3269091plb.296.1528399829496; Thu, 07 Jun 2018 12:30:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528399829; cv=none; d=google.com; s=arc-20160816; b=JbTx9uzDXvPLCNxeNUNDwop0q2mPJnksSTYhYjm4P0cXtd6fpP970G5c5NBSvWJY18 NyLEhxtQntTJyJyhvD4MEkKZy2MccX0Im0Sv9PYoeIpqIVOjB0n2T456yRSpP9yH/czc BUf9q4/4crOmACJOhCdG5fRnwzIgu7fmGqOVMXo0vhXbDujC3wqqG2N3kzIpkJKtOiyB SghL7SLMyWZiR8ieXNDAQHjZ8pmik5UIfkrWEDUtWjrVOw7TCSs7JdK3k+eFWR7xHrox 6IH4J+tmtQGe/FnrMa9HZP/0+8qyBGSARKWpHybKEV5D+Y9iujOXDtVE+ceEXZ00IkSs 6uPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=Jq4YMJMe/V5XMR5mZN+fjPZ8cGuphVOER0JybDH/Jp4=; b=JxFf3gB5aH08LIJ3pL7e0z6UfEEe7EVNK5H+ypkMldL8AlphsSG/8ylIhuPcwtJLyU KEC4w2m47KXbuf7vvHMKxA7R3itN/AIefqHkYYCEw9LdIGWgeIQnf3KZmfBBVfS+nugc BSjH33BD4eEO0p4Vz6GusCKadnsbZqdRzjORL4pStTYKvjMA79JYnVAQWxpbGD8lGrBW PwIQl+/vulmnys5UNKj3hg0u7amtqQqVO5iFMdzajukRFOEAlhcdS910kbt+p2Ki55Ym k3Uv8Kb41GqXphKBcOpuNtb656vywxh/X6dY/aDckk9rgYf5B/huTjdamkLB9WFlEsu9 B5Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=I47ecloT; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si54403738plw.519.2018.06.07.12.30.15; Thu, 07 Jun 2018 12:30:29 -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=@gmail.com header.s=20161025 header.b=I47ecloT; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932337AbeFGT2x (ORCPT + 99 others); Thu, 7 Jun 2018 15:28:53 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:37964 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932124AbeFGT2u (ORCPT ); Thu, 7 Jun 2018 15:28:50 -0400 Received: by mail-pg0-f67.google.com with SMTP id c9-v6so5221267pgf.5; Thu, 07 Jun 2018 12:28:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Jq4YMJMe/V5XMR5mZN+fjPZ8cGuphVOER0JybDH/Jp4=; b=I47ecloTcQpAv+ZaDQY9WKgZ111NYN9vrS+dw+QNVTX2XTiQ2UbDo+RFG9GN6ZU24v MtCKy2M82x2xekjTll1EySIEjNLpwDUy9mtr5G+ifAENQlf8rs3gzE2+Tdlt2x169W/g n5wFnCi+eIm2QRbQ1OV0mS3pV/Bh1m0RHD9R4+DHSrq1Aeiu6A0F1WnJ4yKaQ3fx+BF0 lC1MZ0ma5HNE4Dcyic717qLWXWyyi84zVj6n/Ln0VIrQ8jG7k7CUNVwSRQUVCbrU0o1H FQHkSv/jDg5BviObQq38RnApftU7l8LnzrNm5GjqeEnwqWUTIEcVOwIXMnenZ2jeKwpZ 0lWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Jq4YMJMe/V5XMR5mZN+fjPZ8cGuphVOER0JybDH/Jp4=; b=hnLTtn93DWwVzSo+Smy9FEVFq4sXt11YQYN1DdMruq0HgxXvm2fVBVZHjtapAMBzLU twE+kY1lWAs70ngYfAYHepiJE1oRJV1nqS59VrN9+bdKEb/3Jdku2Lor418+SXyWsh5D FcBczMIFRNDPE39sBLn1m9xe21ncaQty2nXuKzhGm4SgJuLCOFYK4QvM8wRUyaGwOzd0 /Z/ehmr2HV6m/gftMjaRXEKVa2GoWe7qaC0XdyTOoe64U437sbBsFC+SJeFl1p+QWNgg aCoQCPMSwzJPxSnhJQX6FInq4NDiegweqhghdxXq5FgN/SC/2DDtb2OvhPNo2pfry2dV 9s8w== X-Gm-Message-State: APt69E0GXqmSxlyaUP4H8VHBZy5ry8KSj3d6ou9862FZ3pz1g/53eJBw vjr+WKpSqeqY5XljoFOJNQg= X-Received: by 2002:a62:3889:: with SMTP id f131-v6mr2932595pfa.173.1528399730196; Thu, 07 Jun 2018 12:28:50 -0700 (PDT) Received: from gmail.com ([2620:15c:17:3:dc28:5c82:b905:e8a8]) by smtp.gmail.com with ESMTPSA id u1-v6sm18840364pgc.80.2018.06.07.12.28.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Jun 2018 12:28:49 -0700 (PDT) Date: Thu, 7 Jun 2018 12:28:48 -0700 From: Eric Biggers To: Kees Cook Cc: David Howells , James Morris , keyrings@vger.kernel.org, linux-security-module , linux-crypto , LKML , syzkaller-bugs@googlegroups.com, Tycho Andersen , Stephan Mueller , Eric Biggers Subject: Re: [PATCH] dh key: fix rounding up KDF output length Message-ID: <20180607192848.GD29665@gmail.com> References: <0000000000009c221d056e0cf53a@google.com> <20180607191201.97080-1-ebiggers3@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 07, 2018 at 12:16:16PM -0700, Kees Cook wrote: > On Thu, Jun 7, 2018 at 12:12 PM, Eric Biggers wrote: > > 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. > > round_up() vs roundup(). Wow, that's not confusing. :( I wonder if we > should rename the former to roundup_pow2() or something? Yes, it's very confusing, and I wish the names were clearer, or that there was one macro that just did the right thing (but then the power-of-2 optimization could only be done for constants, where it might not be necessary anyway). roundup_pow2() would still be confused with roundup_pow_of_two(), unfortunately. Eric