Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp2252993ybg; Sun, 27 Oct 2019 14:27:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqz41oSr1n8vapnUgRKtGMxcNrUBF2iJuyDEiWdgMaeA9Q5fG9IzzbYSgKbz/J/GVM7xBBFg X-Received: by 2002:a17:906:2989:: with SMTP id x9mr13708303eje.318.1572211630875; Sun, 27 Oct 2019 14:27:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572211630; cv=none; d=google.com; s=arc-20160816; b=vWRbVXq4gjwgQyw4izCi18v6xqeuh06suWhcR3vUnuhbasdcK46mZzP9SSp9cMVCiP FZM2c2RI0UxshG+Vyjx76bEpwy90Ksvsk1wlYtXx7GfejGvmAHRylx0MW5TeiRjSIh7j hMgRTGHno2xmwV7lXvgbjpUpnyqDhcGliMfcRpsbEOa6QMol4/DXbI1OZSUsXYPGq/Im TtBKorbxo8yLtSQPAoUj3pbKNqvVY7vI9fIrrBMFn4h9XG6gV1BptqcsmXB/5WiQXohu ZGkMz7Fgacx1RyTq3leoEWAyPJCKnr9CJVTfba3ElcDtZ9zdjx6gQhu9XdvxjbjS9F8k fqqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=p7+6Yt/nc3SIwCTFI24HGNo/l4p9fkN0XSjqTPEyOtY=; b=S9GtNU1Tg+GnPOB+kmfTNC0F8XcT6Yej4nV1Q4s1UZ7ANryRLn33ca4DMizQ2DkuU4 3J71yyb38ccMHY4fi25OF/ngDqeCXZcXib4XL84gNufuab7ct1v141Esod3hoTXXVOls a28ng2TjNHbSZVIqOokpPtS+3tOUeaPXzMSv4gUqcr2zgnEiq0eb+a7QT/dTXMtrlpCk soEZAqe0+h1Xr6AeJwhdt0kK7ZkvqYjF4kgXLlgVc04tcwfbOjl/PAMuGagI+RVaxXci Urfvu5iR0VNw6pouITc2l5evXAZuwPnwd6fkbMvSYDVafLLxp+Rf62/IVHuyxlCEZ6p0 dVvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ydku8zuF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 7si7005414edx.33.2019.10.27.14.26.47; Sun, 27 Oct 2019 14:27:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ydku8zuF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732703AbfJ0VZR (ORCPT + 99 others); Sun, 27 Oct 2019 17:25:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:47026 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732692AbfJ0VZP (ORCPT ); Sun, 27 Oct 2019 17:25:15 -0400 Received: from localhost (100.50.158.77.rev.sfr.net [77.158.50.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D043F21783; Sun, 27 Oct 2019 21:25:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572211514; bh=+fUGPU/cUvr4r1VruQzw+nmYANorNrfj6Z+QY1jRk18=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ydku8zuFdPxfihrZijqqSwBgqGKIddNuyWhQ4VFIipf9qF7mq6DF7rXOKx5P7NOOn pFs3UBH69XHH8FFEqmIpf10XAVWHJ3tP5lUAtB6HPdvPJfpmZ83A7xIt2t954XKdqx OB2/BQenm69RqUl8z1mFoSrmAcbDPikv46nqm4U0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , Thomas Gleixner Subject: [PATCH 5.3 176/197] x86/apic/x2apic: Fix a NULL pointer deref when handling a dying cpu Date: Sun, 27 Oct 2019 22:01:34 +0100 Message-Id: <20191027203404.857732611@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191027203351.684916567@linuxfoundation.org> References: <20191027203351.684916567@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson commit 7a22e03b0c02988e91003c505b34d752a51de344 upstream. Check that the per-cpu cluster mask pointer has been set prior to clearing a dying cpu's bit. The per-cpu pointer is not set until the target cpu reaches smp_callin() during CPUHP_BRINGUP_CPU, whereas the teardown function, x2apic_dead_cpu(), is associated with the earlier CPUHP_X2APIC_PREPARE. If an error occurs before the cpu is awakened, e.g. if do_boot_cpu() itself fails, x2apic_dead_cpu() will dereference the NULL pointer and cause a panic. smpboot: do_boot_cpu failed(-22) to wakeup CPU#1 BUG: kernel NULL pointer dereference, address: 0000000000000008 RIP: 0010:x2apic_dead_cpu+0x1a/0x30 Call Trace: cpuhp_invoke_callback+0x9a/0x580 _cpu_up+0x10d/0x140 do_cpu_up+0x69/0xb0 smp_init+0x63/0xa9 kernel_init_freeable+0xd7/0x229 ? rest_init+0xa0/0xa0 kernel_init+0xa/0x100 ret_from_fork+0x35/0x40 Fixes: 023a611748fd5 ("x86/apic/x2apic: Simplify cluster management") Signed-off-by: Sean Christopherson Signed-off-by: Thomas Gleixner Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20191001205019.5789-1-sean.j.christopherson@intel.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/apic/x2apic_cluster.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/arch/x86/kernel/apic/x2apic_cluster.c +++ b/arch/x86/kernel/apic/x2apic_cluster.c @@ -158,7 +158,8 @@ static int x2apic_dead_cpu(unsigned int { struct cluster_mask *cmsk = per_cpu(cluster_masks, dead_cpu); - cpumask_clear_cpu(dead_cpu, &cmsk->mask); + if (cmsk) + cpumask_clear_cpu(dead_cpu, &cmsk->mask); free_cpumask_var(per_cpu(ipi_mask, dead_cpu)); return 0; }