Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3882548pxb; Tue, 17 Nov 2020 06:08:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJzW1+sDovDF4YhsDSLzixevkiEnheyAwfDWtlG4ISN4jkak2uHQ03AMLCse4uKJ3ev43fXZ X-Received: by 2002:a17:906:a3ca:: with SMTP id ca10mr14210807ejb.40.1605622104592; Tue, 17 Nov 2020 06:08:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605622104; cv=none; d=google.com; s=arc-20160816; b=wmqylLlnYntiRk2I0OXH43ZBmYjjglibij5Zx/W9DqZ3bPgM31u6oqQv4836WcPjJp Nj0luVjEw87nMiy6n9VDrijoHOknT6pMOVLC4etmezvwmfKbaGmuLpy36Bu+HiPrfjeL a5jgk1oU2qu+d6h7iqSUo/vESIpXqCi2Nx5e5Y7KHsHbjMYiveEDUSP+zo0fIddyBkB5 QWSW+LLrIN2n7J4Vjg0FWp1jo/t6oIKmn26y5epJ+QxXfzrXX3MU78kCprZb4WuzPX5g 3R7kpnjBs8ASHSl1F5SZ9FZ5hwIs7YTOj+j68OD29cBIq9gKhOtF6Jrz0mjdMV++56HG RAKQ== 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=faUkpCg9MJX29INWDd5e0NY0bHyA26LPOYQzVyoD90s=; b=Ul1yqRUJLkvMAVjFbrSFdd/hl6Jv38vjOb+/5NYmYxvkd7kjzxiRHY//MEM9sUk52H SvR+PRe9G0jBUO0yxIxOLE63DLnBgCx9Njgrr/zcsAHlalqaoN5wi1z3KyOP24D4uuyZ l07qe3307ZU0Q5l6eDmNdl3IwGQzFWwedimPbesLdA04rqONK9e0o6XSbbEjMb3XUDue dFbYzMyFUJk3eADLANTZ4XSaO6c7Tacqah2O0BOcEM8zTntF6NajSg9bpitlqALr/Ts/ jDR/vS2+5jDuLdoLbCnJW4icR7+npPABOX8BKapoHIVgVsvzaf43exzIIpW5mrmwuGJ/ dYMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=y29sIGGl; 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=fail (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 wn12si4577164ejb.43.2020.11.17.06.08.00; Tue, 17 Nov 2020 06:08:24 -0800 (PST) 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=default header.b=y29sIGGl; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728725AbgKQNJW (ORCPT + 99 others); Tue, 17 Nov 2020 08:09:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:37754 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729373AbgKQNJG (ORCPT ); Tue, 17 Nov 2020 08:09:06 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 11E6D2225B; Tue, 17 Nov 2020 13:09:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605618545; bh=Erzmw6T1KHPpYXvP6UTHaqQVh+xzUZeFxd3OXrj3tkM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y29sIGGlmF+GYpqTGqdDd/HpSdct95pzwQuqZ2E0zW8Sxij6zpITRNCmnvZ0yVAPx HKTyARteNbjSwqaVn+ykiTZOjRkGJV9LqAWBl9wLQFYo7cIF309Zb2JV7cYqDfj5Hq eyIzXjYsyMKGeRJfRlVnhOcPza+6kQ0IEYCRcqJE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Matteo Croce , Andrew Morton , Arnd Bergmann , Fabian Frederick , Guenter Roeck , Kees Cook , Mike Rapoport , Pavel Tatashin , Petr Mladek , Robin Holt , Linus Torvalds , Sudip Mukherjee Subject: [PATCH 4.4 62/64] reboot: fix overflow parsing reboot cpu number Date: Tue, 17 Nov 2020 14:05:25 +0100 Message-Id: <20201117122109.241383427@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122106.144800239@linuxfoundation.org> References: <20201117122106.144800239@linuxfoundation.org> User-Agent: quilt/0.66 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: Matteo Croce commit df5b0ab3e08a156701b537809914b339b0daa526 upstream. Limit the CPU number to num_possible_cpus(), because setting it to a value lower than INT_MAX but higher than NR_CPUS produces the following error on reboot and shutdown: BUG: unable to handle page fault for address: ffffffff90ab1bb0 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page PGD 1c09067 P4D 1c09067 PUD 1c0a063 PMD 0 Oops: 0000 [#1] SMP CPU: 1 PID: 1 Comm: systemd-shutdow Not tainted 5.9.0-rc8-kvm #110 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-2.fc32 04/01/2014 RIP: 0010:migrate_to_reboot_cpu+0xe/0x60 Code: ea ea 00 48 89 fa 48 c7 c7 30 57 f1 81 e9 fa ef ff ff 66 2e 0f 1f 84 00 00 00 00 00 53 8b 1d d5 ea ea 00 e8 14 33 fe ff 89 da <48> 0f a3 15 ea fc bd 00 48 89 d0 73 29 89 c2 c1 e8 06 65 48 8b 3c RSP: 0018:ffffc90000013e08 EFLAGS: 00010246 RAX: ffff88801f0a0000 RBX: 0000000077359400 RCX: 0000000000000000 RDX: 0000000077359400 RSI: 0000000000000002 RDI: ffffffff81c199e0 RBP: ffffffff81c1e3c0 R08: ffff88801f41f000 R09: ffffffff81c1e348 R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000 R13: 00007f32bedf8830 R14: 00000000fee1dead R15: 0000000000000000 FS: 00007f32bedf8980(0000) GS:ffff88801f480000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: ffffffff90ab1bb0 CR3: 000000001d057000 CR4: 00000000000006a0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: __do_sys_reboot.cold+0x34/0x5b do_syscall_64+0x2d/0x40 Fixes: 1b3a5d02ee07 ("reboot: move arch/x86 reboot= handling to generic kernel") Signed-off-by: Matteo Croce Signed-off-by: Andrew Morton Cc: Arnd Bergmann Cc: Fabian Frederick Cc: Greg Kroah-Hartman Cc: Guenter Roeck Cc: Kees Cook Cc: Mike Rapoport Cc: Pavel Tatashin Cc: Petr Mladek Cc: Robin Holt Cc: Link: https://lkml.kernel.org/r/20201103214025.116799-3-mcroce@linux.microsoft.com Signed-off-by: Linus Torvalds [sudip: use reboot_mode instead of mode] Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- kernel/reboot.c | 7 +++++++ 1 file changed, 7 insertions(+) --- a/kernel/reboot.c +++ b/kernel/reboot.c @@ -519,6 +519,13 @@ static int __init reboot_setup(char *str reboot_cpu = simple_strtoul(str+3, NULL, 0); else reboot_mode = REBOOT_SOFT; + if (reboot_cpu >= num_possible_cpus()) { + pr_err("Ignoring the CPU number in reboot= option. " + "CPU %d exceeds possible cpu number %d\n", + reboot_cpu, num_possible_cpus()); + reboot_cpu = 0; + break; + } break; case 'g':