From patchwork Thu Dec 8 16:38:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 31439 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp302689wrr; Thu, 8 Dec 2022 08:48:19 -0800 (PST) X-Google-Smtp-Source: AA0mqf5jQF1yQMfJ+SAQy5oBGloytIL3qWI/Wi9KwsjObvbcFVX+EDAvJt31expHBCY2fIhsHmwT X-Received: by 2002:aa7:c042:0:b0:462:2f5a:8618 with SMTP id k2-20020aa7c042000000b004622f5a8618mr84930118edo.42.1670518099158; Thu, 08 Dec 2022 08:48:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670518099; cv=none; d=google.com; s=arc-20160816; b=wDqe5RIYz001Jq4KRnTiJM1AneuGJGNonaMQ7tP1dOKDNx3FLhGPCdUpcvIn4Gwfw4 t95BlNMWtBONaFW5CJ+NeranDc0Le1TTvl8gGw1YR37gm/F2ns0jS7U3yumCWIqZKJD1 rMyNfE3LIuVKJN/gMs1RqRx2C7M41YB+/XZ9JP360DYxRpni6SWQC06zZfC73g/SVELj Fs41GzulDlu3UxDj7nTbhS+8W9QTxqdrzk4Vu9tZHecVxsSWuqY6YfvBi+nh3jjFGEB7 8k2l6QUcq3tYuwXjbyOcQyoG8NqdNIa3wMzjbiU+1YMImkdwtSEwuFxX5rWGeKurT0Yu InvQ== 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=AhaF9GqJ13TY0Hg27yR5BzoVfdO8sTpyXYMoNgjajPA=; b=YHH9MaeJWBTQ87Q+2V7ERT5a1sYeiTi5DmElcVIB4FgtorZjkLFYgl3yovjzkxjapV J+M5oVMRNrcXCfBLQEWBrageDsbwMZwM0WcB7vekkR234EY0pAcXTIedZBcmq4sXtoNq TfkDSCtZCOghWUkrLLyts0tgWXWiactKlRD2ypPaRMPOTSxZKhLLnC/rv1vnwgNoPrZA QImFz3rlhODqRoiU7F4VfIvTjIRrWej/ABF9JkEMK5wUb5BudJF0OUSW/+3vwW8JtFrd emF59f2cMTnDZHORsaA16sAOWddMwvjtG22Wpj1fL/H61gdhKhxv6IBG/uOskIk99zjj RG4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=i9c67mj+; 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 j15-20020aa7c0cf000000b0046840ac2af1si6015789edp.68.2022.12.08.08.47.56; Thu, 08 Dec 2022 08:48:19 -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=i9c67mj+; 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 S230196AbiLHQiX (ORCPT + 99 others); Thu, 8 Dec 2022 11:38:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230016AbiLHQiU (ORCPT ); Thu, 8 Dec 2022 11:38:20 -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 4B1883AC15 for ; Thu, 8 Dec 2022 08:38:19 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id r26so2527099edc.10 for ; Thu, 08 Dec 2022 08:38:19 -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=AhaF9GqJ13TY0Hg27yR5BzoVfdO8sTpyXYMoNgjajPA=; b=i9c67mj+9AQi4YP+ksbG4h840ith9rqM0BG3ZURvebcEwPzRnnOXDmFZLMiElsFjQd hExkE7m+ye6SWjL5pY6ftcA7YtxZGrd67eYNQnwmU3dQ9EZTxTbhTpgVZUHfydcZ2R8K caTkIQ9eViZXa53Dni5MTjKQFgCubYVYWAQ5k= 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=AhaF9GqJ13TY0Hg27yR5BzoVfdO8sTpyXYMoNgjajPA=; b=2ZPCdpHj3o3IX6WCY9DT31V2qriZ8IeyBthMDADiN9a3s/3OqUNxDDGDDA/Iink0Tn pRPLitb+lyPJ073pcXBld73MQXawb35I4OCvOKj7avBU2rKIW8ekXewGOmcAJMW9o9NA Cq1Vb+LohhIx5PvLlW9xweKTMDBydAT1dYjjZUlwZUQiJeSe8iR6wE+HNck1R14ezJ4t f0g62KOy1NaFhLcAsFuxrBJpbEDQcy5qlEF/Jag/DHCrGcqBzzQV8NIo1x4PKqJwCheC jOgwzUky5jFjct7xkd7G5NkEpQOq8CY92SO9IS1wAoAHkQFusir9VhCcVlqHTMoqh0W5 zB0w== X-Gm-Message-State: ANoB5pkFcSdZR3AQ8/HQesYmaMOxADFou3C0bfLXIor/eoGTz6W6TX5x yTr2w8ZsWfnIOftrkYCAdAT/hQ== X-Received: by 2002:a05:6402:3908:b0:462:8a68:139f with SMTP id fe8-20020a056402390800b004628a68139fmr2240885edb.3.1670517497880; Thu, 08 Dec 2022 08:38:17 -0800 (PST) Received: from alco.roam.corp.google.com ([2a00:79e1:abd:5c00:8aae:c483:8219:bdba]) by smtp.gmail.com with ESMTPSA id ck3-20020a0564021c0300b0046778ce5fdfsm3569046edb.10.2022.12.08.08.38.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Dec 2022 08:38:17 -0800 (PST) From: Ricardo Ribalda Date: Thu, 08 Dec 2022 17:38:00 +0100 Subject: [PATCH v2 1/3] Documentation: sysctl: Correct kexec_load_disabled MIME-Version: 1.0 Message-Id: <20221114-disable-kexec-reset-v2-1-c498313c1bb5@chromium.org> References: <20221114-disable-kexec-reset-v2-0-c498313c1bb5@chromium.org> In-Reply-To: <20221114-disable-kexec-reset-v2-0-c498313c1bb5@chromium.org> To: Philipp Rudo , Eric Biederman , Jonathan Corbet Cc: linux-doc@vger.kernel.org, Ricardo Ribalda , Steven Rostedt , "Joel Fernandes (Google)" , kexec@lists.infradead.org, Sergey Senozhatsky , Ross Zwisler , linux-kernel@vger.kernel.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=1261; i=ribalda@chromium.org; h=from:subject:message-id; bh=B8aDh7OSN02BJ2pf/rcRX//p3+ltOWRPCwelS9y3Ngw=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjkhLy7d+A9Xd6db3iX02SAJV6vvpdaEGh+vrOfiGj 6tTf/XCJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY5IS8gAKCRDRN9E+zzrEiA2dD/ 947qf3hcL5NPrOsphwYmep1sKdvBXyfRYLZc4ZAVhbXaUa1/MgZ+9DemziS4H4PuHf4HRniwQR1flY nPiupdyswzRyxyjw0zA0B+MP8qC5kt2csBlxYZeQkFsYP6MXmG9YJk3gxNCfGM+zoQoQuoUVuNJQ4/ hOVs97S9gWlCLnswwemGdrLrwW7sZR7ct69r6RSnIghYgrwnMgwbeqvj+YWn5ph/mwsVNpoRn24tUl BZj547MmwJ46BVtmhdf329NS4uJTGRVFU5+kQEe5813/6DYloTvzW/ZDgpG1lreh6tqLdGrn2xouWu M/UOrJ3hqHWe8dJh5nRP7DRiDvBusEP24kLBnK9VFvM4extNvGElx6zp8EiOuLm8zumWZDuLcg1EHw K4236OoivuGmnO29pu07/YFV28QyVXFpPPr6rxEM9CCSBjw+NCN4lajOpa6ZX1NzEAU1oyazGV96kN GZ6MQRE3VS4UHc8T9mnpmM6yLjcBEuGPCXa7UKhdFckX3P5xSCKoRudBQSKxMLSlA27gkVHQb3SXDS WW9Ub0jfHM/wB1mC4pKeFMKsmuqoNZZdPJb/u8sfyRvTIpynWuTubGb9QhGV7m8OMVvyWnZTgTHN31 +JVvGqQ2OhdJRm/K3bhBuajW85vpI7xTXUnb31Y95M2ZWLMoAEiSQrbKhpJg== 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?1751665186649102884?= X-GMAIL-MSGID: =?utf-8?q?1751665186649102884?= 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 Thu Dec 8 16:38:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 31437 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp302539wrr; Thu, 8 Dec 2022 08:48:04 -0800 (PST) X-Google-Smtp-Source: AA0mqf4DM6mRYN+dJin+dzBamCJiZ1tmIEfVirbBxL7dx5I0ylOBikGD6s8OUj8dhX/LfB1NYi2F X-Received: by 2002:a62:e301:0:b0:577:d5ac:8561 with SMTP id g1-20020a62e301000000b00577d5ac8561mr368861pfh.15.1670518084015; Thu, 08 Dec 2022 08:48:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670518084; cv=none; d=google.com; s=arc-20160816; b=w5Wbv3De2yo8s6KaoeLXiBmWovUbBs0BNVOtXh5qIHaCyh/BkokgxDW+HYa9kKLfiA tTfoPdvWJWmFljQwBPRwJpoNz4P0630fbDyabwxuyOQlBBnvjZr54G0kurmJNp0GHGah 4gLiG10lOkhBjo68DwbHGLbZmSBswnDmghUAVAMt4NDQGN8J3xiiv4YCOl+BOGvCWFzl bl/4Y2BUIxlTV/E6E/9CbMAqGqlwg3KCjLiScL7rZ4yG2WsUaGFcrA2L3iZRnUjxuTV0 nxIDmr53dFDGshW83sixv1ThHM9gmFUwgoY+gAFvmNeauqMBX9bS0txs1IqkkqpCN6QI 9yPw== 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=LQ3ul1jQRXTmaEsuvA4DkzO41vWZ0ws2E+AUBitFzrQ=; b=hTrPbDq+rpZcOtPauPj/0VKVjF/NCo6KpwcixNFSpD+l19s1tN8+5g6s61VsH2UAKg PSWG7AKq0KNWyB8vSQHS/e7HY3XTbjASsEZ0dIEOzzQ5330Sg8g7O3B5FEkMcm3x6F8I qBbZIwP3Uq99N5OR0Fhfgq5yrjr60t4Jm1ZG7+aLiyjRXOhki7GFbNcJMO528iXZeIVx CSWy3pGrQyKAEYqp6z5koHrnTupQOxdb2O9vK1KPcdo6za/rjSgrZ396Nh7zz+hMQfTw 7rymo3QKuvF2QnGU+OhvrSBQeDvr1VeirWFug/bNMeNJj/tlrUKSqy8cTl/JnRFBUTAv V4UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="k/7X3z9v"; 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 p16-20020a170902e75000b0018996404dd9si18594157plf.267.2022.12.08.08.47.50; Thu, 08 Dec 2022 08:48:04 -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="k/7X3z9v"; 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 S230227AbiLHQi0 (ORCPT + 99 others); Thu, 8 Dec 2022 11:38:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229733AbiLHQiV (ORCPT ); Thu, 8 Dec 2022 11:38:21 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B5C113F1A for ; Thu, 8 Dec 2022 08:38:20 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id fc4so5302646ejc.12 for ; Thu, 08 Dec 2022 08:38:20 -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=LQ3ul1jQRXTmaEsuvA4DkzO41vWZ0ws2E+AUBitFzrQ=; b=k/7X3z9v4qZ29jB2yYGyTKe0hRoo77mPXZfDtm/XwjaqyLx2sHjGxg9aBpwD9Ee3qz Np0blameSJM60Ssvq6O9wMJFkHCAokczTYCo3ver8LXm+zG6gA+ypMSfMMzlou1PPHti ELRuj4yf83+9A377gSgGNh1Ubqx45IuT2Fo1E= 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=LQ3ul1jQRXTmaEsuvA4DkzO41vWZ0ws2E+AUBitFzrQ=; b=Zv9VUrxfpgyz9h2V3ZgaTH2vOsC/GudGQp7Rsb+ZsIfNat/7H1o62zgCjtwXmNYVwG rWeca9bwwT3WFstvCs0PFT2N5TJTlKM6d4CgrFgb8vahVjfFXJToPFy4O9Qffh+xul/k Xp1TsoEczUbQYXmzOlROupjZajgmnVXOVfmy3e0jn8oq64btGZYheLJDfHmD4lSVBFyP 2MddbYPf2e//X5kyG0gYIgvkaVvxQBDqJl1cVInfl20RNXSiQlVBrPW5KHyVBeFFMS6K PuZ3NU7j+PmxRojtH32T0gCLax0zwz5IsVMCluwBLDvOnxE6U4ytwrE+AXesYC99eL92 Wjcg== X-Gm-Message-State: ANoB5pmul55LvXs3JeZAW0GHN9jF6SjZ48ev4xHh5PU09w9t4ZWhrLKM 1NEahDsExUsIQ+qSmfdghWbjcA== X-Received: by 2002:a17:906:3716:b0:7c0:bbab:22e5 with SMTP id d22-20020a170906371600b007c0bbab22e5mr2410973ejc.16.1670517498873; Thu, 08 Dec 2022 08:38:18 -0800 (PST) Received: from alco.roam.corp.google.com ([2a00:79e1:abd:5c00:8aae:c483:8219:bdba]) by smtp.gmail.com with ESMTPSA id ck3-20020a0564021c0300b0046778ce5fdfsm3569046edb.10.2022.12.08.08.38.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Dec 2022 08:38:18 -0800 (PST) From: Ricardo Ribalda Date: Thu, 08 Dec 2022 17:38:01 +0100 Subject: [PATCH v2 2/3] kexec: Factor out kexec_load_permited MIME-Version: 1.0 Message-Id: <20221114-disable-kexec-reset-v2-2-c498313c1bb5@chromium.org> References: <20221114-disable-kexec-reset-v2-0-c498313c1bb5@chromium.org> In-Reply-To: <20221114-disable-kexec-reset-v2-0-c498313c1bb5@chromium.org> To: Philipp Rudo , Eric Biederman , Jonathan Corbet Cc: linux-doc@vger.kernel.org, Ricardo Ribalda , Steven Rostedt , "Joel Fernandes (Google)" , kexec@lists.infradead.org, Sergey Senozhatsky , Ross Zwisler , linux-kernel@vger.kernel.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=2723; i=ribalda@chromium.org; h=from:subject:message-id; bh=oo014ZHz6Xm+AA2th2qtraBO9RjgGW/IoV0rNAHz2pg=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjkhLz9anViJqu4KFmbxZAiE4U2e9028qdN4mFsCU/ 1AN51y+JAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY5IS8wAKCRDRN9E+zzrEiA5dD/ 9Pnutdugl35mpmsNND3wkKYkKNVhDCU8yN/9efaLGUCOX18rdNdmF3OzB74ulcQOMbIr2OtHsVwpo8 774SGkYfiSh0s0ZSNKxDlPkWagoP/wxCj6puE4NrwNwCTkvB3kzOeS4FZClutvKDzN/fds75Ulgh9N S1EjqrWZhSjN+O/xNJmUUun3CDqvmnmT6D2U+mTDX8RqDAEAp1bNjEObBHgL1hVqYifBtLOZS667yS YLSakIjNXJt2J+TIHfM0r+gMO7RIbhNef66a9jQ4Xg2BLiReHsLjFTbeU9C3K9GHvPqkIk1kI/FJ88 MQRmL8zMvoSiStw8sG5VHDDS/OFaWUCl4rtasmT+CtoQ4EvL17sn42HGV64EDP0kIERzVUnmnQXxXv 8G/IblodKjK7Yx8/ABySgL3/I3sV1HAwgA0Nfnc6NhEA5yjDHQx//rajtVLww7eodwn+zhovNohNm1 AVd1ovekbd3kDn1Wtpz00x+ED5qhmZaNi1+IA++Kk+l5J/Uzk1GiY8zAhVg7s07Jky/3/c7XVrCRhe rfGeUjRbUmaQnUpA9r7+4wtRsHWQerSnZK6D3nVj2Kz6nc+1Sv2os3AMUPdrbXpKNfHSRzc1QmqDDm W2PLGlbTyb6BM1UX4yi0LbPbZivH+/xZAuHbRinNocOiAsO8108osa8eKAAg== 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?1751665170293798157?= X-GMAIL-MSGID: =?utf-8?q?1751665170293798157?= 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..e9e1ab5e8006 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_permited(void); #ifndef kexec_flush_icache_page #define kexec_flush_icache_page(page) diff --git a/kernel/kexec.c b/kernel/kexec.c index cb8e6e6f983c..d83fc9093aff 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_permited()) return -EPERM; /* Permit LSMs and IMA to fail the kexec */ diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index ca2743f9c634..18bd90ca9c99 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_permited(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..701147c118d4 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_permited()) return -EPERM; /* Make sure we have a legal set of flags */ From patchwork Thu Dec 8 16:38:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 31440 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp302741wrr; Thu, 8 Dec 2022 08:48:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Yk8Pip0Y17dG1ZwKzhvomYBdUf2fAutGi2QFznQ0ozPY9pJYZ4m/tO4GTKndvFOwTyUXT X-Received: by 2002:aa7:d14c:0:b0:46c:f8af:b331 with SMTP id r12-20020aa7d14c000000b0046cf8afb331mr10662606edo.390.1670518104649; Thu, 08 Dec 2022 08:48:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670518104; cv=none; d=google.com; s=arc-20160816; b=xMfHbBaT1iDk+Jrgo9hDIjbi2UcoIl3lUQFvDy8M3diIIOItIu2+cZoROhnNhBqd/W 5m3oTkDGAcUbvxNoFmMzL5avtexXLYJUtzf+zbjrQByqd1LciSRoN9zxFW8ilpqKDEiA aOeuGwQTvEjOtsgwkLfoyTF9x1WUYhFgoiKK/3Javm7hLFWsYAaoKOB9MAkuIXibpbk1 tpxXX3HAvif5I2BTboRNQc9SNiw2pE7dhGWBFX7wEQgWUHTnNMBYRrE0ZncC+9NrgxpM sXpiWSkghx6Ir7crBBdByAQOGq8ap3h9bRubeKeNZTR9ZzrxJe8c5k4a+0t34phlJKaC gB1g== 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=3nXDL6kXVne0kc9TUvNDrggV3hJQmgrUq1c5voIjIIY=; b=zQK6CBpKAs8DXAnHXq6k8JAABbyrLlqToeaIiwR78nxLGLlF7A+2dFHQrYN6nud1a6 YB2KWuVDL0jht8ylySY+a0a/+PvL7J32fiNJm1v5UtH1aQ2Gn2MPgqek+Q+pT//xFsbV oASjq1ROD1L31Ms+lctTlM7HBcUBRUaIWk9MKXKnZlCx0qcARTT9yDmpJdZyezMWG/bo fKZcz/zJRRr7UCt8d7K+cNRNIklWLSzFctrJUHO4DEaJo7o6ITxjLpeFdqIA1zs66HAi xGpjCT/u5vD/Q7mZEzOlOB71z7JkNMdSsZrvRA++I8bNNORi7aXam9SOrOuloKFUPJdm N55g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=PojL+2VW; 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 m5-20020aa7c485000000b004637e16cfa3si6217805edq.598.2022.12.08.08.48.02; Thu, 08 Dec 2022 08:48:24 -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=PojL+2VW; 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 S229781AbiLHQi3 (ORCPT + 99 others); Thu, 8 Dec 2022 11:38:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230171AbiLHQiV (ORCPT ); Thu, 8 Dec 2022 11:38:21 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44709286CE for ; Thu, 8 Dec 2022 08:38:20 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id c17so2515466edj.13 for ; Thu, 08 Dec 2022 08:38:20 -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=3nXDL6kXVne0kc9TUvNDrggV3hJQmgrUq1c5voIjIIY=; b=PojL+2VW16cI+CcvRz8pQZWoBJ9qktlie/qAPj5ucWA5MY8xtpgOHHVDVRU5pAe7Ce nDMmiPUpy0eW53Q6kW23pyE7V2lP4nW7AbwoIeQfkrOqyTUr4G+BupC0g3nDqnKbB6sP ldvNVDRaqGjV6SEVCCxtCFgoIT/1ss5WM32c0= 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=3nXDL6kXVne0kc9TUvNDrggV3hJQmgrUq1c5voIjIIY=; b=xVdgVQfdYoqLW2kx+SN528HBran6HyNbHlHJsx0aa1X+mhfpqFa2HsW/F+bTsYOg8x eQxGKkhaQkaFJVSpPPFKZ/n48nA0/FJg0o1TXvZfrBODaocHxtCvtjrap61ndZmGs978 LkbkvQ7obffajkKQglcjjt2heKT+4eBJa2vOkJ+rStVE97u+buJw9oIOL9jKlNwRGj44 2sPJ5RPdiaUiEOwrNGn5H0rDuBElMsLvv4WTcIcV1kkR23QbZsAF2Bqga/Z2LC75cqWR TjuutimWbzLcc2hRsRisnoPtw0tbHtRyELfdMOl7JbaOGWH23K5WTdTJkdzZsrRLptoE eRHQ== X-Gm-Message-State: ANoB5pmslEgiIm3Hb6NUZhWkc873k8sGekppeznVmxMKLNmP4elja6IY b6+t2r9JfxMW9QIB+imIUrbG/A== X-Received: by 2002:a05:6402:4284:b0:45c:835c:eab7 with SMTP id g4-20020a056402428400b0045c835ceab7mr2555836edc.37.1670517499837; Thu, 08 Dec 2022 08:38:19 -0800 (PST) Received: from alco.roam.corp.google.com ([2a00:79e1:abd:5c00:8aae:c483:8219:bdba]) by smtp.gmail.com with ESMTPSA id ck3-20020a0564021c0300b0046778ce5fdfsm3569046edb.10.2022.12.08.08.38.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Dec 2022 08:38:19 -0800 (PST) From: Ricardo Ribalda Date: Thu, 08 Dec 2022 17:38:02 +0100 Subject: [PATCH v2 3/3] kexec: Introduce paramters load_limit_reboot and load_limit_panic MIME-Version: 1.0 Message-Id: <20221114-disable-kexec-reset-v2-3-c498313c1bb5@chromium.org> References: <20221114-disable-kexec-reset-v2-0-c498313c1bb5@chromium.org> In-Reply-To: <20221114-disable-kexec-reset-v2-0-c498313c1bb5@chromium.org> To: Philipp Rudo , Eric Biederman , Jonathan Corbet Cc: linux-doc@vger.kernel.org, Ricardo Ribalda , Steven Rostedt , "Joel Fernandes (Google)" , kexec@lists.infradead.org, Sergey Senozhatsky , Ross Zwisler , linux-kernel@vger.kernel.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=5820; i=ribalda@chromium.org; h=from:subject:message-id; bh=ufAC+5YemcJmz894l6PORczSfr2QBpgPQ5bjY5F1p5U=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjkhL1d+L3xiTqMUfLNsBi+qtGpD5Qyq+yPRk8XU3C qeZYpfGJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY5IS9QAKCRDRN9E+zzrEiOw9EA Ci4347jIGvkhhvZj0crcvK5gwVYFGy86RP/xrwiw1eNsD4O5aYVg/imd6Nc49cl04xIhEeTj/hv1W/ hkARCp318XqH7yNDOpH5IAE3TKoKalTtEKGbrWCsaD4pCUf4oYuRKqNq2Zu+WFw3/vnGoUXSX9SBRw A6HYl93KHYPcrFL0QqE+StFWwWYqBwmkxsM+1boorjoLIV3hL0xZDfMH/o4KY2YK0uAPXPm1WPNc/o WZgslC6WHQhWKRowkutP4MCINeOIbd5SCP1jIuukVb4q8xsGzKNlcQ1Hz0vW3YFYWaOY/hsjGzAIFZ sUwO7jou4m9QOjkXzctFUIQKWjyTwbwGLHlzxPqWKKvnQ+W+U3yY2a5I7Q3fLpvIFrJoJt505mshGc bhBJBXKGorGs4F0nP5F5Evh90AUQsAaNcQgwgnqvqytM+TAzLXSXr57DZHZ/PRRnUEqEOb0J4eZXJt IPM9sjrhAmU+Y1/nhOAEN84BmowIsyz8QMjpZkTlALIc29owcmvKAi8DrM/wPCxJJOypZlSY7Lx24G FE7KiVsqpaR5KDpx5kK9C3ompKCNYN7PMoySslSGsnpNfWzjC96bSFRJqB2Qy6JR5tBaIIz6Dh0GTh b0lX3nfY+sVZ6nbUulNMptRcET51QU4x3Fori81S1zjoUm6JjXW3cuyF86RA== 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?1751665192528253959?= X-GMAIL-MSGID: =?utf-8?q?1751665192528253959?= 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 e9e1ab5e8006..3d7d10f7187a 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_permited(void); +bool kexec_load_permited(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 d83fc9093aff..2b0856e83fe1 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_permited()) + if (!kexec_load_permited(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 18bd90ca9c99..7f9d5288b24b 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_permited(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_permited(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 701147c118d4..61212a9252a6 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_permited()) + if (!kexec_load_permited(flags & KEXEC_FILE_FLAGS)) return -EPERM; /* Make sure we have a legal set of flags */