Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp455893imm; Wed, 26 Sep 2018 01:20:18 -0700 (PDT) X-Google-Smtp-Source: ACcGV62xdIlRUjMFs42/EqeX3azwKhvuV5SeSB2DK4HJ7/ikYq9pi59+KzmAmVDr3msbwXdiIxv1 X-Received: by 2002:a63:f206:: with SMTP id v6-v6mr4688029pgh.319.1537950018898; Wed, 26 Sep 2018 01:20:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537950018; cv=none; d=google.com; s=arc-20160816; b=xHPnFE1OSInxKfSA+ERVxhZjIflnmTRTR31SylXFiuViiSFDPmxesudwRiqlv3hZqh syRw3vzTsKfUq36WFfs7G6JnUJecr+ZwyirBY1jbn+iJqmslmhryVoHfD0/ZIkglJSuX 5/VBPN8AnXd2WXG9Pizsl+Fr/D5tGKtLEe6ep9vG0mZ+4x9NNLIlkc5H3BaQ2ysgXdNp 7J35BkW+aRdMiwd6PgiA8UgzQUje1Jr6XoeO8tY8cU4ZGLTSWh5F9vcS8RFttHpFyvQk GEUPgdOLeTV6thVPK1s9SZTF+5arowB3TO+wp4l4mmsI2ejszqQ4SmUmzFFeGeVZqkZd 9kPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=bywhI0QRBMo8SrhPMTSwkwlpczTVhh3MZgIlE5XvC38=; b=kecFrEoPp/aCQb+JKyDTl1t+716+3hY2J2GU3EmKc78pygSARxFlethzBZt3OHcEIo P07cYXTJUZvvXEKme+2Qe8uUdxCtFiAFUoY5FpY/f5a42jJT4A9To8hcpPLtywgfiJw1 Fs/vJn00c0AXCyuTVtBf0k9McN+luDzA7xVGoHfh07u2dtKbiW9zbybjaX7MLjQg9HCF zsjyqOrU4Y4Xxdc0mFEb2sA8qesuxAmPr5qRNr5019uiSd/dv2HoHEsqDBZZAH9TnlXy VS5WHKgXuINuudJA1+Jeo9i+eI401WBOHsepYQFOr3pw9lKYDlxETGhLRynBxYbmeyIt SUcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ICsV8uGr; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l12-v6si4732832plc.332.2018.09.26.01.20.02; Wed, 26 Sep 2018 01:20:18 -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=@linaro.org header.s=google header.b=ICsV8uGr; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727347AbeIZOb3 (ORCPT + 99 others); Wed, 26 Sep 2018 10:31:29 -0400 Received: from mail-io1-f66.google.com ([209.85.166.66]:37184 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726704AbeIZOb3 (ORCPT ); Wed, 26 Sep 2018 10:31:29 -0400 Received: by mail-io1-f66.google.com with SMTP id v14-v6so22614577iob.4 for ; Wed, 26 Sep 2018 01:19:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bywhI0QRBMo8SrhPMTSwkwlpczTVhh3MZgIlE5XvC38=; b=ICsV8uGrvVcrGqx/te5QDU6vOgUBkWZ9A5MZY63oK36vlT7HOp2fhhnAPoLSMjKBJN xEE7IgB7iEMQKZpoNFtGvbffZF7SJ1yt/CviiCUolfxmTzkhsRP8EJG9YcnGgvHHgMXL +bw2MBTsQ2V9ma3uttl2H34OvIwz2Xl1k0b1I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bywhI0QRBMo8SrhPMTSwkwlpczTVhh3MZgIlE5XvC38=; b=HQsP2k2ag9+anDx4sDrhqvUtf1OtiXOtNCrfAwuvIjy+KVR3+Mfnx+WuM6g2UT+CO6 umAVTNpAZdXL/TaqfWgYXHWI0e5ackLjd9LNsBco9e0LoE3BpRRvbWP61rn0SEBUPjZ9 vCDUUEh0M1O3DX8YyOhpewupmV00pOmARfDIYXmfQrQ8NJorh3hCfP5VYv5aEhY9pG26 g8KwivStMwwREevsIADeZdSilLOfGjZDfd3ui06BxjApAiclIFW3S9Nrrt6Hm+g8N7WQ qtEjujd4be8F4Xwucc0ydBiz3IRXnvIx1HyVUCsRUQbflX88UEUVH1WRwMBEZpcMR5WJ LkiQ== X-Gm-Message-State: ABuFfoiSsmlYuNZTGn7TLg34f+4BAg7GwR2/4y7N9CDiM/Sz8c/4Dkak I+kgtP8j0HEpyq+fzHvVjKlPIX/ZEkkj7jjL1eBwIw== X-Received: by 2002:a6b:5d12:: with SMTP id r18-v6mr3975273iob.170.1537949983491; Wed, 26 Sep 2018 01:19:43 -0700 (PDT) MIME-Version: 1.0 References: <20180919021100.3380-1-keescook@chromium.org> <20180919021100.3380-8-keescook@chromium.org> <9c71afda-a668-10b3-842e-26f72e425691@kernel.dk> In-Reply-To: From: Ard Biesheuvel Date: Wed, 26 Sep 2018 10:19:30 +0200 Message-ID: Subject: Re: [PATCH crypto-next 07/23] block: cryptoloop: Remove VLA usage of skcipher To: Jens Axboe Cc: Kees Cook , Herbert Xu , linux-block@vger.kernel.org, Eric Biggers , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 25 Sep 2018 at 18:32, Jens Axboe wrote: > > On 9/25/18 10:16 AM, Ard Biesheuvel wrote: > > On Tue, 25 Sep 2018 at 18:03, Jens Axboe wrote: > >> > >> On 9/25/18 3:25 AM, Ard Biesheuvel wrote: > >>> On Mon, 24 Sep 2018 at 19:53, Kees Cook wrote: > >>>> > >>>> On Mon, Sep 24, 2018 at 4:52 AM, Ard Biesheuvel > >>>> wrote: > >>>>> On Wed, 19 Sep 2018 at 04:11, Kees Cook wrote: > >>>>>> @@ -119,7 +119,7 @@ cryptoloop_transfer(struct loop_device *lo, int cmd, > >>>>>> unsigned in_offs, out_offs; > >>>>>> int err; > >>>>>> > >>>>>> - skcipher_request_set_tfm(req, tfm); > >>>>>> + skcipher_request_set_sync_tfm(req, tfm); > >>>>>> skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_SLEEP, > >>>>>> NULL, NULL); > >>>>>> > >>>>> > >>>>> Does this work? > >>>> > >>>> Everything is a direct wrapper for existing types and functions, so I > >>>> wouldn't expect any functional change. I haven't been able to test > >>>> this particular interface, though. cryptoloop is very deprecated, > >>>> isn't it? > >>>> > >>> > >>> Ah yes, I managed to confuse myself there. This looks all fine to me. > >>> > >>> In any case, this is another example where we may decide to fix the > >>> code rather than retain the request allocation on the stack (but that > >>> is Jens's call ultimately, I suppose) > >>> > >>> diff --git a/drivers/block/cryptoloop.c b/drivers/block/cryptoloop.c > >>> index 7033a4beda66..5ed2167219ba 100644 > >>> --- a/drivers/block/cryptoloop.c > >>> +++ b/drivers/block/cryptoloop.c > >>> @@ -110,7 +110,7 @@ cryptoloop_transfer(struct loop_device *lo, int cmd, > >>> int size, sector_t IV) > >>> { > >>> struct crypto_skcipher *tfm = lo->key_data; > >>> - SKCIPHER_REQUEST_ON_STACK(req, tfm); > >>> + struct skcipher_request *req; > >>> struct scatterlist sg_out; > >>> struct scatterlist sg_in; > >>> > >>> @@ -119,7 +119,10 @@ cryptoloop_transfer(struct loop_device *lo, int cmd, > >>> unsigned in_offs, out_offs; > >>> int err; > >>> > >>> - skcipher_request_set_tfm(req, tfm); > >>> + req = skcipher_request_alloc(tfm, GFP_NOIO); > >>> + if (!req) > >>> + return -ENOMEM; > >> > >> Is this going to be reliable? ->transfer() is called when we're doing IO, > >> and you'd normally need a mempool backed allocation to make this safe > >> and guarantee forward progress. > >> > > > > As far as I can tell, this function is only called from > > lo_read_transfer/lo_write_transfer, both of which do an unconditional > > alloc_page(GFP_NOIO), which is why I assumed that kmalloc(GFP_NOIO) > > would be permissible in the same context. Are you saying this may not > > be the case? > > Doesn't appear to be safe for either your case, nor the page it's > allocating. If the allocator fails this allocation, then you'll get > an EIO on that request. The more likely case is the allocator taking > forever to satisfy the request, in which case you'll have very > large latencies for IO when you are close to being out of memory. > The preferred setup for allocating memory for IO is having a mempool > of at least one item. If you end up blocking for memory, you'll at > most get to wait for the existing IO that's using that memory to > complete (per waiter, of course). > Ah, great. So the code is already broken to begin with. In that case, may we have your ack for Kees's original patch, which is effectively a no-op except for the fact that the size of the stack buffer is no longer decided at runtime?