From patchwork Thu Mar 22 17:21:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinz Mauelshagen X-Patchwork-Id: 10302011 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E43CB60385 for ; Thu, 22 Mar 2018 17:23:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C875C2899E for ; Thu, 22 Mar 2018 17:23:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C607C288B3; Thu, 22 Mar 2018 17:23:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7802C28B2C for ; Thu, 22 Mar 2018 17:21:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D5858C0587DD; Thu, 22 Mar 2018 17:21:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9CD0C18A4E; Thu, 22 Mar 2018 17:21:38 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 24ACF4CA99; Thu, 22 Mar 2018 17:21:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w2MHLZsh029972 for ; Thu, 22 Mar 2018 13:21:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 36D5810B0082; Thu, 22 Mar 2018 17:21:35 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from o.ww.redhat.com (ovpn-117-1.phx2.redhat.com [10.3.117.1]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9F0B111CB9E; Thu, 22 Mar 2018 17:21:29 +0000 (UTC) From: Heinz Mauelshagen To: heinzm@redhat.com, dm-devel@redhat.com, snitzer@redhat.com Date: Thu, 22 Mar 2018 18:21:28 +0100 Message-Id: <6386b9f02b3513bd0ba5ddccd437502313448f7d.1521738866.git.heinzm@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: dm-devel@redhat.com Subject: [dm-devel] [PATCH v2] dm raid: fix parse_raid_params() variable range issue X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 22 Mar 2018 17:21:40 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP This v2 addresses Mikulas' point about the variable range and folds in "[PATCH] dm raid: use __within_range() more in parse_raid_params()": parse_raid_parames() compared variable "int value" with INT_MAX to prevent overflow of mddev variables set. Change type to "long long value". Whilst on it, use __within_range() throughout and add a sync min/max rate check. Signed-off-by: Heinz Mauelshagen --- drivers/md/dm-raid.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c index c1d1034ff7b7..c0e3d2aa9346 100644 --- a/drivers/md/dm-raid.c +++ b/drivers/md/dm-raid.c @@ -1141,7 +1141,7 @@ static int validate_raid_redundancy(struct raid_set *rs) static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as, unsigned int num_raid_params) { - int value, raid10_format = ALGORITHM_RAID10_DEFAULT; + long long value, raid10_format = ALGORITHM_RAID10_DEFAULT; unsigned int raid10_copies = 2; unsigned int i, write_mostly = 0; unsigned int region_size = 0; @@ -1153,7 +1153,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as, arg = dm_shift_arg(as); num_raid_params--; /* Account for chunk_size argument */ - if (kstrtoint(arg, 10, &value) < 0) { + if (kstrtoll(arg, 10, &value) < 0) { rs->ti->error = "Bad numerical argument given for chunk_size"; return -EINVAL; } @@ -1315,7 +1315,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as, /* * Parameters with number values from here on. */ - if (kstrtoint(arg, 10, &value) < 0) { + if (kstrtoll(arg, 10, &value) < 0) { rs->ti->error = "Bad numerical argument given in raid params"; return -EINVAL; } @@ -1430,7 +1430,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as, rs->ti->error = "Only one min_recovery_rate argument pair allowed"; return -EINVAL; } - if (value > INT_MAX) { + if (!__within_range(value, 0, INT_MAX)) { rs->ti->error = "min_recovery_rate out of range"; return -EINVAL; } @@ -1440,7 +1440,7 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as, rs->ti->error = "Only one max_recovery_rate argument pair allowed"; return -EINVAL; } - if (value > INT_MAX) { + if (!__within_range(value, 0, INT_MAX)) { rs->ti->error = "max_recovery_rate out of range"; return -EINVAL; } @@ -1472,6 +1472,12 @@ static int parse_raid_params(struct raid_set *rs, struct dm_arg_set *as, } } + if (rs->md.sync_speed_max && + rs->md.sync_speed_max < rs->md.sync_speed_min) { + rs->ti->error = "sync speed max smaller than min"; + return -EINVAL; + } + if (test_bit(__CTR_FLAG_SYNC, &rs->ctr_flags) && test_bit(__CTR_FLAG_NOSYNC, &rs->ctr_flags)) { rs->ti->error = "sync and nosync are mutually exclusive";