Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3850079pxb; Tue, 17 Nov 2020 05:21:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJy4CBPcbDcUi34AFjNC/bozyc9hc1BmJ1jrn1/suvyLqFgWeONel0EawAaY8oUhLtdZlgQm X-Received: by 2002:a50:9ee4:: with SMTP id a91mr2664873edf.121.1605619296569; Tue, 17 Nov 2020 05:21:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605619296; cv=none; d=google.com; s=arc-20160816; b=EEBP6NNfnmPmU6WdmMlE4xzLGhYMjeXOQfp+WWjMWIAPfsKiSCJrtNeCMC3kr3Cqsj KLGW1fwM2gzlr3Z6Lkp36JV/UQxpArKFwod44N8cFjng0EJA8q0lw/wRB4ewjsnW/5Or zcTSizVu+7+N5QWQBoicVMm7mg3nA4CosBVbOb+WdwRKMqzSXj1nJgs3y2XLtJNy4Kth +6HNizTqwsAjGzfagdZPM7zed49V6+40f9dqlkvWDahpWTwK2HMu1K8mCpg3rcVQyAlE M+FDLZBFhPNy9yLqD1qixlfYxao2aq15liTPWK4VwNIv0dZmoNq2HZeh1V5T8DBw/uvW LuzA== 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=n/9LRE25dMcYaSqMU1FVeRCft5+zUtRALpflQKy3dvTHrOSz5KbTvHANDI9p7pQF5Q XlGW6UYzVIGPRvcJt2ZKI6WDgIm4BSKf9SSKj28QIJz/tJ3N8fvJ3ZiqxvUftt2XMIIy MIXlv6tZz+bezAOw+tjdyxUoGDfjI56dI/US7aCZy+e6sOaArpDg6nwpqpWIKdVVW5nz TlQhVrRI0peACI+EvZWeJhi1onvPrG6k7nXXKK5xE4PHqV8K4DTP7yDML9WLRpDZh71t rbuJidYctxbhF8yW89u6HdEK5WVSZ4l9vw6wFFLm6ijMq02N+AMbfCblW2lDHwCL2Joa NKNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KQgkOeNT; 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 h7si5823921edn.270.2020.11.17.05.21.12; Tue, 17 Nov 2020 05:21:36 -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=KQgkOeNT; 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 S1730179AbgKQNS4 (ORCPT + 99 others); Tue, 17 Nov 2020 08:18:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:48888 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730492AbgKQNQu (ORCPT ); Tue, 17 Nov 2020 08:16:50 -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 B510D2225B; Tue, 17 Nov 2020 13:16:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605619009; bh=Erzmw6T1KHPpYXvP6UTHaqQVh+xzUZeFxd3OXrj3tkM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KQgkOeNTcVYTOhxVmczsN/HGW1fbt38tixSF0UTBVvuMkK8tPwDa5cfIIV3R6QSmP vv6pKOEsaWtthNtPCH/oZo4AchJqHlAyhgMrb0TAThFT4eqj0aW2ooFYfUtFzqE2sM 1Xhyi2CaW4zbmICB5ZMmifU1WVofj0MGAfA0lbQo= 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.14 84/85] reboot: fix overflow parsing reboot cpu number Date: Tue, 17 Nov 2020 14:05:53 +0100 Message-Id: <20201117122115.170985258@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122111.018425544@linuxfoundation.org> References: <20201117122111.018425544@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':