From patchwork Wed May 12 14:46:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 435666 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp5133431jao; Wed, 12 May 2021 12:49:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRTtQGNsuejQHxgZ8+CMafoTAgKbhsXXZCzMK8yeffRe5DCgnTdIb7U0Uw8WTomxuIB1DP X-Received: by 2002:a02:630e:: with SMTP id j14mr34024096jac.115.1620848949012; Wed, 12 May 2021 12:49:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620848949; cv=none; d=google.com; s=arc-20160816; b=SvBQ5TtpV77Ude4NzntZle9KSJ9i7RJHhlSfh9tFMq7cHTYJJb/jxNvfOE1OJ7ap4b CYCzeAXkikB+xykBnEjh80DwPuxVojaxjoe+SIKyMQHqn0hDq+x80jq2hreKQSH7Ksmb krsxifdZM3Pzx/Wk0sgF8lLzczq9/35thO33JLd+foUsFCtf/f4seYeukGHUGiwCeyws E5Hbanc8MROw7Qc1Gk32dcCeRGQRHsWXEBXbvmDMJqq1IiiMnFspeuUNxs7+g5n1PqCm +iRQVv2JNqpqcFDg/IOOet0+FZKx6pgsgLMxv17KS7w5aouPv/nczjgfQDZTS8AnMvgE n8oA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pX+ENiC5ADwJw2RXCCGDam/p30a/FEPq+ZvNX2Oq+dU=; b=OhEoCX7pCbvGXcp+ewDLIaX+yJieq4pykmu76Le3hdi8h9/+HKaC0ZrPfg5SyqkC7H zq9bxRvXpJ/kaVY1TUBZh9On0hZICYkqcwlvUsfYxjbG0Fn5B3hZ1lIi0XpC2JBhza97 ZndwIC+uY870NiKsdQFRF7DaSe8tvUqWQ75KwKLNe+0y55VWVf49TSVT0ydREYwTeA4U C5l1oYv7ML2aIa6XkXUPO7hj6htdmEAJuSwwIOukqm55nZ3qnMtKKrg1NJ+c02+mRIEz Kp9Xpj/KesjAr02/32H0ogcb5SNZPyuin77GKBIL/pv2C2+sg82wv+MBy0VRGwzMw8lj JnVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RRFQ82hu; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q8si330223ior.12.2021.05.12.12.49.08; Wed, 12 May 2021 12:49:09 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-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=@linuxfoundation.org header.s=korg header.b=RRFQ82hu; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244423AbhELQpy (ORCPT + 12 others); Wed, 12 May 2021 12:45:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:33526 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239339AbhELQjN (ORCPT ); Wed, 12 May 2021 12:39:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BC4CD61CDF; Wed, 12 May 2021 16:03:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620835398; bh=gY9Pp0xiZuLgyrykZk4BpV1fMrVQZQKidXqE3FDqiKg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RRFQ82hurHulzWpN1XZRRO/emmX260szEuR4j7q7ZwWH0Ei54x7Cen/ko7x0gFwAP u9sfCcvE6LU3T2c5tw5T946Gp1yPd3OmXxggyi6Cdg/VdqgeEi6xBnE/X6Fyr/agDd 2HnMtkqeBjrFTAEjwjeGi6/5umZVjUPanI3NN9iY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arnd Bergmann , David Sterba , Sasha Levin Subject: [PATCH 5.12 327/677] btrfs: zoned: bail out in btrfs_alloc_chunk for bad input Date: Wed, 12 May 2021 16:46:13 +0200 Message-Id: <20210512144848.110528854@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144837.204217980@linuxfoundation.org> References: <20210512144837.204217980@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Arnd Bergmann [ Upstream commit bb05b298af8b2330db2b39971bf0029798e7ad59 ] 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, as validity is checked in the callers btrfs_alloc_chunk init_alloc_chunk_ctl init_alloc_chunk_ctl_policy_zoned 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") Signed-off-by: Arnd Bergmann Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/volumes.c | 2 ++ 1 file changed, 2 insertions(+) -- 2.30.2 diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 1c6810bbaf8b..3912eda7905f 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 */