Received: by 10.192.165.156 with SMTP id m28csp282099imm; Tue, 10 Apr 2018 21:48:10 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/V2mTd1Qx73pzorUuHTOALjKitEd67H0aTqEKREXj4NmCpVm0ammtePf7reg+xfQXtL/kH X-Received: by 2002:a17:902:2a43:: with SMTP id i61-v6mr3433336plb.54.1523422090890; Tue, 10 Apr 2018 21:48:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523422090; cv=none; d=google.com; s=arc-20160816; b=meRfamG9lwMIcO5ZjCWG7MATJHy2rdkaIClUB4+8cesi5CmRpN45zVA2ubYK2bZ498 e4HmZnJnzW3SOGOpqmfqojiSNNVGVUbjXcXWpb77UVpe2h920apBI3AOM005LWOoAQxQ sTf95xNcD00cVd5i/g1Eeg9B8u1tO9NrhSKKC0UCeEkX3BA6/dfklMg6JLrvoEigR7v3 bjRn2JvVHYfMwErG3+9btu2P+t5LmvBLTEtNK+oDpcU1+1ZPtOwXLkdWcFVrnJpleAzs rPlhlrQyvZoeQB5fbwK+nFB6/k74aXpDckIgq/1jFbkwjv8grJWDvQRGYAmYlwSu9Ws7 GgXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=C8leKj4z5wrnAY0aE7NmRgjBm7acw7fDQHuonPYveMo=; b=tSTkrWK9SBv9nnw1gYzKejXJTmvC5xqtpnJ3f6A4S2f/1LsbJ8nd3M11zrIqTc0OVt 96Y0/mP0HQKSTD6r6ixzn0+mj1msNF8jSsKAJe1nBb02UlVdrHqcyptsbfky2poqp1Xu jkjgmIMl8FHPOgg8lM5ngKS6nkT4YLtTJpK9OdJsAaev1TRXhFclBdhElFGC2CGRtDMH km1yyQiYGQggdhZAq/Hl+VWnSizf1LRom3QIH0VMYtLaBelYtZ0R1bez05Euebq7Qgiw N4CnSilwpw6RMqnfZdwLMt5Lt9pQlCfQtOMBDBfYMQ4jvNofuR8y5X7sHvFm0JB+/xaI ERnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Tv7gLda8; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b63si212752pga.222.2018.04.10.21.47.33; Tue, 10 Apr 2018 21:48:10 -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=@chromium.org header.s=google header.b=Tv7gLda8; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752041AbeDKEnT (ORCPT + 99 others); Wed, 11 Apr 2018 00:43:19 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:37576 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750801AbeDKEnR (ORCPT ); Wed, 11 Apr 2018 00:43:17 -0400 Received: by mail-pg0-f67.google.com with SMTP id r14so213430pgq.4 for ; Tue, 10 Apr 2018 21:43:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=C8leKj4z5wrnAY0aE7NmRgjBm7acw7fDQHuonPYveMo=; b=Tv7gLda8TBOgst7TZovcQDuvVYa8P/PP8RXmyjBIez0B1AVomXWqhWSC5gPrf5uAiw THNmczSLXvKb+5TKOvzZ6fhgxYlW9vs+QlhGwW0oCa+ze+4h8UBjS5SXX1ypCpJZcqaD 37vEHPUOXcC9dlIlGQ7TB5bipDOyRRFzYNeJc= 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:mime-version :content-disposition; bh=C8leKj4z5wrnAY0aE7NmRgjBm7acw7fDQHuonPYveMo=; b=c+QsB7FwwsICHkp1YpshXSt2t1qAwgu+yOeiAgg5t9rOahoGnuJXpGwvlAz9D0oefO mRyijG54k5BCH50FMwy4w9XZIJcA1Ffow+BK1/gvZf4hqEp6ZTrJeuE50V98qmgNzVIc CuZJMRVLszmV2fevI7tZtV/sTeCTapGyN2A1a9Aq8iGGggN/AKd/TMSguHdB663clmg5 Pxg+YmNqED+mZ+gvR4/WnniGpYuCJszZQQi/pBL6h64hGKIGLfEu0CsNEvmiQ4lyxMkd d3DA+2GjP6xP3k/krp6Mi+i9M1D6RYixKelCsQNEmMcHbvoDfOEfW0yaAGGCt5sHcBaJ +1JA== X-Gm-Message-State: ALQs6tAQkB6zGpCo6373QKFXfXpkk7sUn0NpnNbbPoDB/JS+U9WVmlQa Di1SWAXR7x0Ai6dFR/OQyCl/g+E1ugo= X-Received: by 10.99.62.71 with SMTP id l68mr2275955pga.205.1523421797409; Tue, 10 Apr 2018 21:43:17 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id r70sm649160pfe.22.2018.04.10.21.43.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Apr 2018 21:43:16 -0700 (PDT) Date: Tue, 10 Apr 2018 21:43:15 -0700 From: Kees Cook To: Alasdair Kergon Cc: Mike Snitzer , linux-kernel@vger.kernel.org, dm-devel@redhat.com, Tycho Andersen Subject: [PATCH] dm/raid1: Remove VLA usage Message-ID: <20180411044315.GA46144@beast> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On the quest to remove all VLAs from the kernel[1], this avoids VLAs in dm-raid1.c by just using the maximum size for the stack arrays. The nr_mirrors value was already capped at 9, so this makes it a trivial adjustment to the array sizes. [1] https://lkml.org/lkml/2018/3/7/621 Signed-off-by: Kees Cook --- drivers/md/dm-raid1.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c index 580c49cc8079..5903e492bb34 100644 --- a/drivers/md/dm-raid1.c +++ b/drivers/md/dm-raid1.c @@ -23,6 +23,8 @@ #define MAX_RECOVERY 1 /* Maximum number of regions recovered in parallel. */ +#define MAX_NR_MIRRORS (DM_KCOPYD_MAX_REGIONS + 1) + #define DM_RAID1_HANDLE_ERRORS 0x01 #define DM_RAID1_KEEP_LOG 0x02 #define errors_handled(p) ((p)->features & DM_RAID1_HANDLE_ERRORS) @@ -255,7 +257,7 @@ static int mirror_flush(struct dm_target *ti) unsigned long error_bits; unsigned int i; - struct dm_io_region io[ms->nr_mirrors]; + struct dm_io_region io[MAX_NR_MIRRORS]; struct mirror *m; struct dm_io_request io_req = { .bi_op = REQ_OP_WRITE, @@ -651,7 +653,7 @@ static void write_callback(unsigned long error, void *context) static void do_write(struct mirror_set *ms, struct bio *bio) { unsigned int i; - struct dm_io_region io[ms->nr_mirrors], *dest = io; + struct dm_io_region io[MAX_NR_MIRRORS], *dest = io; struct mirror *m; struct dm_io_request io_req = { .bi_op = REQ_OP_WRITE, @@ -1083,7 +1085,7 @@ static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv) argc -= args_used; if (!argc || sscanf(argv[0], "%u%c", &nr_mirrors, &dummy) != 1 || - nr_mirrors < 2 || nr_mirrors > DM_KCOPYD_MAX_REGIONS + 1) { + nr_mirrors < 2 || nr_mirrors > MAX_NR_MIRRORS) { ti->error = "Invalid number of mirrors"; dm_dirty_log_destroy(dl); return -EINVAL; @@ -1404,7 +1406,7 @@ static void mirror_status(struct dm_target *ti, status_type_t type, int num_feature_args = 0; struct mirror_set *ms = (struct mirror_set *) ti->private; struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); - char buffer[ms->nr_mirrors + 1]; + char buffer[MAX_NR_MIRRORS + 1]; switch (type) { case STATUSTYPE_INFO: -- 2.7.4 -- Kees Cook Pixel Security