Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3874888pxb; Tue, 17 Nov 2020 05:59:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJzBkXqgyRTTfazRRZU6pZxkErDrnNBtcqTMsBRdsObbzBdiMOMOaQ98cRkEvK+ZxvzOHWll X-Received: by 2002:a17:906:b150:: with SMTP id bt16mr19856220ejb.257.1605621571797; Tue, 17 Nov 2020 05:59:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605621571; cv=none; d=google.com; s=arc-20160816; b=Xasf06WAIWKymwA08P9J2S1/hiy7L6eMkhrXXatzO/ih0seBBv9ZqUcdClIS5HZQMu 1kDtk7QiWxvTCfYmFJITpFAFL3CKr8IV+SIt7wgNO1cV23E+9Def3K4d/t2I/9YiWFvB fEWF9WKRHteFJampUGUgJPKNG12X1o5KEWX6eB1oSqyM/ExuJIMZfM90e8lLIA6KAYKG 4reL4wxRBQKRL/mBEl4Pt80MjJaHy03hGAuCAQR7GpFw3INeCjhGpHlb1oFI63MFB0oq +GvIRjD2SwpRRhWWu/cWKz9cZs+BVf0EfHK5Wn2U766HW/uf/Rp/TGKYoAOg/urW/LHZ 2pCg== 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=BSFlNBepL0mMdeUCFob1bYhMs+c/BiKF576dZdgMm08=; b=hgzYCIoiLrKjXMj9TxFaaRibKTgKAfkISq8Ptl/kaDZ7Hk0t0pDvoI9Njw5DYbnHh4 R6wF5vI8S+sidN/+eQm5IYDlSaP0RI5TsY+ge4yqKP3+/w4+aB9pSD0M1fQTxC0EQkzJ eFsAtZNelOb4CLwyXbiS9l74drTaGlWqljc1pTvmi2Ab5rxePSC4l0SxVouy01a2e53v Y2hcvWF8MIgpVlB0Jah84e7/vWToL7zijiFyCpwsipxTbRcftFSxJXL1JvQdDPXq/lTd qfwYgASe3DdAAGJwRudelprRXkMIGYZUzS40iZFPeb9pVziS5k0s1nABJs/37iX1jH7Y kdbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zkEiJmb7; 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 f15si11532691edj.239.2020.11.17.05.59.09; Tue, 17 Nov 2020 05:59:31 -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=zkEiJmb7; 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 S1730350AbgKQNWJ (ORCPT + 99 others); Tue, 17 Nov 2020 08:22:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:56050 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730695AbgKQNVz (ORCPT ); Tue, 17 Nov 2020 08:21:55 -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 C09AA2465E; Tue, 17 Nov 2020 13:21:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605619314; bh=JcCtDXP1TBnDBsuxkDxtzwebT7QyzeH9ixZ2iy/s/Wo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zkEiJmb7Rjr3AIavOCtXOgXqLlbqvqNM2c2vOmEvyHcaFGf7XTJSgB3lgOi9LxKke KhDT39kPz5u7dXsuhxG6Du3mpcS8vBzHpw7HjLlTJ9+pCIjKVHfD1VOoRrLYH6rJv3 m0TL9YtZizyIWlbWyf3k/Hqggx8zMBuTPDrEaFaw= 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.19 099/101] reboot: fix overflow parsing reboot cpu number Date: Tue, 17 Nov 2020 14:06:06 +0100 Message-Id: <20201117122117.951015215@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122113.128215851@linuxfoundation.org> References: <20201117122113.128215851@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 @@ -546,6 +546,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':