From patchwork Wed Dec 21 19:45:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 35498 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp3711728wrn; Wed, 21 Dec 2022 11:48:15 -0800 (PST) X-Google-Smtp-Source: AMrXdXuTEyavH2Chawhwkco/mYWMX/UCF4HQcuKizzA12JJHoURpuwgPPYaWaq5DjXxqsx11qPfh X-Received: by 2002:a17:90a:ac04:b0:225:ad50:3b18 with SMTP id o4-20020a17090aac0400b00225ad503b18mr811042pjq.25.1671652094842; Wed, 21 Dec 2022 11:48:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671652094; cv=none; d=google.com; s=arc-20160816; b=AQwCijtTzevdQKoAbBnY+zbnX8IRPRA/NtKHADA+Dk4WiYWKJ3FMnKh+0A+BtNk+n0 s1Zxqi81Pdg74jBHj9sSeKBcNYvAiiIdYaG9EJbCd6ADZlZw4tAqxJ2K8c5/7M0wkyyL M3ifMVzYM6K42/IWu+f8a88tCDg9P0F/dm/cGkVc+U5fEfE62BOks0Pru96/QdtjDZYL FcY+i0AbfkFeaxnqReM9+qMFHLzYv/iJcsJI/n+f8F7DBSAN60md3ZS+t3LKpCTLU4+e 2RuU8iw7PG1fXWzLgtJVJP9hwkvMzGk6/22TH0gbY9mXhJm9TZwYhG35h+TB0HLEZxtG W4/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=xv7lgqcsWR7csyQW/ua9GbEMjmdKQM2eL6DIBrKZNHc=; b=cPGF/nxx5NAwIxAcQM10OrmsLK+dt3LhXM6EokvqSrUyxIfvIiRthAn22KcCidPMjE qo3r+PTM2kfkPT85t+MZhHW/gBkbRK/iMoleBsVHrHBNwDEJvF5fKjqoTcFJUzNmuwCF i3aPjzWYyUGg3Fs45+TxIIQJ7H0qacSR7TXIvidR3VSv9VpT0CiNAOaZ/fbCx3vCGtwO 9WtD1jlqfWCHHWavKcdfVfkKN98szr2Qm4PkbPPoEyqVTa3FQ2D2DM1AlUcNINcmlGzJ 8NrffCBTnfcdM84s44gvuceQN4s/Krg6pqAtpPEIt0hq4dNehIwd6aQqgzPxV0ODZch7 Ztcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=RQbFTmSp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cx3-20020a17090afd8300b002193e1a906esi2328693pjb.133.2022.12.21.11.48.02; Wed, 21 Dec 2022 11:48:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=RQbFTmSp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234668AbiLUTqU (ORCPT + 99 others); Wed, 21 Dec 2022 14:46:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233283AbiLUTqP (ORCPT ); Wed, 21 Dec 2022 14:46:15 -0500 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A12B325E8E for ; Wed, 21 Dec 2022 11:46:12 -0800 (PST) Received: by mail-ed1-x536.google.com with SMTP id m19so23454657edj.8 for ; Wed, 21 Dec 2022 11:46:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=xv7lgqcsWR7csyQW/ua9GbEMjmdKQM2eL6DIBrKZNHc=; b=RQbFTmSpCufgNXH4cjE/NEaU/tEsNuzVOXIbI8CwMamw5qAWhVCN2G0OePZAGiA7kj 1F+gYgX+YqQxgMX8QnWDLWOUT9frqU8rVVDlo2XOFQL2RcFmTwvlLp/ylO6/Ec1sZ1je yQOoeN3E69nDmdnkj/Bn6C32nSB4lRotDVDZs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xv7lgqcsWR7csyQW/ua9GbEMjmdKQM2eL6DIBrKZNHc=; b=et5m9Oq6XR0dcMIM/vp0xVkGka2AaZAFrepxi/rfHGbeJT5DF5UQmOnTs9hEVCQzOh XPwmZqZRErzDnB1iWU4FpzGIBgXjdh34ZWLoNX6Kfxi+32t2phozgIt6S4toFw7LUArQ J7xAAH+Liq+/RiRtG4cmRWSVeLrz0wupKeqa4upcWV6uUDac/Rg6wRTxoZAxnHDDOv48 VAwcDfo2E7xVBDaAuPwEVYCKGGtYkdE6YzY79k6v/pywtsx1QGVOsljPxTV2E6p/UZqA VQdacHnl2Al1ivBpzn1g3lK8Rg+AxpBkYctCkYeuxS0fjBnBRtYV7g//wxKDfPIKjsXB 177Q== X-Gm-Message-State: AFqh2kppPImjEDD3AfFqyQnycH+KkbxpJMzyCR7RtAgKVfW3d8IRXM8D /a+JbuD5bw8Oj7diGGXglt/9ag== X-Received: by 2002:a50:fd10:0:b0:46d:aef2:3350 with SMTP id i16-20020a50fd10000000b0046daef23350mr3127946eds.26.1671651971256; Wed, 21 Dec 2022 11:46:11 -0800 (PST) Received: from alco.roam.corp.google.com (80.71.134.83.ipv4.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id f24-20020a056402005800b0046cbcc86bdesm7382008edu.7.2022.12.21.11.46.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 11:46:11 -0800 (PST) From: Ricardo Ribalda Date: Wed, 21 Dec 2022 20:45:57 +0100 Subject: [PATCH v5 1/3] Documentation: sysctl: Correct kexec_load_disabled MIME-Version: 1.0 Message-Id: <20221114-disable-kexec-reset-v5-1-1bd37caf3c75@chromium.org> References: <20221114-disable-kexec-reset-v5-0-1bd37caf3c75@chromium.org> In-Reply-To: <20221114-disable-kexec-reset-v5-0-1bd37caf3c75@chromium.org> To: "Guilherme G. Piccoli" , Eric Biederman , Jonathan Corbet , Philipp Rudo Cc: Ross Zwisler , Sergey Senozhatsky , Steven Rostedt , kexec@lists.infradead.org, Ricardo Ribalda , "Joel Fernandes (Google)" , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=1258; i=ribalda@chromium.org; h=from:subject:message-id; bh=U6cVA0f3MVv7jTHbprLKEENRfx9C5MeH7N8/eIFjhzo=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjo2J7s4JnwPmuL15uZ+xM4QsaksUW5vucOTw7PXPE fZ88t7CJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY6NiewAKCRDRN9E+zzrEiDaJD/ 0bTQsbJRZ8Zw4ky/CUdrnkq+0uRbLoHVXu1ml36UHUihbFPSWbVefZ5p1bYmwIZmSzSEOemUBtbWdT eCmm343+ZRdig25r3HYVQIPjfZmV3J4KTW1CW2kJ/RYT7TV+eqt/2WIoUfoJ+caPbmQMSk2sX9JKNe iijWrC7+ouZanLCd/BxoBeKuuYxs23zGypKigm9U8VNs+DkSs81Bzs3scnfDafdqogSPF8hXbIbarZ oYujynTcfBNl3PXB6y3B6cJqOY/XAekyQrlGk2qzoIdtLj1ehxmNAcSQb9+iFt5B1oCkklY6C/E2XX Nasw1eCd8feM4nAnrK7M5JGDx676PMd/68QY1M1yPkv4/4eQei8ivJydAsQTcda25vtz6qRzt3oziG 5aPY9IuCSwEUB/A49HgpyPNeO3QQyjM/JRlwFsngYGpwhUoLjMHpkW2ic3AlmQyZz3dxm92CG0nH80 9HJmFnuxPGB1Zps0f8nXKPz8DHobHLJPNu8nwBs6F2O2o5m6u0I3dlHrcwLEQS1eG7KZWLLfA93nPc BGj1rKeM5vda3r4fqTGmqxUFj5yoH5KqsYwSG8iPQfUQMSVO07eiyfXsDi2RZdrO8JPAG/120gdoY1 Tqqx7ihn4UKRARwU+N4J0xr0tgvT6t1e8J1doKvNiEfsUHBHmrvedZ9miHuw== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752854266955113014?= X-GMAIL-MSGID: =?utf-8?q?1752854266955113014?= kexec_load_disabled affects both ``kexec_load`` and ``kexec_file_load`` syscalls. Make it explicit. Signed-off-by: Ricardo Ribalda --- Documentation/admin-guide/sysctl/kernel.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst index 98d1b198b2b4..97394bd9d065 100644 --- a/Documentation/admin-guide/sysctl/kernel.rst +++ b/Documentation/admin-guide/sysctl/kernel.rst @@ -450,9 +450,10 @@ this allows system administrators to override the kexec_load_disabled =================== -A toggle indicating if the ``kexec_load`` syscall has been disabled. -This value defaults to 0 (false: ``kexec_load`` enabled), but can be -set to 1 (true: ``kexec_load`` disabled). +A toggle indicating if the syscalls ``kexec_load`` and +``kexec_file_load`` have been disabled. +This value defaults to 0 (false: ``kexec_*load`` enabled), but can be +set to 1 (true: ``kexec_*load`` disabled). Once true, kexec can no longer be used, and the toggle cannot be set back to false. This allows a kexec image to be loaded before disabling the syscall, From patchwork Wed Dec 21 19:45:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 35499 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp3712170wrn; Wed, 21 Dec 2022 11:49:34 -0800 (PST) X-Google-Smtp-Source: AMrXdXtrIrdCJ+S0/Fq5U47gnvmcKVY3RktP0OpDsEhRHNn++zmRhgsDigj4n5n2RftqxwhVaxdz X-Received: by 2002:a17:90b:3c0a:b0:219:f383:abf0 with SMTP id pb10-20020a17090b3c0a00b00219f383abf0mr2719182pjb.37.1671652174753; Wed, 21 Dec 2022 11:49:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671652174; cv=none; d=google.com; s=arc-20160816; b=P/8SwGTLcDGYd6zdKivok7y0WfPN1FYFQdBiA7oWnJ870tV8ZwOFN6o3w06Lh/kT3U KFFx0MMUPg88jVbwjiplc3xDyU54ICjyem0MPwVRim2xfDoGTkzjC75bQg8D27+tXghg uxyRZk7kN/cZrCZCZvBtYaGyAD17z0VecBP/C27/Xpf6Oq4t8CNCWOziXB8zjTbiH077 W/R5C8f7AT2tntyc6QUcf/xJFbOQIo9AyUVXCLAHsgXNYSVI426jdrrrZoZV6rgUzZ+B DfR/b8rIeuoKevJNNP47ljkLp5OHGBK7VOUzj8G7E6sHUfwD4k3Ct7C5U2yqMhN/wYW5 S5+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=0uo7tfZaiqOin2cp8QemVMZCCRCz92hxCxC8vhk5Wl8=; b=tDlLVlSqg4j+7rrKBxmHEp3wVokEnbQ2l+SWNNIdcrG9OsIpH2V38CaJbxTZbpt1Zu 2iektgurAirV2MaHIS9fllFo0+JtylKnXHxUhNyxEej59ADUpLDiLPnqPqoAN4eA16qU 0AdpoIhCkpTOhkFTVIbgzMD7kSY1QjYjFBL71hEkbW+kzWp2fopW8QOpWqqf1hLb9hmI PoIs79mDtqn+TXT2Ugbzge45SeJpWSHkgpijNlYbaCD2N6oBs+Y48XBzN0h8zacN6zaZ k4XdJidWYBItnqYEO/uMEN/LQa2HEEuEWLpmZ4+dS390SQ9psEHnQSbyC/aXgyEudSit 6nWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=WX7m0hFp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cx3-20020a17090afd8300b002193e1a906esi2328693pjb.133.2022.12.21.11.49.21; Wed, 21 Dec 2022 11:49:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=WX7m0hFp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234792AbiLUTq0 (ORCPT + 99 others); Wed, 21 Dec 2022 14:46:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234210AbiLUTqP (ORCPT ); Wed, 21 Dec 2022 14:46:15 -0500 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81DEC26109 for ; Wed, 21 Dec 2022 11:46:13 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id z92so32892ede.1 for ; Wed, 21 Dec 2022 11:46:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=0uo7tfZaiqOin2cp8QemVMZCCRCz92hxCxC8vhk5Wl8=; b=WX7m0hFptzAKKxKsaaznTLCeqXMlEsjlHE0rP+ZyG0YNSw3h+7aI7mg0glILNtGFCz kzOlSrRMq6Oix0VtjYBFRnisX2Hn0x2yoaYyc6H5n87Xgzm59sWQtqEsetF/PRaxhxNX gSrN4JjE5E5W5C9pns16Llt81QhijcSi4pGHE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0uo7tfZaiqOin2cp8QemVMZCCRCz92hxCxC8vhk5Wl8=; b=GwFwfO/E3qMbOJw5UWrrevWIapXcmoQNT1xoCz3eX4+HkkoDBAq/psClM4OWPyrruU k2FGGZQxM6zpk4y2tEQZfimz51J88ujQqAAFA9z3MTF37uy33Bl8UkYmeamChs5UY8pQ Oys/qw/+an+Qc5rohOKThrgCHz3DmkzgCSaqqhI2pb58dpchbiIfYI/MVtsrecQ9xav9 HSyO9k94xW1yEeg8SAqIZP7bSdqANR6lZLYzoE/5ZC4guhCF7v0U2btkMj12vKbK30ub EZvTI33oCpj5TT4YfKUE5dlRo94l+p7cmBHkq0UdR4F6PN7LqNtYRDwtZ7HxEzsvQtCH VGWg== X-Gm-Message-State: AFqh2kpPVN+Q/6M0yWd0SkTaGaWvwpH94CDHth/7RRz9Xd/r0n5hWlKy WKEvu+9599nJ6lRmf3nk5CiN7Q== X-Received: by 2002:a05:6402:501f:b0:460:5706:d1fa with SMTP id p31-20020a056402501f00b004605706d1famr2808261eda.18.1671651972067; Wed, 21 Dec 2022 11:46:12 -0800 (PST) Received: from alco.roam.corp.google.com (80.71.134.83.ipv4.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id f24-20020a056402005800b0046cbcc86bdesm7382008edu.7.2022.12.21.11.46.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 11:46:11 -0800 (PST) From: Ricardo Ribalda Date: Wed, 21 Dec 2022 20:45:58 +0100 Subject: [PATCH v5 2/3] kexec: Factor out kexec_load_permitted MIME-Version: 1.0 Message-Id: <20221114-disable-kexec-reset-v5-2-1bd37caf3c75@chromium.org> References: <20221114-disable-kexec-reset-v5-0-1bd37caf3c75@chromium.org> In-Reply-To: <20221114-disable-kexec-reset-v5-0-1bd37caf3c75@chromium.org> To: "Guilherme G. Piccoli" , Eric Biederman , Jonathan Corbet , Philipp Rudo Cc: Ross Zwisler , Sergey Senozhatsky , Steven Rostedt , kexec@lists.infradead.org, Ricardo Ribalda , "Joel Fernandes (Google)" , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=2724; i=ribalda@chromium.org; h=from:subject:message-id; bh=rm7FZlNI1K3HcWDQ5vaPpIW63r8rInBklo9MHxPCtFE=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjo2J+j6VSiwnd2NWq7ZYy+eTh20kxBVZ9N+tQgsO4 igsMiaWJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY6NifgAKCRDRN9E+zzrEiGD7EA CYxHLKOPM0+bvFezijOnO/4euoKLtab/2RYTcKlJRXfaLDSfpGPq/yiF2XmosQXz9H1wOwxZjPq0UV S+/PlFVreAJhuOn9yogBEAdK9wkQu4xJUtE84othkWC84aYXOHQK6PSZCScw6dWYV3JV2v3JOrNqB3 hRcsbyMxlyPsXIdpxlwA6ZHmdLVsivB1zoYcJl7CwUGPNcC+/OLyyVORgUI55LdUAVqeHxyaVfuGav gY8xZzttKJEAlpzfB5cz7yyqK1Zd5FPdV/1BDsxLEG2G1ej1IFkaoUZItbfAPHq+w/q+zJfpv76m3L 7bw4bH8WT321wqTso6Ixppe2rUErDpNDtDWSUJJDIlRZJeWmr0opiVPxaG+i51uWHfO3d7YKV6JJ16 ACej0FAbBCJgZgAGSWby008b6GoyJWcMoN4a6xfP6hEDqjsmSYDJ+GQNBuWg3U0t/PlFDJbQZS2Y2c C3QCGfQ+o+6QYZ5RTV0pv90pQZunYJ3VJlaxVD16OSM+HRroJGo1zhLgJeMbDr+00+BNw9BRUnEtQk KQ7E20venuQA+qKYRD+AB1egECzOpXL1bpBMNjmE8254qy60xBRjk3iM1dqnApJPFBI9qSKY4V39ZC kH4XZdG16Fnrhi2q3Mr4lD8J1Q5WMmGdya5RTg4lw0296MOpLuJqkhRD3+Gw== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752854350456534432?= X-GMAIL-MSGID: =?utf-8?q?1752854350456534432?= Both syscalls (kexec and kexec_file) do the same check, lets factor it out. Signed-off-by: Ricardo Ribalda --- include/linux/kexec.h | 3 ++- kernel/kexec.c | 2 +- kernel/kexec_core.c | 11 ++++++++++- kernel/kexec_file.c | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 41a686996aaa..182e0c11b87b 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -406,7 +406,8 @@ extern int kimage_crash_copy_vmcoreinfo(struct kimage *image); extern struct kimage *kexec_image; extern struct kimage *kexec_crash_image; -extern int kexec_load_disabled; + +bool kexec_load_permitted(void); #ifndef kexec_flush_icache_page #define kexec_flush_icache_page(page) diff --git a/kernel/kexec.c b/kernel/kexec.c index cb8e6e6f983c..ce1bca874a8d 100644 --- a/kernel/kexec.c +++ b/kernel/kexec.c @@ -193,7 +193,7 @@ static inline int kexec_load_check(unsigned long nr_segments, int result; /* We only trust the superuser with rebooting the system. */ - if (!capable(CAP_SYS_BOOT) || kexec_load_disabled) + if (!kexec_load_permitted()) return -EPERM; /* Permit LSMs and IMA to fail the kexec */ diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index ca2743f9c634..a1efc70f4158 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -928,7 +928,7 @@ int kimage_load_segment(struct kimage *image, struct kimage *kexec_image; struct kimage *kexec_crash_image; -int kexec_load_disabled; +static int kexec_load_disabled; #ifdef CONFIG_SYSCTL static struct ctl_table kexec_core_sysctls[] = { { @@ -952,6 +952,15 @@ static int __init kexec_core_sysctl_init(void) late_initcall(kexec_core_sysctl_init); #endif +bool kexec_load_permitted(void) +{ + /* + * Only the superuser can use the kexec syscall and if it has not + * been disabled. + */ + return capable(CAP_SYS_BOOT) && !kexec_load_disabled; +} + /* * No panic_cpu check version of crash_kexec(). This function is called * only when panic_cpu holds the current CPU number; this is the only CPU diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 45637511e0de..29efa43ea951 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -330,7 +330,7 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd, struct kimage **dest_image, *image; /* We only trust the superuser with rebooting the system. */ - if (!capable(CAP_SYS_BOOT) || kexec_load_disabled) + if (!kexec_load_permitted()) return -EPERM; /* Make sure we have a legal set of flags */ From patchwork Wed Dec 21 19:45:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 35500 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp3713040wrn; Wed, 21 Dec 2022 11:52:08 -0800 (PST) X-Google-Smtp-Source: AMrXdXuTDJIyiY9N17FLqBxK7cZRnl1nHmyUXW+KixbKD+T40P1niFGIwcEUvf/RGNzRmfjymimJ X-Received: by 2002:a17:907:c92a:b0:7c1:6344:840 with SMTP id ui42-20020a170907c92a00b007c163440840mr2005314ejc.24.1671652328481; Wed, 21 Dec 2022 11:52:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671652328; cv=none; d=google.com; s=arc-20160816; b=XGCPfwBzpjRUbohXYKSCeL6OXEESlOetZcJMmlxSPFjKuZfCsFJwQ51m+NWuIGJBGG s1F5T/YHeL76+98BrA2AD6TMjFYM6IXf1uhXAPgIoEdt6wWTBPixWA+pElLu+fpw8t2D fCv0lkCvnUk0PcbZPINdv66BnVIwlk8qT9QUtX2gY/2PTPzSR93AeDRvMRJAY+cGlaji YG4bEQk+dSO8MOLhQ4NTKVNcPB7hxd1j5TiVUs+RICxg3BjuXyv41RD6nyDBcPz7luJp wCP+RMuGQ6vIeeU/FgdM1cJSjdE/hReD/+CeyoiwoDD5gWCWq26SP29MSzVokVMfDOi4 /S9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=8WMtn3c3gpWE05X13XBtql1qRSWe7APE4L2Sbgmggnc=; b=q5ZwSEPAh7BmTe6gejfKQlcMQaJcZJNoFAKIXhpfqp4lXlqI4+tl3ysWqTwU6OoFXm rqwo0MTSHtMAt59xuRbRFY5h2Vv01EeBlUn5W0jgGuBTfSW91vqPCu/NELhOcxPTV1Vs AR2E3nMowugSwYTQg3jGHALGUV0S/mZvW+ZPhxl5qS442K6lvKwexW/jhay+2QLQo/XZ BCdOqoT9q9sojHb5Nq2Esjn4/vvGwvDNp9S6F7H1hvp8Xyn88ulHeU4CsXMvaDoSkIIq AVxZ4AMD7tei2zlpJMlsh1vNjaFCnsqGOLLj51F93mDZR75OfDgW2fw2sc2JzG+9nITD Ny+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kfWUeKOb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id wt12-20020a170906ee8c00b007a92b00c094si4945352ejb.421.2022.12.21.11.51.43; Wed, 21 Dec 2022 11:52:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kfWUeKOb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234804AbiLUTq3 (ORCPT + 99 others); Wed, 21 Dec 2022 14:46:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234296AbiLUTqQ (ORCPT ); Wed, 21 Dec 2022 14:46:16 -0500 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52AAC23EB5 for ; Wed, 21 Dec 2022 11:46:14 -0800 (PST) Received: by mail-ej1-x62b.google.com with SMTP id ud5so30327ejc.4 for ; Wed, 21 Dec 2022 11:46:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=8WMtn3c3gpWE05X13XBtql1qRSWe7APE4L2Sbgmggnc=; b=kfWUeKObDucY3ttXwvmnW6H3aQHW7MbPw2qZSiY5uhfCg9F6pDBSHjdJtUpiwekPqs D7f5wfCCqLn/FNRDgUnFCPcX19UsTEybjftvnd4T9uR+u5sbuji5WA/ogtq7hg5RBoM9 GsRHxRJAsY1snXXf943+/bcTHc8KgXL2fODG0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8WMtn3c3gpWE05X13XBtql1qRSWe7APE4L2Sbgmggnc=; b=OJ+Tvcn0BGnWWiVjQC3o+zGUoAqSUmFn3ELcJf2V/lvuc0IxWkQ8DqnHEciEdOg2od SQaSqPazZHdNgNgJuW4R7ZGUeCwJx8y8WDhX+uPQF0VQs4P69gaNMqDn/74CxTTCCrKE H+2K05jWmQQk49bYoCXWcbWfci7Z3BsXrNxFmYdnYu28awZQzDNQDm9oe4lKO+9MvI3I 6/P2VrcdyTZG6PRpoHnjEQQQIfmKbdg+B+ILT5js6pdMRuX3CmjNwLHtaxzfVVZWDu6t wOlG22OfUV1f7dGsQUwV6qmVu69wjCPsPHMU2iOCSZWtwnlFXAC51QiMHSSTIlGAIlgu uVqg== X-Gm-Message-State: AFqh2ko5qsqaGKqlPZsTEEgfsWv4CuhNFHnU6papdO3yJHMRAztIT8fU M5FDqXJVwKJxex5UdROLEJxx2Q== X-Received: by 2002:a17:906:c34d:b0:78d:f455:b5de with SMTP id ci13-20020a170906c34d00b0078df455b5demr2255047ejb.30.1671651972842; Wed, 21 Dec 2022 11:46:12 -0800 (PST) Received: from alco.roam.corp.google.com (80.71.134.83.ipv4.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id f24-20020a056402005800b0046cbcc86bdesm7382008edu.7.2022.12.21.11.46.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 11:46:12 -0800 (PST) From: Ricardo Ribalda Date: Wed, 21 Dec 2022 20:45:59 +0100 Subject: [PATCH v5 3/3] kexec: Introduce sysctl parameters kexec_load_limit_* MIME-Version: 1.0 Message-Id: <20221114-disable-kexec-reset-v5-3-1bd37caf3c75@chromium.org> References: <20221114-disable-kexec-reset-v5-0-1bd37caf3c75@chromium.org> In-Reply-To: <20221114-disable-kexec-reset-v5-0-1bd37caf3c75@chromium.org> To: "Guilherme G. Piccoli" , Eric Biederman , Jonathan Corbet , Philipp Rudo Cc: Ross Zwisler , Sergey Senozhatsky , Steven Rostedt , kexec@lists.infradead.org, Ricardo Ribalda , "Joel Fernandes (Google)" , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=7080; i=ribalda@chromium.org; h=from:subject:message-id; bh=wjOv1kjeZCTcr83lBBKlpshLnU6euVnomopYZ4Y2tkg=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjo2J/jUTf5Bub+D3fWzqRqf9/P57dD764DcRO2C+6 /CmMFZyJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY6NifwAKCRDRN9E+zzrEiBYwD/ 0doNCURaknqHC+qQW+dsQrYiP3jY0XwQQqM72OhAZNNy4MlvEwIoyeOkbV3GDBSRPAKeduCFLVzy55 NQmb+W9f3A1h0nhimYEbI+N+Csch1GYhL1uYnuskt9EhTY8yAKixxL+VO5FaAlFPU4I+CtiFaox11z efiKTNI4aUu3PLNHZ+IEiLSsZSncw/+JTXEasIbJ2g0KlX5kt15MnkfnItriuibnjaXfD8OKWzXCth QVK8S2h0/KmTR1CiCdoynGo+BJXiYYxXWUpLbIz7rhJ1lAh1Gm3eyga+6wROZOiS4q5w0htQNk6S9g h0JnaWvXIYa0/WzAi7czsje+qhgdN2EjmewdUWfkBT2gV+g+Zb3Pb9DoVLBfJ7Yu0bCFp59sSIKh2s jXqIvh4/sIS9nqr4OOcVMjXXKpnHF7ewnWw6bXGe9V1BfuVzrvqm3Ukd85tP4v3KpRiV+fs7PFTgl8 fzJ/ipFCibsgkXZboA5aDlKFY7KTppUfsB85XO4F/3CpHPfNnZ0yAQXrEeLvIhoFMGP0/GFEwc3WxA ww0cn81HBQfVTtKv6231eDe4cBuZM3iSQGGOzJSlq8QjKafMzWEuW7QW9lxy0443G0nYuV9N5tsYL5 Ybi+b2NVHSVlFn+yT7xp8ynf9LQ3VUVY5nzmoeuvwkRbdoynhFVRBnvYoXUA== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752854512447447526?= X-GMAIL-MSGID: =?utf-8?q?1752854512447447526?= Add two parameters to specify how many times a kexec kernel can be loaded. The sysadmin can set different limits for kexec panic and kexec reboot kernels. The value can be modified at runtime via sysctl, but only with a value smaller than the current one (except -1). Signed-off-by: Ricardo Ribalda --- Documentation/admin-guide/sysctl/kernel.rst | 18 ++++++ include/linux/kexec.h | 2 +- kernel/kexec.c | 4 +- kernel/kexec_core.c | 87 ++++++++++++++++++++++++++++- kernel/kexec_file.c | 11 ++-- 5 files changed, 114 insertions(+), 8 deletions(-) diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst index 97394bd9d065..a3922dffbd47 100644 --- a/Documentation/admin-guide/sysctl/kernel.rst +++ b/Documentation/admin-guide/sysctl/kernel.rst @@ -461,6 +461,24 @@ allowing a system to set up (and later use) an image without it being altered. Generally used together with the `modules_disabled`_ sysctl. +kexec_load_limit_panic +====================== + +This parameter specifies a limit to the number of times the syscalls +``kexec_load`` and ``kexec_file_load`` can be called with a crash +image. It can only be set with a more restrictive value than the +current one. + += ============================================================= +-1 Unlimited calls to kexec. This is the default setting. +N Number of calls left. += ============================================================= + +kexec_load_limit_reboot +====================== + +Similar functionality as ``kexec_load_limit_panic``, but for a crash +image. kptr_restrict ============= diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 182e0c11b87b..791e65829f86 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -407,7 +407,7 @@ extern int kimage_crash_copy_vmcoreinfo(struct kimage *image); extern struct kimage *kexec_image; extern struct kimage *kexec_crash_image; -bool kexec_load_permitted(void); +bool kexec_load_permitted(int kexec_image_type); #ifndef kexec_flush_icache_page #define kexec_flush_icache_page(page) diff --git a/kernel/kexec.c b/kernel/kexec.c index ce1bca874a8d..92d301f98776 100644 --- a/kernel/kexec.c +++ b/kernel/kexec.c @@ -190,10 +190,12 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments, static inline int kexec_load_check(unsigned long nr_segments, unsigned long flags) { + int image_type = (flags & KEXEC_ON_CRASH) ? + KEXEC_TYPE_CRASH : KEXEC_TYPE_DEFAULT; int result; /* We only trust the superuser with rebooting the system. */ - if (!kexec_load_permitted()) + if (!kexec_load_permitted(image_type)) return -EPERM; /* Permit LSMs and IMA to fail the kexec */ diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index a1efc70f4158..951541d78ca8 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -926,10 +926,64 @@ int kimage_load_segment(struct kimage *image, return result; } +struct kexec_load_limit { + /* Mutex protects the limit count. */ + struct mutex mutex; + int limit; +}; + +static struct kexec_load_limit load_limit_reboot = { + .mutex = __MUTEX_INITIALIZER(load_limit_reboot.mutex), + .limit = -1, +}; + +static struct kexec_load_limit load_limit_panic = { + .mutex = __MUTEX_INITIALIZER(load_limit_panic.mutex), + .limit = -1, +}; + struct kimage *kexec_image; struct kimage *kexec_crash_image; static int kexec_load_disabled; + #ifdef CONFIG_SYSCTL +static int kexec_limit_handler(struct ctl_table *table, int write, + void *buffer, size_t *lenp, loff_t *ppos) +{ + struct kexec_load_limit *limit = table->data; + int val; + struct ctl_table tmp = { + .data = &val, + .maxlen = sizeof(val), + .mode = table->mode, + }; + int ret; + + if (write) { + ret = proc_dointvec(&tmp, write, buffer, lenp, ppos); + if (ret) + return ret; + + if (val < 0) + return -EINVAL; + + mutex_lock(&limit->mutex); + if (limit->limit != -1 && val >= limit->limit) + ret = -EINVAL; + else + limit->limit = val; + mutex_unlock(&limit->mutex); + + return ret; + } + + mutex_lock(&limit->mutex); + val = limit->limit; + mutex_unlock(&limit->mutex); + + return proc_dointvec(&tmp, write, buffer, lenp, ppos); +} + static struct ctl_table kexec_core_sysctls[] = { { .procname = "kexec_load_disabled", @@ -941,6 +995,18 @@ static struct ctl_table kexec_core_sysctls[] = { .extra1 = SYSCTL_ONE, .extra2 = SYSCTL_ONE, }, + { + .procname = "kexec_load_limit_panic", + .data = &load_limit_panic, + .mode = 0644, + .proc_handler = kexec_limit_handler, + }, + { + .procname = "kexec_load_limit_reboot", + .data = &load_limit_reboot, + .mode = 0644, + .proc_handler = kexec_limit_handler, + }, { } }; @@ -952,13 +1018,30 @@ static int __init kexec_core_sysctl_init(void) late_initcall(kexec_core_sysctl_init); #endif -bool kexec_load_permitted(void) +bool kexec_load_permitted(int kexec_image_type) { + struct kexec_load_limit *limit; + /* * Only the superuser can use the kexec syscall and if it has not * been disabled. */ - return capable(CAP_SYS_BOOT) && !kexec_load_disabled; + if (!capable(CAP_SYS_BOOT) || kexec_load_disabled) + return false; + + /* Check limit counter and decrease it.*/ + limit = (kexec_image_type == KEXEC_TYPE_CRASH) ? + &load_limit_panic : &load_limit_reboot; + mutex_lock(&limit->mutex); + if (!limit->limit) { + mutex_unlock(&limit->mutex); + return false; + } + if (limit->limit != -1) + limit->limit--; + mutex_unlock(&limit->mutex); + + return true; } /* diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 29efa43ea951..da9cfbbb0cbd 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -326,11 +326,13 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd, unsigned long, cmdline_len, const char __user *, cmdline_ptr, unsigned long, flags) { - int ret = 0, i; + int image_type = (flags & KEXEC_FILE_ON_CRASH) ? + KEXEC_TYPE_CRASH : KEXEC_TYPE_DEFAULT; struct kimage **dest_image, *image; + int ret = 0, i; /* We only trust the superuser with rebooting the system. */ - if (!kexec_load_permitted()) + if (!kexec_load_permitted(flags & KEXEC_FILE_ON_CRASH)) return -EPERM; /* Make sure we have a legal set of flags */ @@ -342,11 +344,12 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd, if (!kexec_trylock()) return -EBUSY; - dest_image = &kexec_image; - if (flags & KEXEC_FILE_ON_CRASH) { + if (image_type == KEXEC_TYPE_CRASH) { dest_image = &kexec_crash_image; if (kexec_crash_image) arch_kexec_unprotect_crashkres(); + } else { + dest_image = &kexec_image; } if (flags & KEXEC_FILE_UNLOAD)