Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4298023pxf; Tue, 23 Mar 2021 07:33:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZzjXiNPpktgGFqrmlUbKpqp5HjrAmeMjsWxu91KNy1GjKAMJYjxF9UtTMKKGGW1/ITeXg X-Received: by 2002:a17:906:170d:: with SMTP id c13mr5012686eje.491.1616510018308; Tue, 23 Mar 2021 07:33:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616510018; cv=none; d=google.com; s=arc-20160816; b=kWMekpVRcjtHybmtkbQJ29GNNt3ASyjOXXg1eau1QYbjOQJcSg9YpkWj5WizbNFgEr qQJ+rZwcgwtzw27fNj50SGPhHE50olQz3gvepVaRBOP/ayx3zvP2AgPU0hT21PTr30CM vABUEUm5uNwVXQ9KLEDDZQjPAyndsZbgxS56UGwyBI023OVGc/Zlyec0H2rkEJfu0LEp mK6d8WCPQqWyMbXkoY3DP06z+D+jKVmnsjpr56U+sfqtinz7J2CmDFQ1Oq6rCw/UOMuS rouZXi9vWV2Xts+p5n/1trCgu6ea894BBQNQIgrlCyr1ACfB4lGlqdoZMV9Rysbxoe45 fS3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=fVMvf8eVy9AWqyntk6oUV0PNizVoZ/d/gE1aiTuzf/E=; b=iiwQfZ9cd491jaaV79MPetPF0i0AX6rwkbL3epIZ9olaD2eklX9M1PhocGjRSFQCca PjnqZrY9YRYCS0UmSXkFhlhCY1NQDpvtO9ZgsJynoBwlkEocqcqu2f0grYfel+sy47hl Fp/bxkl4KbE3fkluXn6Zhckp9ksVMusn9uW6xfKrwHvjmVMTv4VIFlTtPshuNXJHb7L3 OrPXghOg6ieUAqfjrNpBFyS3caHCXzjWjVn04VbRMV0r0JlVFGJRHmGcX5grmbruVdnN lTNP6VfGALEzsVWmVGbke6fIRgljcrGhtabJmyXPzomRjZgiyBHmjJmITGlpFZ4zHPQX 4lhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="eag8/Tjo"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k19si13597065eja.265.2021.03.23.07.33.15; Tue, 23 Mar 2021 07:33:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="eag8/Tjo"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232282AbhCWObp (ORCPT + 99 others); Tue, 23 Mar 2021 10:31:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:33988 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231830AbhCWObd (ORCPT ); Tue, 23 Mar 2021 10:31:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 19F7C619B1; Tue, 23 Mar 2021 14:31:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616509893; bh=yhZhazX2oACtfcU29Xevp6wA10wkcp2mGKfW9VxdBeM=; h=From:To:Cc:Subject:Date:From; b=eag8/TjooaMama1LhkL9+vLR4a0gGdT1zyhNJwRBRrNsvYpxcehxMwrITAD4WwPXV GgPiQHdtaLG63JToJAjT6iRVZdUGMnFaR/i4g3OtRVUEwJM7NPohScAjcA7wNaNoA0 rZYT+eNMlHBOY2jNQAFMSo/OCQCSYg5i+qFhLmtAxx2lgmoLD6IJ4gSWmQO6A9KSO5 78s4v1G83pE12LxKgHDM/Z9OvR2mbgOClazkH7l5VCzASVqDDEGT0zV0Ff6v6/9FqK 7SgrqYMwzqPwl0zriTxXWk8KnrHkn/H7idqffQ9UXRzC7CizphkZKi+Qrjyc8/yvQK uI99OZxiIQ3QQ== From: Arnd Bergmann To: Chris Mason , Josef Bacik , David Sterba , Anand Jain , Naohiro Aota Cc: Arnd Bergmann , David Sterba , Nikolay Borisov , Johannes Thumshirn , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] [v2] btrfs: zoned: bail out in btrfs_alloc_chunk for bad input Date: Tue, 23 Mar 2021 15:31:19 +0100 Message-Id: <20210323143128.1476527-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnd Bergmann gcc complains that the ctl->max_chunk_size member might be used uninitialized when none of the three conditions for initializing it in init_alloc_chunk_ctl_policy_zoned() are true: In function ‘init_alloc_chunk_ctl_policy_zoned’, inlined from ‘init_alloc_chunk_ctl’ at fs/btrfs/volumes.c:5023:3, inlined from ‘btrfs_alloc_chunk’ at fs/btrfs/volumes.c:5340:2: include/linux/compiler-gcc.h:48:45: error: ‘ctl.max_chunk_size’ may be used uninitialized [-Werror=maybe-uninitialized] 4998 | ctl->max_chunk_size = min(limit, ctl->max_chunk_size); | ^~~ fs/btrfs/volumes.c: In function ‘btrfs_alloc_chunk’: fs/btrfs/volumes.c:5316:32: note: ‘ctl’ declared here 5316 | struct alloc_chunk_ctl ctl; | ^~~ If we ever get into this condition, something is seriously wrong, so the same logic as in init_alloc_chunk_ctl_policy_regular() and a few other places should be applied. This avoids both further data corruption, and the compile-time warning. Fixes: 1cd6121f2a38 ("btrfs: zoned: implement zoned chunk allocator") Link: https://lore.kernel.org/lkml/20210323132343.GF7604@twin.jikos.cz/ Suggested-by: David Sterba Signed-off-by: Arnd Bergmann --- Note that the -Wmaybe-unintialized warning is globally disabled by default. For some reason I got this warning anyway when building this specific file with gcc-11. --- fs/btrfs/volumes.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index bc3b33efddc5..d2994305ed77 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -4989,6 +4989,8 @@ static void init_alloc_chunk_ctl_policy_zoned( ctl->max_chunk_size = 2 * ctl->max_stripe_size; ctl->devs_max = min_t(int, ctl->devs_max, BTRFS_MAX_DEVS_SYS_CHUNK); + } else { + BUG(); } /* We don't want a chunk larger than 10% of writable space */ -- 2.29.2