Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp886918pxb; Wed, 6 Apr 2022 03:15:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/sgVjy/NOo9/Uae4aBPKvWsi/bmGLCC6HZ3gZ8kRAbnJsE78n0E/ZmK3nWb+uKXXoYvUT X-Received: by 2002:a65:6713:0:b0:382:3e2e:9ae9 with SMTP id u19-20020a656713000000b003823e2e9ae9mr6313335pgf.469.1649240131841; Wed, 06 Apr 2022 03:15:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649240131; cv=none; d=google.com; s=arc-20160816; b=cEIykH/UZ26oSvw+ZLrOcB1kSJJofQWZNAb48pMEklJKKyDYb/lqRNYGO/OGwGY4T1 SGCJYqZT2pQPcFzxfCRyiPlerinrTGDMbGxSzQ/IP3+ZmjfUd53AcXkBy6CE/vArAQ/h LCFXCLDvUuCSUGgsEhQtrm2wC+cVlDu5hujvWt718V3rRZ6RcHmeOXjy+mHvO8GWTnL0 cfHDfz31LtTtF2nVh+QA+S8JsP/i6Tgef6KwaU4zhxjAylNEhORlXgPnApt60+uM7/cP VwSwEhlla6up8my+q7LMUyFyPGc9VMhilyLFdiZbC7AAnYknQV+kMdZptFKDwB9xSBWp YQpA== 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=xlIVdvdzxePFvaQQZ32M8UdbnC7i5SnYWM3cakSYKTTj2nK2ipCS0sBMFoWMpmqwqF vkvqFrPLNI/nd+Ggap3sSwi3r124oLVdcL9JbCPoRTNwiZQh3ZZeDu2mO9FjJ8ZttEoN H5kno/2CvDVCCQBTxGsqu0Tu+bMILECUoGXCciIybtgBSXkI1+R+rw1OSFtx4QfEvd7t 547RWCbFwStQynvBKYCmeuFneMkNeGdsNdrTxaBBjTTkoloaRrf8cMFixnv0hRfP5v4n 6rE2gx4GpMPCxpbPEUfr4ls1Fte0NWmNoQ6tzybFZ6KTjlRJSGF2Cgrk9qWl+aLx3PF2 88GA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XciM5jLb; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id o1-20020a170902d4c100b00153b2e6c913si15382976plg.207.2022.04.06.03.15.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 03:15:31 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XciM5jLb; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 2981C5857CE; Wed, 6 Apr 2022 01:46:05 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1579446AbiDEXbM (ORCPT + 99 others); Tue, 5 Apr 2022 19:31:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349147AbiDEJtO (ORCPT ); Tue, 5 Apr 2022 05:49:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00A6ECF5; Tue, 5 Apr 2022 02:41:30 -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 90A856164D; Tue, 5 Apr 2022 09:41:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9AE95C385A2; Tue, 5 Apr 2022 09:41:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649151690; bh=/P8TunVzWGpmmpgr6qat+AphEiaH/CrUmR30w+542Fs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XciM5jLbygJN/CLzfbx3MvNtCxy9nz8PebMhc1bYpFM+gYxLx69nWkfcOof4olqM6 RcOCY6jSQOfNfTA3J97b9I5KWZoiLQIihW/qq9D61L2HZ1fS5f2EI/uVsYp0Y/cbiK mOaB8omZRAOgKcgssrbH7mXCyMR/w8N004IMtatA= 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.15 507/913] powerpc/mm/numa: skip NUMA_NO_NODE onlining in parse_numa_properties() Date: Tue, 5 Apr 2022 09:26:09 +0200 Message-Id: <20220405070355.054023170@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@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