Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp630242pxb; Tue, 5 Apr 2022 16:34:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9jWnBk71zwuswO6jzhWrh1jVECGw30gqyYyIGPpypibZFhHfkLyXLG8efifFcoSPW4xnY X-Received: by 2002:a17:902:e84d:b0:156:bf35:6449 with SMTP id t13-20020a170902e84d00b00156bf356449mr5966003plg.26.1649201641547; Tue, 05 Apr 2022 16:34:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649201641; cv=none; d=google.com; s=arc-20160816; b=xxx9vs7xFX8SRaoBwWl/bNd353PGbXgSl7IYy8hx3qOQCAWFDxDTfjqaZ+3ybcCvIt HJgF+s2w+uQPSAtG4rjouUTSZSkS6jrdxIsY9dX/HYvAXyszV/6X8I5lR/kneiE38Kbv ywEecltHQEX4qhTW+ERlKIKQ5Uu31AlAchvnTmgqWNLIBR6gMVfqYAz3s9rtemI141sZ 8IjN14604tNtu1OSpEIhclVZHDmJ7ZA2SkjGr8coLvK8Vp+bjRQFXo381zh2rQHGKoPb NuI7qO/UhwUvxQBMAvPH4UaORjc3ZSFCPSyE4oZV+4HUvlvPR+abgBAnIrrcBucpQF4I b2HQ== 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=P6fI9aOuAHoWE2k3wSP7+jsvl3tWaN+2bzzJE4irGE8=; b=diKep0Pw/F25cepFdeuCOOy3WFbPFjne9M4sJC37LXZCDj3ViUiMelZ/kPq7lfz5He o9EnDdX99aXLW7rj9Y/R5CdyG/UCWA1hkpjyt7RmpNpeU2Z12Nf+n9oEjAfOvGB3KV+r 725FFqZ+pt0smlfQO1iq3aCVK+WOTXs/eqFbwz1BefY1AkDaUpVKLQ6+BX5UPNtgvk/P nUaUhWyaQWlp7/+vOlPpMdQXaE0Yt324FzI7MDt/ffOkQWWNwBRELh8jxqClJrlmH4wM eO0LWsDLQ8p4hFKq/ISYxAoKt0oJhJPYKpUD/USlae5N7b86GK0AcSlImSRT0rQvEVoE zK6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1qQKjnNV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id l4-20020a6542c4000000b003816043f0dasi13164493pgp.719.2022.04.05.16.34.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 16:34:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1qQKjnNV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DF79A124C38; Tue, 5 Apr 2022 16:18:32 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1390165AbiDENhY (ORCPT + 99 others); Tue, 5 Apr 2022 09:37:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242408AbiDEJHx (ORCPT ); Tue, 5 Apr 2022 05:07:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51E526AA49; Tue, 5 Apr 2022 01:56:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9D94961572; Tue, 5 Apr 2022 08:56:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF95CC385A0; Tue, 5 Apr 2022 08:56:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149007; bh=/P8TunVzWGpmmpgr6qat+AphEiaH/CrUmR30w+542Fs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1qQKjnNVytpUXwgHNWappBGfyHGqchqGTtOjjO5x56FBPd2SsJfeCGUZOjGO3UKm4 IS07dC8/XRLKiL7IjbY1AJXYdjBrF3MvnYXfrKb30AngiXuGQNkTDvo2IMgWEbOKae UHGbzC3J7N4rbmc3PzY+1P8fvSTKQR5Dr2NzNS2k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ping Fang , Daniel Henrique Barboza , Michael Ellerman , Sasha Levin Subject: [PATCH 5.16 0561/1017] powerpc/mm/numa: skip NUMA_NO_NODE onlining in parse_numa_properties() Date: Tue, 5 Apr 2022 09:24:34 +0200 Message-Id: <20220405070410.932484127@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daniel Henrique Barboza [ Upstream commit 749ed4a20657bcea66a6e082ca3dc0d228cbec80 ] Executing node_set_online() when nid = NUMA_NO_NODE results in an undefined behavior. node_set_online() will call node_set_state(), into __node_set(), into set_bit(), and since NUMA_NO_NODE is -1 we'll end up doing a negative shift operation inside arch/powerpc/include/asm/bitops.h. This potential UB was detected running a kernel with CONFIG_UBSAN. The behavior was introduced by commit 10f78fd0dabb ("powerpc/numa: Fix a regression on memoryless node 0"), where the check for nid > 0 was removed to fix a problem that was happening with nid = 0, but the result is that now we're trying to online NUMA_NO_NODE nids as well. Checking for nid >= 0 will allow node 0 to be onlined while avoiding this UB with NUMA_NO_NODE. Fixes: 10f78fd0dabb ("powerpc/numa: Fix a regression on memoryless node 0") Reported-by: Ping Fang Signed-off-by: Daniel Henrique Barboza Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20220224182312.1012527-1-danielhb413@gmail.com Signed-off-by: Sasha Levin --- arch/powerpc/mm/numa.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c index 59d3cfcd7887..5fb829256b59 100644 --- a/arch/powerpc/mm/numa.c +++ b/arch/powerpc/mm/numa.c @@ -956,7 +956,9 @@ static int __init parse_numa_properties(void) of_node_put(cpu); } - node_set_online(nid); + /* node_set_online() is an UB if 'nid' is negative */ + if (likely(nid >= 0)) + node_set_online(nid); } get_n_mem_cells(&n_mem_addr_cells, &n_mem_size_cells); -- 2.34.1