From: Mike Snitzer <snitzer@redhat.com>
To: Kees Cook <keescook@chromium.org>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
Eric Biggers <ebiggers@google.com>,
Ard Biesheuvel <ard.biesheuvel@linaro.org>,
Giovanni Cabiddu <giovanni.cabiddu@intel.com>,
Alasdair Kergon <agk@redhat.com>,
Tudor-Dan Ambarus <tudor.ambarus@microchip.com>,
Andrew Morton <akpm@linux-foundation.org>,
Thomas Gleixner <tglx@linutronix.de>,
Geert Uytterhoeven <geert@linux-m68k.org>,
Arnd Bergmann <arnd@arndb.de>, Will Deacon <will.deacon@arm.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
David Woodhouse <dwmw@amazon.co.uk>,
Matthew Wilcox <willy@infradead.org>,
"David S. Miller" <davem@davemloft.net>,
"Gustavo A. R. Silva" <gustavo@embeddedor.com>,
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
Date: Thu, 13 Sep 2018 13:54:39 -0400 [thread overview]
Message-ID: <20180913175439.GA5414@redhat.com> (raw)
In-Reply-To: <20180807211843.47586-6-keescook@chromium.org>
On Tue, Aug 07 2018 at 5:18pm -0400,
Kees Cook <keescook@chromium.org> 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 <keescook@chromium.org>
> ---
> 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 <snitzer@redhat.com>
next prev parent reply other threads:[~2018-09-13 17:54 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-07 21:18 [PATCH v8 0/9] crypto: Remove VLA usage Kees Cook
2018-08-07 21:18 ` [PATCH v8 1/9] crypto: xcbc: " Kees Cook
2018-08-07 21:18 ` [PATCH v8 2/9] crypto: cbc: " Kees Cook
2018-08-07 21:18 ` [PATCH v8 3/9] crypto: ccm: " Kees Cook
2018-08-07 21:18 ` [PATCH v8 4/9] crypto: hash: " Kees Cook
2018-08-07 21:18 ` [PATCH v8 5/9] dm: Remove VLA usage from hashes Kees Cook
2018-09-04 3:13 ` Herbert Xu
2018-09-13 16:41 ` Kees Cook
2018-09-13 17:54 ` Mike Snitzer [this message]
2018-09-14 6:10 ` Herbert Xu
2018-08-07 21:18 ` [PATCH v8 6/9] crypto alg: Introduce generic max blocksize and alignmask Kees Cook
2018-08-07 21:18 ` [PATCH v8 7/9] crypto: qat: Remove VLA usage Kees Cook
2018-09-25 16:12 ` Arnd Bergmann
2018-09-26 8:44 ` Ard Biesheuvel
2018-09-26 8:53 ` Arnd Bergmann
2018-09-26 8:55 ` Ard Biesheuvel
2018-08-07 21:18 ` [PATCH v8 8/9] crypto: shash: Remove VLA usage in unaligned hashing Kees Cook
2018-08-07 21:18 ` [PATCH v8 9/9] crypto: skcipher: Remove VLA usage for SKCIPHER_REQUEST_ON_STACK Kees Cook
2018-09-04 3:15 ` Herbert Xu
2018-09-04 5:19 ` [PATCH v8 0/9] crypto: Remove VLA usage Herbert Xu
2018-09-04 5:50 ` Kees Cook
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180913175439.GA5414@redhat.com \
--to=snitzer@redhat.com \
--cc=agk@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=ard.biesheuvel@linaro.org \
--cc=arnd@arndb.de \
--cc=davem@davemloft.net \
--cc=dm-devel@redhat.com \
--cc=dwmw@amazon.co.uk \
--cc=ebiggers@google.com \
--cc=geert@linux-m68k.org \
--cc=giovanni.cabiddu@intel.com \
--cc=gustavo@embeddedor.com \
--cc=herbert@gondor.apana.org.au \
--cc=keescook@chromium.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=qat-linux@intel.com \
--cc=tglx@linutronix.de \
--cc=tudor.ambarus@microchip.com \
--cc=will.deacon@arm.com \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).