Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1308424imm; Fri, 29 Jun 2018 15:41:44 -0700 (PDT) X-Google-Smtp-Source: ADUXVKImxX1/w11DdqM/EBVp88pnR8Y7gqUIQIOXNWQtAPpf46P+jLzt+7gzC4N2Xs8eNoea4BJx X-Received: by 2002:a17:902:3281:: with SMTP id z1-v6mr16843563plb.226.1530312104741; Fri, 29 Jun 2018 15:41:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530312104; cv=none; d=google.com; s=arc-20160816; b=W4R3jQ9X1hz8ba1Cusfig9PEQ2e+7DNl9oHXvZG+cbFLAuCdS5CJq7Wi6qSiPSnOFa Kl1YqFoznXC7docYe550TIVJ9dsQSTP5xPJGq6EXUdhtSVHVdK1DrtwyKBFr7BIkP3Ea /rqG+89XjQ2BdYjt10vtKGcRamYnYxxwfzjSee2YEKnkbeIJFjcslF6eUf9O3rSwuOSu 66ASuQxfkGKEsEtYnAD7TrRqkX4pTHT1/nGfWi8+WUY9VvGVdNZ8NEq2Qy0FcmQrPXxP lCnk+4+c3NRs1nAutJ9zeH6/+yFS7x3rWIq8jJMAl/uZC1WH9xnJjdcgA9vezQlfDoWG Ykpw== 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 :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=deIU8Q7YXT3lVZMXyASHEU0pPu8YXogke+JaVTqTzS0=; b=KcFp9cyI5XmkAo0AFylLCjsA+lcp3fsmoFlpeA6hO03wpbOJyuKIl2aN75LfgjjqI2 9PSZYAxY/M68HM/vSZ8OSIuzht02HnB7hPHNR0tMyO/1q2iZJeaThZO+UNrWVCGlhqNK RxvZMGalBxgDB7LRhVvEYpgI1zTRlhAXwrYk/AtU5Ow4vWfux0StMtJC/Um17nVa9cLx k1eeX3heq5wiMFQBC4fdokeQJD9rt9RmGYEbTqz5LbMAmlUuqC+mFOmPQmlcRHZXR17a LK6vro3iUIhdgBkMCx/2hOx0aRGNL+ZdNRYpFpaoD+96aOe5B5BxJYvzB9tmCvTmkP0V khMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=eQc3fgt6; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p88-v6si10219678pfj.294.2018.06.29.15.41.30; Fri, 29 Jun 2018 15:41:44 -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=fail header.i=@gmail.com header.s=20161025 header.b=eQc3fgt6; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S937416AbeF2Uni (ORCPT + 99 others); Fri, 29 Jun 2018 16:43:38 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:37180 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932119AbeF2Ung (ORCPT ); Fri, 29 Jun 2018 16:43:36 -0400 Received: by mail-lf0-f67.google.com with SMTP id g21-v6so7697613lfb.4; Fri, 29 Jun 2018 13:43:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=deIU8Q7YXT3lVZMXyASHEU0pPu8YXogke+JaVTqTzS0=; b=eQc3fgt6+3dCrUQRuIQ5hhIdvjThbmE9QSYL1rXnLxx+aGlDszEFSX99PFlowCJjcp yniDuDf8iFmJylfxYpktPhayP3SdCyog7ta6PPK+r726abnNxrvDYr60DY7QyqlircoP yV1CQA0CmEP8gHL+75y6l5w6OFSf+i9SAIN4vTVJvSaF2llohJWeKmys3q4U4wJt3IIh tSDGREly72LqtT0V+7itwZgSKMtKfkngZKwkO4QUWkxDRRDMziOrOOggnXT5q1WemDS5 k3Y1iyIpvb1cB2RxpeWk1Sxo5UpShjO3tjGY04C5uODI3/OFaZyY1047YZmUd1+dmzUT 3kEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=deIU8Q7YXT3lVZMXyASHEU0pPu8YXogke+JaVTqTzS0=; b=p5o6dlkZmbDf/GpSRO8PS9SU/iKTcUJ0ssvHoqdSzvdwZ3loPR63epzkLhB06vj2t8 aNnGY+UGQciisftyFFlEFRpqZJZ/g9UASFy5YYHUfrkNErq37v1dt3cD1bL63cyeMP09 CPMItNdF3NsS+3tx/FAfk13VLP+QbgF69z8q4MBExMUczrmdP7sjoK3zckKfY5kqz5bq M0c1MQr5cH5FZC4tBYgup8xTuV8VXKKYRFPxJAQh0uEZBZPpv2RhhtC1piR6TJPtnolT c7sA9XYSijV5cvXPRzrp9jwZse1paBWjCQj49b9iGulEsPwPgyJesCltdfYRz/lqQ3+p C94w== X-Gm-Message-State: APt69E1bgyDFKSEmPT+PX+1kz4aqVFx7ufv0WDM0wYcr+uvGWafCXzDy 5tiBxN82+SytXOR0IRstqN6aVLvdzQ18NjeUeBk= X-Received: by 2002:a19:c203:: with SMTP id l3-v6mr11382104lfc.55.1530305014892; Fri, 29 Jun 2018 13:43:34 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a2e:41cf:0:0:0:0:0 with HTTP; Fri, 29 Jun 2018 13:43:34 -0700 (PDT) In-Reply-To: <20180629002843.31095-5-keescook@chromium.org> References: <20180629002843.31095-1-keescook@chromium.org> <20180629002843.31095-5-keescook@chromium.org> From: Arnd Bergmann Date: Fri, 29 Jun 2018 22:43:34 +0200 X-Google-Sender-Auth: zSobpIYxLKeeJpEQTR7lia26FMA Message-ID: Subject: Re: [PATCH v3 4/9] dm integrity: Remove VLA usage To: Kees Cook Cc: Herbert Xu , "Gustavo A. R. Silva" , Eric Biggers , Alasdair Kergon , Giovanni Cabiddu , Lars Persson , Mike Snitzer , Rabin Vincent , Tim Chen , "David S. Miller" , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , qat-linux@intel.com, dm-devel@redhat.com, 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 Fri, Jun 29, 2018 at 2:28 AM, Kees Cook wrote: > diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c > index 86438b2f10dd..85e8ce1625a2 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[SHASH_MAX_DIGESTSIZE]; > + > + if (WARN_ON(size > sizeof(digest))) { > + dm_integrity_io_error(ic, "digest_size", -EINVAL); > + goto err; > + } I'm still slightly worried that some patches like this one could make things worse and lead to an actual stack overflow. You define SHASH_MAX_DIGESTSIZE as '512', which is still quite a lot to put on the kernel stack. The function also uses SHASH_DESC_ON_STACK(), so now you have two copies. Then you could call shash_final_unaligned(), which seems to put a third copy on the stack, so replacing each one with a fixed-size buffer adds quite a bit of bloat. Is there actually a digest that can be used in dm-integrity with more than 64 byte output (matching JOURNAL_MAC_SIZE) here? Arnd