From patchwork Tue Dec 20 22:05:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 35200 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp3205619wrn; Tue, 20 Dec 2022 14:08:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf4ruUsTe+dxfStzY4J8odK9MyL5A3RIfWomOaK/D06rp5kCDYdakBEc9JBpkezu39vKjTdC X-Received: by 2002:a17:906:c0c4:b0:78d:f455:b4d5 with SMTP id bn4-20020a170906c0c400b0078df455b4d5mr32523591ejb.60.1671574125394; Tue, 20 Dec 2022 14:08:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671574125; cv=none; d=google.com; s=arc-20160816; b=w1hWxieTki9O+KTe47tTLCUw/a+KLkx8x5Q2a6JvdE4ifr0Fw6JViGuOmqvnPCWuO9 yhgW2R3yaoCfwmOpIqWB5vWSDh6f7vcIkuFeM+0Uoly9vE7XULUl6KMBN9L6exRKQ/Io ds4zozFd3pq/z7CA8n5OyjgjEoSp8kdbNmFpaR9yKubVzCIrcZO21/3MZ3Mz7aQ3yrCI B74SBJWykL6LormoM7/JgwZtMQTdKA1Lfn1ZaGuHGYGsYbAyzvr47X+A5o6oQW4Fq8sA vff26SxxuTr9dyGzrYMGfVcNmPf0/zYPHAwGp1IZ+cVi8r8kPeSwO0yGmc4P5djlBNr5 3xfA== 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=m6wtFkz1or1nILz6wKiOp8pBHJbHz0CkffxPvcSRrcxQhrFDjeW3/a/lf014iQ8peQ D8Sh+9wWUQBVpTjGUZuNU/CHqOzeLzdP5RJZSIkAxRhZxnBiGYucYqLQDLS99E4fihIu 99IviWiGTQoPhncyB4jwwLNGWaHsgMjQgLQcphBryWwzJlg41HVv0rb9oxFT7+LEXYTO jm7hZPDWe3ca82UpSuRb3z06wh+pMTPiWx9BmFp1Pk0EvWZdMY37+HXeIf0W/SzBXQrC jmTWU9WYzDUAMIQ4UcS0JfitoiA/BPgjHxdMILWhGWk+qinZNT6yIy5Nilz7qcVoR+hl 9rVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QZyYvSYS; 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 m7-20020a170906848700b00787c0e9818csi10782619ejx.568.2022.12.20.14.08.22; Tue, 20 Dec 2022 14:08:45 -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=QZyYvSYS; 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 S234149AbiLTWGQ (ORCPT + 99 others); Tue, 20 Dec 2022 17:06:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234134AbiLTWGK (ORCPT ); Tue, 20 Dec 2022 17:06:10 -0500 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED1661838A for ; Tue, 20 Dec 2022 14:06:07 -0800 (PST) Received: by mail-ej1-x631.google.com with SMTP id x22so32494715ejs.11 for ; Tue, 20 Dec 2022 14:06:07 -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=QZyYvSYS/5R/0vxSGWLo/6TrG71If7NC5DtCubDinMXdIvsAOTSsTYPjceSC5lhJec BXd6ndGzKfOPGsXk7IAnWkD2+Jg9cIRiiS2AMo0PWk/H6f73e5vb/qkVYFuzoPnK9/Es mlmynVTyGNzumcJRS3bL1ypHkrfyanKKrHzs4= 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=hGjsjC6xg6lZNgohp9i6N2NEmxch3FN7ST/+3K9GV45PHrqBbWn43WqP2oRRu8pcox LBQ9dnwZHBy4nxb3WPnEeSbNwBc13nfXm3Pt6MqOjWXSZUIdvwKNOyaN1rlGrJbSEnvf pRbD+EOU/cp6QU317yGeUG6yEwKmBX2/nhJRITpHg5mFsXsieve68EBIVAkhSHODDybh fPi45qp2ynJ8WV7hTeZC3ZcK3ordYZiiLoztsCOz/R1/vuV0eVOZAE8+vKW44XsNxO6g z9pXuUGYHnYCP3aG7l9rO2OjxWVJCXGToDWWWvdXMQU1MZUeguKivkIqvQxe5Ov2PoJF 7ppw== X-Gm-Message-State: ANoB5plRMbm5MOhGGmaEIz4PYlRknZpNYyPApBDQ6PsM8z7CvwyXDUVR MNpxbEC3Tk4v/hrc1EI4NQY/4w== X-Received: by 2002:a17:906:f6d7:b0:7c0:bf7c:19f4 with SMTP id jo23-20020a170906f6d700b007c0bf7c19f4mr40561370ejb.74.1671573966509; Tue, 20 Dec 2022 14:06:06 -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 ku13-20020a170907788d00b00837ac146a53sm1175492ejc.23.2022.12.20.14.06.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Dec 2022 14:06:06 -0800 (PST) From: Ricardo Ribalda Date: Tue, 20 Dec 2022 23:05:43 +0100 Subject: [PATCH v3 1/3] Documentation: sysctl: Correct kexec_load_disabled MIME-Version: 1.0 Message-Id: <20221114-disable-kexec-reset-v3-1-4ef4e929adf6@chromium.org> References: <20221114-disable-kexec-reset-v3-0-4ef4e929adf6@chromium.org> In-Reply-To: <20221114-disable-kexec-reset-v3-0-4ef4e929adf6@chromium.org> To: Philipp Rudo , Eric Biederman , Jonathan Corbet , "Guilherme G. Piccoli" Cc: linux-doc@vger.kernel.org, Sergey Senozhatsky , Steven Rostedt , linux-kernel@vger.kernel.org, "Joel Fernandes (Google)" , Ricardo Ribalda , Ross Zwisler , kexec@lists.infradead.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/ZANAwAKAdE30T7POsSIAcsmYgBjojHIpdmcVeMVxZ7UQR/ZxrK0wjocsFOqbUXV1Pzf kKjKvmWJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY6IxyAAKCRDRN9E+zzrEiFfID/ 9z8ZdKo6lWAEJ3T0FZH9P5dUY7+G8f57r2NUYkbXfSZyBnKZrzNJO/zzg6qs0zVpVhq0Q6tya9Lr5n i9pKqqZzciEhZ5dxXjxdUSdA+bnNgCHYoV19PtdKclGJWT3ZlunTNW6b+m2ecsEEwry0nzYTY8tfmX 0Z2upPGKphHkKHuehW+ZatYoiD9ryoeqcsUa/ISkFK3J2H5tlKeqTK2uJwxEAyYJewvSydZUCPvHAv 8ZUh4us+RWedvK9hUg+79yijwSID58bKxu7aAsRdhMef+vRkERdD4hYDEHoCFVoO0BytlMagDtbC55 7p2OA6GEjZ2rjT41K6fO1h9gZcScdk3oYi4mdeAFZz81BpO237UWXl3ONMimGUS8nOhYkULDJ/gL+i PRRgDg3X/pcbA/EwQCjr0sjvCIFH7+kUYsG5ugtmyoWYS3v6xyIsgwkcN1vapyrWDtiwqQvZgZAnO+ zaiPo0WMlJ8U16DM2A0hxHsvqQVtUq4/3ZOti2PXiwSjbF9Hkcs+huWx6+r9ZIpDU4cS6DRcpi6JWj GXAjtzK3OYQmK4Tfy91pBoGNKL15xLeJ7zbR+t9Llz1b4P5Yr7pbW0Niku63bJ8EhyWZqUSwSEUey1 Z8QP37ORLoJzuJVT/YNbvtLZOzvKP3bWpLxPZ6Ax6fx4bMYhgraJntD8MAJA== 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?1752772510051427852?= X-GMAIL-MSGID: =?utf-8?q?1752772510051427852?= 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 Tue Dec 20 22:05:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 35202 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp3205974wrn; Tue, 20 Dec 2022 14:09:28 -0800 (PST) X-Google-Smtp-Source: AA0mqf7qzNJbdzPNnF/pcG6kvbUocTQk3nG0LwfcuqvPWPFfqBeI+fHXuZMBWf1OAB8T41IVxfQ1 X-Received: by 2002:a17:907:b689:b0:7c1:7441:57f3 with SMTP id vm9-20020a170907b68900b007c1744157f3mr30225246ejc.10.1671574168772; Tue, 20 Dec 2022 14:09:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671574168; cv=none; d=google.com; s=arc-20160816; b=XUsLi67EXAGGYmbm/FKnIGJaFh3Et4WklMaMBev7SV5nUhHeXNJt9J+5esDcRDs7aI OmYGQKq1F4eyZEj3CdFzJ0qKgBbP5BSMl4GTbBieWRJGtutQkbQJc6ivwQFrOl2jrVXo tb+ZTpujyTkj8bjFrmx4UhKOXrEHD4mXhOkL/BRFH3TPuhN+FPsJsOj3VxosyeOI+ZVy Wjes7Szq1g7509hULQxvKnQdgWUoqgiZopnWM9KbR4f+vpkKQHu8woIaDhYdHBw4Qv3K 2fTfKJ5+0Y0F9v27G4ZbX1lUb3T7o1fAH6DJRmZgFWcfHkkomn6nNvaL9B9tHMko+4t+ ibzQ== 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=Zug8YMnMibhXQSdB0hz4oMVIDeBoaWKJaHtpCNILOr1YQxoynfbqV48rAt1HM44MVo NqMM0itDEultfu2l/2+5C73ixYoq6Klh2VsaU2rSkdmNbO1uvizZ+sf1e/GOXeIvoABk R9jTaZYG4PE0EXTKk4dZroXqN+EYd2bWCRnuwUcxlS1Gc7F/0mx8IfnnaE+rf6gfxeDR t88CRBKIWR70QYV8zCnbyy8SLzZdsd0//3ijIglaxKLu8j7O83nWAq9Vd9r49QVa8PZR euU9m6McMFQWbwH5V0TrL9cU2FAEXKIDvFyQ8Sl/FVOkU+1CMW/D7zeLzK5dtMulUiqU 5F1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=c0EpSka2; 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 va28-20020a17090711dc00b007c115fb8501si1460351ejb.252.2022.12.20.14.09.05; Tue, 20 Dec 2022 14:09:28 -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=c0EpSka2; 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 S234020AbiLTWG0 (ORCPT + 99 others); Tue, 20 Dec 2022 17:06:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234154AbiLTWGK (ORCPT ); Tue, 20 Dec 2022 17:06:10 -0500 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABE731DDF0 for ; Tue, 20 Dec 2022 14:06:08 -0800 (PST) Received: by mail-ej1-x634.google.com with SMTP id n20so32665438ejh.0 for ; Tue, 20 Dec 2022 14:06:08 -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=c0EpSka2OkXl5W+Dl7hPwpEaeN+NdBH3EzU6HhKZkH8+2XWo9puTrQBfluMS1O4U6F YWa3b1blPJNLpgLgQjnd18NGYt3GWxhceXP0cKvEom172VwR9onTJMp2QKx5azS5/+xO kUBszu1d60MZJ0JPNqcHy1Hofql+nmBofgUFc= 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=GXuPz1mKuBp+E5G27RVNIFJtJgF5y372yTNx30oLNZn0L041fPFQsO/xC/hvJThocn ar6AudcO2BWtLlgxRZHXqq7dbY/F+LmT9mb7VRp9zSqo9k+P4eUosNhiu6INTw04lpt4 6rfSMgQBNkpEcV6qEg2CSGOYb/Kn5oPTgRvHkp/CLCol9xEovzYMx5NW4w+ogKrxANoW xwqFm2kddSrRN4G3lHc8qQipbOnZgjf/87VH0UoGYUHys9/seGY8HqIGbEfJhUBDKCDu 6g/pT1V8U/JBMhMi7PauKs2BZbiOUgddVIqLlWpQm83lbEb1JMYQxXDuibLGTQZhYUCZ DJfA== X-Gm-Message-State: ANoB5pn5Jh4Cv71WADK07wCAG3NJsRIMHnax5EKQMJEBElasWRtrZiJu j76REzEEJo5Qy45F0YWh+Cz7VA== X-Received: by 2002:a17:907:1110:b0:7c0:fd1a:79ef with SMTP id qu16-20020a170907111000b007c0fd1a79efmr38892271ejb.48.1671573967232; Tue, 20 Dec 2022 14:06:07 -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 ku13-20020a170907788d00b00837ac146a53sm1175492ejc.23.2022.12.20.14.06.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Dec 2022 14:06:06 -0800 (PST) From: Ricardo Ribalda Date: Tue, 20 Dec 2022 23:05:44 +0100 Subject: [PATCH v3 2/3] kexec: Factor out kexec_load_permitted MIME-Version: 1.0 Message-Id: <20221114-disable-kexec-reset-v3-2-4ef4e929adf6@chromium.org> References: <20221114-disable-kexec-reset-v3-0-4ef4e929adf6@chromium.org> In-Reply-To: <20221114-disable-kexec-reset-v3-0-4ef4e929adf6@chromium.org> To: Philipp Rudo , Eric Biederman , Jonathan Corbet , "Guilherme G. Piccoli" Cc: linux-doc@vger.kernel.org, Sergey Senozhatsky , Steven Rostedt , linux-kernel@vger.kernel.org, "Joel Fernandes (Google)" , Ricardo Ribalda , Ross Zwisler , kexec@lists.infradead.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/ZANAwAKAdE30T7POsSIAcsmYgBjojHJBckCkaRQr+TYZrF3kjpd1KCko1R5cEm6gufq +jL/ctqJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY6IxyQAKCRDRN9E+zzrEiMSUD/ 9f/BnyydzLUgxCB/+6MPK5x85yrh4BQzpJFvUHfpUcS4bvaQxOKcu42CXvd7TlWapp3anOCskcmg42 XTOJ6jxFo2Zdjd+HB+gQc8AzBwAsTS7lk5/GG5HkOXdqE7oRGXSpyVzd7daWjm0ZAD/e40xju8QvwS yCZM5hT9nhnEwG9RFkNm3p/5yeJngpYqubIHxexqLNz8P6HyUUGskiE6epSpx0A8l1gK5CjJdcJ2QD TAcAv3+NxhErfOIe28YkMiuiHBibNKLw7kolvHnOoLqgUsbGkAgsTJsXayRaN+aQ+UeCiaEIny4inY IsXan5vCvqjJi6Y59k4ojkdtblxbbHoC6438DfPpfOdJfhPPYkBBsc7GQuMU02H38ig942i8nSLHP3 1h96Q+D3M2QiXyOMsdHuMMrM6xgWpICODgLT0avXHXY9zlK+998nN1iWUJEFzcgDuzD9goVzcGPHTa eriwadLeYeSXIrrpHzkNDincaSpNoxHP1jXLEkQzcvsOX5HNXAWiDBgHVwtGjtRWaMjtuOkmQDZNkB h9hbV7C4XbZLQ8WWhkHcSTxK6sNEhY3V2xWDcGfPKhoMQXZNuRAPy81AEeNwO5djhddq/ldkmJio7C 6cCvL9mR9mST3ODQ0BZSE1QACA5mrPVAR0W95BJ5eAUXM/3nnQs4+askGnFw== 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?1752772555515890179?= X-GMAIL-MSGID: =?utf-8?q?1752772555515890179?= 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 Tue Dec 20 22:05:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 35201 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp3205789wrn; Tue, 20 Dec 2022 14:09:09 -0800 (PST) X-Google-Smtp-Source: AA0mqf5Dc0c2xEqP6pISOW4P6t9mXUcJ4+Kcjen+p0yy+zS9OdnfI1vz1HW7BaIVHsCMj+jIfHdv X-Received: by 2002:a17:906:8d08:b0:7c1:700:1e2d with SMTP id rv8-20020a1709068d0800b007c107001e2dmr63817693ejc.20.1671574149105; Tue, 20 Dec 2022 14:09:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671574149; cv=none; d=google.com; s=arc-20160816; b=Dro2wpelVIBnIPZuQhz4qDbygsI32onEQ90QJSaifJIqKKFY1aLrSu4YmPX9eDGWji qE9lnNyupxzUZvY4iPW/lzTUTLw1emD3UqrMRjtd/gyU0qKaTo7TJOeL7TzBBe4y+pDq tpfKMqBR0tCOui58r8dg3CS/h3Qf4nE9m58JAIgbGAClGH4LtFcYCLTBdn4vYdwH3BrU pu5BVs3xW6dz6M24ja50Y3i25yxXUPzGXMQ2sdhBsdGGBvrWx6lhtPvkWaDJRD+iVP+Z OF49YI0PVlAtFDW+wJWBMRPZZMXgOQniX6I86cCw0xnA1uAnqdQ6MEkWHFko1yK85V02 nSrA== 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=A9+UYStnTWSGjcfg6nbEHqd+1X3j3uTcNPeBDTDi2dg=; b=OuYHJuQY2+XWUAU2/r1h4cqacZ2gThTC9AIDnGYNAgoVaPynjOnw42ECUcVwAykCul wWli3ok7uPmeaL5yjJ0G5NC61jrDk/WEuwgplK8ktguIgacdCLzz/9FCcJi/wDkbOilV Fn3it3XiUIdwYv7iQRpkk0OoBq8ErWnsURH5ud4PgWsy7D4Od9MHi88SyEr/aqq6Ttwt uKD3zZlVHJbPP5bk1OwczDgVoGlJp4Pj45ie2B2vW4SEYU/LUk/Uau+1K4OkXZf0BE2N KBtpcVQbFryz1azGrJrpsiGcJw1O+dlWuEv5wk9XxBh3Sja2u5lfW1OJO6CjRUVKxIdx W+0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=A0qO9cEF; 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 b11-20020a1709065e4b00b007c16e4d5ea6si2172814eju.957.2022.12.20.14.08.45; Tue, 20 Dec 2022 14:09:09 -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=A0qO9cEF; 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 S234227AbiLTWGU (ORCPT + 99 others); Tue, 20 Dec 2022 17:06:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232400AbiLTWGL (ORCPT ); Tue, 20 Dec 2022 17:06:11 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9939DB54 for ; Tue, 20 Dec 2022 14:06:09 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id bj12so32455677ejb.13 for ; Tue, 20 Dec 2022 14:06:09 -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=A9+UYStnTWSGjcfg6nbEHqd+1X3j3uTcNPeBDTDi2dg=; b=A0qO9cEF9BExaKG++8+pMbm2JwjYr+J4MRScp+7250NNGhFaRVBpZSd2wGrXaKkQJv 92dPcds0K8JnxSa5CreUj8k6FfD1QZ7+0Bx9ilEcxK5izAYSrhJc6XJun92Zh21cuK7o cXbXNoBRhc3DCd39gV8gFNMDMakCJHcFOgwP0= 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=A9+UYStnTWSGjcfg6nbEHqd+1X3j3uTcNPeBDTDi2dg=; b=EU3nFuKxBabzGmpKIoWfjjXV9VE4hLKTKnIOPqX7FPriRrNtjYElke6F1O+B8ROjq8 bLN6T13/wKA8976gYufwlULJOzwf7gQKGmyCT2ddn+L2Wo3Yx5ntIChSUnaf6vr/Xt1w kQRlUAW8GuHK1Pp/Xq8kpDphFJ/jSjm73Rfy8bphmZqBhz8nyXXfmwHBAm2A/REMQnlt DZCXQpqM2lL07arkuEhfmzNrzAE+Bno31gWK2vxh/ub9stYeZOaWfQKmetTQkDLvo7rC YydSUyS7iwYn7QkS7yTd2emetKqSrntSt6gvFQRf4VCA149UDREM7k8ZnKR/dpIUpqLJ LdwA== X-Gm-Message-State: ANoB5plqSjpTstT7PaDviAl/+VG8tkJuMqkgYtmHQ/0YXmHc/ufB1SZZ sTPYw22HrI17LAkAMjxtXf06PQ== X-Received: by 2002:a17:906:f2d5:b0:7c0:ff76:dc12 with SMTP id gz21-20020a170906f2d500b007c0ff76dc12mr39257082ejb.2.1671573968178; Tue, 20 Dec 2022 14:06:08 -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 ku13-20020a170907788d00b00837ac146a53sm1175492ejc.23.2022.12.20.14.06.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Dec 2022 14:06:07 -0800 (PST) From: Ricardo Ribalda Date: Tue, 20 Dec 2022 23:05:45 +0100 Subject: [PATCH v3 3/3] kexec: Introduce parameters load_limit_reboot and load_limit_panic MIME-Version: 1.0 Message-Id: <20221114-disable-kexec-reset-v3-3-4ef4e929adf6@chromium.org> References: <20221114-disable-kexec-reset-v3-0-4ef4e929adf6@chromium.org> In-Reply-To: <20221114-disable-kexec-reset-v3-0-4ef4e929adf6@chromium.org> To: Philipp Rudo , Eric Biederman , Jonathan Corbet , "Guilherme G. Piccoli" Cc: linux-doc@vger.kernel.org, Sergey Senozhatsky , Steven Rostedt , linux-kernel@vger.kernel.org, "Joel Fernandes (Google)" , Ricardo Ribalda , Ross Zwisler , kexec@lists.infradead.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=5825; i=ribalda@chromium.org; h=from:subject:message-id; bh=Zc/gSka8wOP3G6tsawZGIGKxFRGZrCiyiT4x6FixMW4=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjojHLZcxNi1sPouIXr6mT+V5x5mHvydbMJzCO3YWh gn4sbiSJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY6IxywAKCRDRN9E+zzrEiDODD/ 0Q4Zvqb8s24SEseZLeUDz32F3wm0l0IZPp1VqYeoxcynPygcG2mdR2kznnMVhzeSL1CU+XTF6+dSY8 1Fj/VpOcrWHhbaa0RvHl0XLZR63nY9Dhz6vBPjv5fM6jrCT3wpxQEtJPNXQ4PT7CMbWuqYi5JATa7p bYpgWNkqliE0ZAMZhxQ/NKaGOPKevRKyVH67KCW/PNn8Kr2f2nupjb5shNblfAOB4GXLUiYQS4s0TQ W2qbEzfyepWmZ9lzh77NnjJ4Qz2kxvKgdpzg4vBnz5BxBJBSNRvczvKOm6ayK1G2/rkrklptquK507 tegnKH4juIa71ObyjuOSQrNf2Vq+waCmtLICjoHuTLxghgmMB/Gow/CD8Nocxx7NgLKkZ8SydPCvLJ Ekv/0p0Z/HpMpRWZhpWRDLvQZW6aye8njLrZHZmrLl4WamlcV9wR9ZtcDzGkXhkdyZNpqTiGtSz7kp +sUOQkebMUvG27zoDDQ6yRBNFsMVI9UQ471SeRGNrT8JE/JbdjZxCFIBsAKW3XhZBMEjC4HfYd+9Ig JEyWhkC8Snqx7AoYJv9E8qcSk9u4TyikYWPeV+Tppef3ZL7FeHki8xlpnHnFbtFL2XJS8I/Ttn1Va8 yH72bJY+zqsfJ+d/dqdNwU15BYpCt0jFZltT2mb7t10hAYLaLwIsYQLq33hQ== 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?1752772534582105220?= X-GMAIL-MSGID: =?utf-8?q?1752772534582105220?= Add two parameter 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 sysfs, but only with a value smaller than the current one (except -1). Signed-off-by: Ricardo Ribalda --- Documentation/admin-guide/kernel-parameters.txt | 14 ++++ include/linux/kexec.h | 2 +- kernel/kexec.c | 2 +- kernel/kexec_core.c | 91 ++++++++++++++++++++++++- kernel/kexec_file.c | 2 +- 5 files changed, 106 insertions(+), 5 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 42af9ca0127e..2b37d6a20747 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -2374,6 +2374,20 @@ for Movable pages. "nn[KMGTPE]", "nn%", and "mirror" are exclusive, so you cannot specify multiple forms. + kexec_core.load_limit_reboot= + kexec_core.load_limit_panic= + [KNL] + This parameter specifies a limit to the number of times + a kexec kernel can be loaded. + Format: + -1 = Unlimited. + int = Number of times kexec can be called. + + During runtime, this parameter can be modified with a + value smaller than the current one (but not -1). + + Default: -1 + kgdbdbgp= [KGDB,HW] kgdb over EHCI usb debug port. Format: [,poll interval] The controller # is the number of the ehci usb debug diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 182e0c11b87b..5daf9990d5b8 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(bool crash_image); #ifndef kexec_flush_icache_page #define kexec_flush_icache_page(page) diff --git a/kernel/kexec.c b/kernel/kexec.c index ce1bca874a8d..7aefd134e319 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 (!kexec_load_permitted()) + if (!kexec_load_permitted(flags & KEXEC_ON_CRASH)) return -EPERM; /* Permit LSMs and IMA to fail the kexec */ diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index a1efc70f4158..adf71f2be3ff 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -952,13 +952,100 @@ static int __init kexec_core_sysctl_init(void) late_initcall(kexec_core_sysctl_init); #endif -bool kexec_load_permitted(void) +struct kexec_load_limit { + /* Mutex protects the limit count. */ + struct mutex mutex; + int limit; +}; + +struct kexec_load_limit load_limit_reboot = { + .mutex = __MUTEX_INITIALIZER(load_limit_reboot.mutex), + .limit = -1, +}; + +struct kexec_load_limit load_limit_panic = { + .mutex = __MUTEX_INITIALIZER(load_limit_panic.mutex), + .limit = -1, +}; + +static int param_get_limit(char *buffer, const struct kernel_param *kp) { + int ret; + struct kexec_load_limit *limit = kp->arg; + + mutex_lock(&limit->mutex); + ret = scnprintf(buffer, PAGE_SIZE, "%i\n", limit->limit); + mutex_unlock(&limit->mutex); + + return ret; +} + +static int param_set_limit(const char *buffer, const struct kernel_param *kp) +{ + int ret; + struct kexec_load_limit *limit = kp->arg; + int new_val; + + ret = kstrtoint(buffer, 0, &new_val); + if (ret) + return ret; + + new_val = max(-1, new_val); + + mutex_lock(&limit->mutex); + + if (new_val == -1 && limit->limit != -1) { + ret = -EINVAL; + goto done; + } + + if (limit->limit != -1 && new_val > limit->limit) { + ret = -EINVAL; + goto done; + } + + limit->limit = new_val; + +done: + mutex_unlock(&limit->mutex); + + return ret; +} + +static const struct kernel_param_ops load_limit_ops = { + .get = param_get_limit, + .set = param_set_limit, +}; + +module_param_cb(load_limit_reboot, &load_limit_ops, &load_limit_reboot, 0644); +MODULE_PARM_DESC(load_limit_reboot, "Maximum attempts to load a kexec reboot kernel"); + +module_param_cb(load_limit_panic, &load_limit_ops, &load_limit_panic, 0644); +MODULE_PARM_DESC(load_limit_reboot, "Maximum attempts to load a kexec panic kernel"); + +bool kexec_load_permitted(bool crash_image) +{ + 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 = crash_image ? &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..6a1d4b07635e 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 (!kexec_load_permitted()) + if (!kexec_load_permitted(flags & KEXEC_FILE_FLAGS)) return -EPERM; /* Make sure we have a legal set of flags */