Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp996876imm; Thu, 13 Sep 2018 10:56:27 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbK6jT/lBbdh4tZF6RpH37Sz+jwypB0L9SziwHJeBugxqG00rtZ2JmKGGrr8Nlas9pIIqfk X-Received: by 2002:a62:8a4f:: with SMTP id y76-v6mr8447483pfd.233.1536861387858; Thu, 13 Sep 2018 10:56:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536861387; cv=none; d=google.com; s=arc-20160816; b=RuBZH0a4cMmFZME81mUzP17dErG/jqctxiEsi35IO1SDai1lE0BkZmM6Pwe4Z8F40r 2zerj96WukLWCQsfqitTT/bybvCZ8hIoWi0cC3H5xJ5aE0QoMxb1324SyEBppSJxibqx BuXF04PYtbbsChKCfvW9xlNza51Naky7g7ooIdHfXgAFiUs8+jIsdGdMA3a8vV2ilY9y gE1ZUO4kEpLeb7iXIHndV/As3vdIgZJ5oORWWAbJc4fzGHTSuFD6ytutr4uuoAjV6XmV fFB8ZAOv60rAVtZL2iYGIAXo9L/+9xTNOiVYW12O88e0f0uqST7a0j3nUstp2WHCptTj AhMQ== 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; bh=JqCb1HtbW334eMXG8YqwZ7mJaN5FmFogtdKjA+hx0qA=; b=uNT+0RXwcJ6adLu/lyLVaMxPNArK9MiYsy+9XqPnJP12Pyn+zUJNUcBQQc6J2W3YMe LnEETJmrNcXNaqb9IOZnKr6xL8cjndI2iQ7D0IUdFMZz9xUNj0DPS5RtUD0ra9l89HeJ pslMWqtuVRgh266W2IImowWh5ZzrGjlnkm8TH01lflq4yFFicVXOnqhwKuSGK3kT9WPh ihdIueODcj7fRXdFchXhMxGwQUFwHoEyWP541Wrq9CDN6Yhn6VPyQ1TY5gKc3ez2plLy MPQs+1nXw3gHA8cM0rteHNyepB+f7zfbzh/x0d81kC4ClVrkzhjOIX59ZpUyK4OOMu8F q+/g== 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 t80-v6si4721118pfk.228.2018.09.13.10.56.12; Thu, 13 Sep 2018 10:56:27 -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 S1727847AbeIMXFR (ORCPT + 99 others); Thu, 13 Sep 2018 19:05:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34862 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726914AbeIMXFR (ORCPT ); Thu, 13 Sep 2018 19:05:17 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 248ED30A7699; Thu, 13 Sep 2018 17:54:44 +0000 (UTC) Received: from localhost (unknown [10.18.25.149]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1EBE819936; Thu, 13 Sep 2018 17:54:40 +0000 (UTC) Date: Thu, 13 Sep 2018 13:54:39 -0400 From: Mike Snitzer To: Kees Cook Cc: Herbert Xu , Eric Biggers , Ard Biesheuvel , Giovanni Cabiddu , Alasdair Kergon , Tudor-Dan Ambarus , Andrew Morton , Thomas Gleixner , Geert Uytterhoeven , Arnd Bergmann , Will Deacon , Rasmus Villemoes , David Woodhouse , Matthew Wilcox , "David S. Miller" , "Gustavo A. R. Silva" , linux-crypto@vger.kernel.org, dm-devel@redhat.com, qat-linux@intel.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v8 5/9] dm: Remove VLA usage from hashes Message-ID: <20180913175439.GA5414@redhat.com> References: <20180807211843.47586-1-keescook@chromium.org> <20180807211843.47586-6-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180807211843.47586-6-keescook@chromium.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 13 Sep 2018 17:54:44 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 07 2018 at 5:18pm -0400, Kees Cook wrote: > In the quest to remove all stack VLA usage from the kernel[1], this uses > the new HASH_MAX_DIGESTSIZE from the crypto layer to allocate the upper > bounds on stack usage. > > [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com > > Signed-off-by: Kees Cook > --- > drivers/md/dm-integrity.c | 23 +++++++++++++++++------ > drivers/md/dm-verity-fec.c | 5 ++++- > 2 files changed, 21 insertions(+), 7 deletions(-) > > diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c > index 86438b2f10dd..884edd7cf1d0 100644 > --- a/drivers/md/dm-integrity.c > +++ b/drivers/md/dm-integrity.c > @@ -521,7 +521,12 @@ static void section_mac(struct dm_integrity_c *ic, unsigned section, __u8 result > } > memset(result + size, 0, JOURNAL_MAC_SIZE - size); > } else { > - __u8 digest[size]; > + __u8 digest[HASH_MAX_DIGESTSIZE]; > + > + if (WARN_ON(size > sizeof(digest))) { > + dm_integrity_io_error(ic, "digest_size", -EINVAL); > + goto err; > + } > r = crypto_shash_final(desc, digest); > if (unlikely(r)) { > dm_integrity_io_error(ic, "crypto_shash_final", r); > @@ -1244,7 +1249,7 @@ static void integrity_metadata(struct work_struct *w) > struct bio *bio = dm_bio_from_per_bio_data(dio, sizeof(struct dm_integrity_io)); > char *checksums; > unsigned extra_space = unlikely(digest_size > ic->tag_size) ? digest_size - ic->tag_size : 0; > - char checksums_onstack[ic->tag_size + extra_space]; > + char checksums_onstack[HASH_MAX_DIGESTSIZE]; > unsigned sectors_to_process = dio->range.n_sectors; > sector_t sector = dio->range.logical_sector; > > @@ -1253,8 +1258,14 @@ static void integrity_metadata(struct work_struct *w) > > checksums = kmalloc((PAGE_SIZE >> SECTOR_SHIFT >> ic->sb->log2_sectors_per_block) * ic->tag_size + extra_space, > GFP_NOIO | __GFP_NORETRY | __GFP_NOWARN); > - if (!checksums) > + if (!checksums) { > checksums = checksums_onstack; > + if (WARN_ON(extra_space && > + digest_size > sizeof(checksums_onstack))) { > + r = -EINVAL; > + goto error; > + } > + } > > __bio_for_each_segment(bv, bio, iter, dio->orig_bi_iter) { > unsigned pos; Given the length of the kmalloc() just prior to this new WARN_ON() line I'm not seeing why you've elected to split the WARN_ON across multiple lines. But that style nit aside: Acked-by: Mike Snitzer