From patchwork Wed Dec 21 12:50: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: 35355 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp3504276wrn; Wed, 21 Dec 2022 04:51:04 -0800 (PST) X-Google-Smtp-Source: AMrXdXtIe7ZL0enoAMC5m4ltc/NOhsUJYDyoSVHO9meBnyCEiizDbbg/jCmbuTys0WkJ/E7etK4k X-Received: by 2002:a50:8e5d:0:b0:46f:a73d:6bdb with SMTP id 29-20020a508e5d000000b0046fa73d6bdbmr1209926edx.25.1671627063767; Wed, 21 Dec 2022 04:51:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671627063; cv=none; d=google.com; s=arc-20160816; b=KOsLn+KyzHFRl0rWGSlBVZwv+0tJWB5XrH+y/ZEZmLEqAanhyHn22DR4mMTbR4EJjO 8kDTcHXQEi5oMQfGh99aL6hL0k36u6UXi3Ojv95SUDe2p/O6JGlt+EszfjWtI2MOqDc9 lM5lvpya6UNAsiZHQKGVRPCm6t8srf1T3pYY/MOx3vzJjARW20fJdHC/yKzeQyZo/xVV 8cHvAVuv2X3Bo3DAvQe2Q9mSsys3z5vPkcpKLL6NUZogXF0R5Zq97djRfZwKkO42biWS KVEG3zptrsHfNj4/pesknQo3wCCUCt6UCHeYYkDKkZ58YBAbGSuZpCmPTjswM+whmEEd lFMw== 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=wtq16U5W4wUHFO6hBhVPLRaH+q9AG1aKNeRyDV7prir23dhz3QEfB98RilmxjRYlxq qtxHRXTX5BTkAy2IEocoR71pzDwbGAcGwP7iivZUgbgI4XlpAqLI6CStnsuKGR4HZKX9 T6ozETryFF1bsabRexhfDTidvE/QzZUZtZC363rFeDwwiqznFQz+puo/0UcOMpakdU6U dX9tKvPjdChb4JiO8pdZSmBPmbTjD6Bw5soTUAE+5zvL4TUdPsBmKXvxRl/0Gf1xgJcD +Tsq0XYL9OVup+QePanujYoLX4xJRjncYvmrgB7FUDciK8BLKn8FtTrmvxfBy1C/SgNq GvbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Yqff2tBr; 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 y2-20020a056402134200b0046abbd721e4si2654599edw.300.2022.12.21.04.50.38; Wed, 21 Dec 2022 04:51:03 -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=Yqff2tBr; 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 S232153AbiLUMuY (ORCPT + 99 others); Wed, 21 Dec 2022 07:50:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231703AbiLUMuT (ORCPT ); Wed, 21 Dec 2022 07:50:19 -0500 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F10723149 for ; Wed, 21 Dec 2022 04:50:18 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id t17so36617045eju.1 for ; Wed, 21 Dec 2022 04:50:18 -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=Yqff2tBr9mLzDgQy6wO8YkbyyU+hHsOTHxduzuz6EKnfOR0lu8sqfmQfLshamlMj55 iVAA8EaJYdBcbzRiPidRkXcu9oG8mq3AKJFuILif+Qw5A9t1mVC0Io31aqbNxssySPHC RX9QCUpEarJByBTn6wamfkTD4mjw446EQSC80= 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=RlFgxlxZvkrynGFc6uywa4aEJoRPMZe+ZYi8ycBawMDKCjuinavLaRM4U4pdxRKoB8 skaIuNIa+MNlEJPngcp0j3tkXM1JTdTSFj3yNs5Jnv/TMmV+u+pLRJI/i0cNjw3EoGoq 390JR7IskzyehsiMUuEHgU+raHEkxoZgOJRV+PgY+sKwrrnFKclTkeujk56fcUnsbnGR jfrDENxFKUY/s26qbCnQChPGX8CnvCoCreNf7woYnS6fNGoPUYtQD3zIz+4SXEtw1WL4 INvI8QIQL2aojzpiowMIKDFy/eVRpl24aFYvBmie6TIlJ9lO7s4jIhNTm4OciBkUxSHe cEhQ== X-Gm-Message-State: AFqh2kqEpfHyktvEkYQxm+8n+OlB/9uO+8msAiI3k5tya65I+g1p/uk4 jgRm0OOCS6WZyere3eMVhG+Y/w== X-Received: by 2002:a17:907:a784:b0:78d:f454:ba4c with SMTP id vx4-20020a170907a78400b0078df454ba4cmr1126807ejc.75.1671627016899; Wed, 21 Dec 2022 04:50:16 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:4b82:b1f8:cb4f:fbbd]) by smtp.gmail.com with ESMTPSA id w7-20020a170906b18700b007c0b28b85c5sm7039250ejy.138.2022.12.21.04.50.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 04:50:16 -0800 (PST) From: Ricardo Ribalda Date: Wed, 21 Dec 2022 13:50:01 +0100 Subject: [PATCH v4 1/3] Documentation: sysctl: Correct kexec_load_disabled MIME-Version: 1.0 Message-Id: <20221114-disable-kexec-reset-v4-1-ab809c8d988c@chromium.org> References: <20221114-disable-kexec-reset-v4-0-ab809c8d988c@chromium.org> In-Reply-To: <20221114-disable-kexec-reset-v4-0-ab809c8d988c@chromium.org> To: Jonathan Corbet , Philipp Rudo , Eric Biederman , "Guilherme G. Piccoli" Cc: kexec@lists.infradead.org, Ricardo Ribalda , Ross Zwisler , Steven Rostedt , "Joel Fernandes (Google)" , Sergey Senozhatsky , 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/ZANAwAKAdE30T7POsSIAcsmYgBjowEB2GKKde5eall1LO2Pukz0oHPGS78uqBtODlWc 0ycx3AKJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY6MBAQAKCRDRN9E+zzrEiNpsD/ 4/Jd6hh8jIzj6DeUtxGlMzPF8D5zTmDrn/O1OymQxG1FrMk5siVZtOH5aFCarWFYcAhrpdhW4IyzQG x0LSbJOT9jtwz5WKENrU42nTbpshboubcK+byC6h9iFYohm+qqWd0DVMtYej85mKcLmBHuT4dp4MoI LPkqfifmzf9blmrz2nDD2uArhMxRsApVCT68UqoZcDIALczol/keRjGKk9vZd8N12QMeUEfCZ+uMs3 dT+AIpxtpZ1NWQpzgdypP9qzvi5ORxV+fA/DkV2ebJ42YUgHdi2NXRE8m7srVCBOLaHJfRSWo0zkGK DCjmmjzjvEjbxg2w0zqkQrQXtKge17NMqdFNrorlc3zOootGjCl32IWvL8oLVI4h6GCBzcDSasVvNT S2D1C3y/IMgOq+cxa3gwXY9Iq0QKA3eSKGvF211pYJYSXSRfjyx72V2VldqDwD/4XS+8lpJ90Ilwn3 txPAfh70ipePz0zVIlvic1kAGXOhxdsXlGVQ+azTd6eBL0e40YuhKA6xogOKxMcMsFD5CZNwZdhGQ1 JkYCGDuyvx5Abq4eX6KsYYAjWrWQ/vOurA90O4gF7DngsY7OB0vWT2T5FJbneNNtj9Nsg/b2HtjoTP PpkbxvNdPTJleHpZEy3DIrOPpkM8bU2jp5zQi/q/mxk7hruVcHMZhsZd/x/Q== 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?1752828020049342966?= X-GMAIL-MSGID: =?utf-8?q?1752828020049342966?= 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 12:50: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: 35357 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp3504949wrn; Wed, 21 Dec 2022 04:53:00 -0800 (PST) X-Google-Smtp-Source: AMrXdXsQGktnubKPUww5NgnPd7EC1e2NzwuCuSrMtRO1Lz92UqJKdWT8ViUxIvrX/kJJ22UtGjRS X-Received: by 2002:a50:ef11:0:b0:461:f201:2d98 with SMTP id m17-20020a50ef11000000b00461f2012d98mr1433809eds.3.1671627179891; Wed, 21 Dec 2022 04:52:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671627179; cv=none; d=google.com; s=arc-20160816; b=HWOk9XlJvOHH4+/1Mw3tbZrVfpDUecXD7yB7l/AWIv2WomupVlwM9oBKdg55YUQXVh QbrBZabL2+OV2hxetTviWnnqKIEF0yInATRVppDQcZA/TtR+QU6UK3ajof8OkBIlnAQh /Gg90M42Hfl55H9nj3vH9qIlIvKmSkfoW2IWeYiqRM7H46KWDYvinKPu9yroIFcsk0+5 6y2a/LyBEz4XBxpMM46QarGD4uVcq3NSJYl7iMeGa+t5tkx6psan10GdJtS2Eg53+qpB ym2ovWC6peKZv10ktc4bPHTrFdzt55wLRhC4mh4bh+uZ+dG2Ejj+B1bjl0ojjBENKBDX whPQ== 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=H3z4VGwNcf7Hp8J13LGV+/f1zsvR3cEcUuVPNZy+wXKdHahveWjyNf/KD586h4460T nmpPyr5rf2TjTWveBXN+b6ns9HM3chtPzDLp2A0oCPAjjYo2YTopB/+kiHPYTS192gVI rQpClEp2U1WFF9Nosdoz/+OJD2zQ0I3UqyRm1qhga2qxU3qkwPMuDeeN5tgZyNjI1tpw CGbNeOZA0jdbBM3vKi49rcBSYGezA9GFU1/j1f8fq2XFQDfJiRYcglixUyBs0ovZxAIs NISr7nc5DJ0mZW7IxKRM6+3WLcJDyUt5o6qqEiq/8TsAKonFzQki3KRYa0gYuiqsa8SC lmSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=R2RT15AS; 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 fq32-20020a1709069da000b007c4fda74f69si9774255ejc.241.2022.12.21.04.52.36; Wed, 21 Dec 2022 04:52:59 -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=R2RT15AS; 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 S232455AbiLUMu1 (ORCPT + 99 others); Wed, 21 Dec 2022 07:50:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231818AbiLUMuU (ORCPT ); Wed, 21 Dec 2022 07:50:20 -0500 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2A8422BF5 for ; Wed, 21 Dec 2022 04:50:18 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id fc4so36461562ejc.12 for ; Wed, 21 Dec 2022 04:50:18 -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=R2RT15ASWFQQ+HJe+0sCo+uF2kmwezaj3G470IQ3VwrN9sGIz7hH7YtE7+LcKHt6Cj oJw2V0LJVsPN/SBndPAGkCuI6O+DXEN9nMef2mvpzYidC5dI2ivk5DxCDGzkMzM1FMVl QVCsZJW6B1pti7LEpdEOt0AR1rG8O44Pgjaag= 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=S1grZ1xWhcS/UqvylDTUuTb1lq8v5bmUSVYG8YCjKAi7nP4nVOTFVqvdMssEu+NFe2 aTIElr5Y9BrujuTz0vQeglIkdrjzq+VxZ43ne1rPGMdlYE7BeYXPoJnALkxXrHZtK7jq ms1YAMRS3ZUTnXBjNxsN3yBKFUq1EYhqcm5rxDoMXlBUfJ3+YFhJ/yB3Kr2FAK16kxfG 2RiJDlw72AnnnCXneCLm8B0Fxpr4eHrIVcBEp8gHbNlCpyLAJ0xZHMgIQ3szxH0MvFr6 iLpQFMwYcPLDnzCL2u51vRmt+7EjwmKlAYex/XOFj5KZpMCZ1QUf5hZLz3krkzMGaZuB D1/A== X-Gm-Message-State: AFqh2kr6mmd8F2kDHwgwh92spL50nvm6WabqXXknmvG1rQ7FsN6nWn23 +NQ/RNiVMw+UPPhTzYZQ4tFb9A== X-Received: by 2002:a17:907:d10:b0:82d:e258:fa55 with SMTP id gn16-20020a1709070d1000b0082de258fa55mr1453100ejc.36.1671627018527; Wed, 21 Dec 2022 04:50:18 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:4b82:b1f8:cb4f:fbbd]) by smtp.gmail.com with ESMTPSA id w7-20020a170906b18700b007c0b28b85c5sm7039250ejy.138.2022.12.21.04.50.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 04:50:17 -0800 (PST) From: Ricardo Ribalda Date: Wed, 21 Dec 2022 13:50:02 +0100 Subject: [PATCH v4 2/3] kexec: Factor out kexec_load_permitted MIME-Version: 1.0 Message-Id: <20221114-disable-kexec-reset-v4-2-ab809c8d988c@chromium.org> References: <20221114-disable-kexec-reset-v4-0-ab809c8d988c@chromium.org> In-Reply-To: <20221114-disable-kexec-reset-v4-0-ab809c8d988c@chromium.org> To: Jonathan Corbet , Philipp Rudo , Eric Biederman , "Guilherme G. Piccoli" Cc: kexec@lists.infradead.org, Ricardo Ribalda , Ross Zwisler , Steven Rostedt , "Joel Fernandes (Google)" , Sergey Senozhatsky , 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/ZANAwAKAdE30T7POsSIAcsmYgBjowECkFe21vSuqwF6tn2p8L+BKJ7tkuaiu4yiHveG nMtEFu+JAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY6MBAgAKCRDRN9E+zzrEiO7dD/ 0XCbh5Qt8a1g8a4Ymj0sdar9KtUlQmWiFta0b5GfuPwcKQF19M9Med6ybxz+sbYW42P4SmN9A2XNec hNqPXR722Yi+HMUx4Qd/B+ioG5bVXLpahjFybWh0OzFejOEsoFCdP+ZIGKqe7i6jIfWWayud7NCbIL 6CXuHhCyrTGg8tpp3wsxfnogoFnEi6Q252E+w1Jgmlyyd/u1tMQbVSJ5XRnOpVTOPWFLecrDwZLRkm vJrOhRDdEnRjGh8q0E12ff/RTZ9giik6eekXfuPzJP6cI9mynKpzBzk8lxlqJzv/c1AdGr1eBvidU7 SwH9z8VvgHgK6vuN/A2DcxIC2Nce4PgvCzE6HLf6N1SaFL1iLZgB1GfFvYRxKf3cstzH9PVF2aYtlm r+QOw7ZwzrUnuYCZ+oULXDrpN9BNvxXwiG8Z2XdLWWqApjvxbZg72DlSXqkoiXK1k67Lj60HEehYyc jW+mz5MmMhqWT9rPRTbOMYdx+ppB4Szq4LEWarobPro9UZ8hhekXyXhYqgdncIvlR707JCUDjuEfpa Y2/uGgzDL2NaIOghN2/Y6X29qA6cfq4aR5wEEKHh8YhUEJBL/lHtsVN//Na8/DHod2e95JHXdO1EFQ JCZkKRC/0AcMQmLyUH832g1pR/uqXtS1FKqQfFmUTzN8WRH+qZmdP3k0Psng== 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?1752828141849981911?= X-GMAIL-MSGID: =?utf-8?q?1752828141849981911?= 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 12:50:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 35356 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp3504592wrn; Wed, 21 Dec 2022 04:52:03 -0800 (PST) X-Google-Smtp-Source: AMrXdXtGE7eJ40Gi4pfXtceHG75s20fLcs5dwVBw3YFxZHVEHIpzX3nQSLVPq60LNbwukIVX7YRo X-Received: by 2002:a05:6402:249a:b0:45c:834b:f287 with SMTP id q26-20020a056402249a00b0045c834bf287mr1468403eda.4.1671627123556; Wed, 21 Dec 2022 04:52:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671627123; cv=none; d=google.com; s=arc-20160816; b=nGuFM0p6sHELI/yfq7Q+gGYpNOGEgf6ETAZEiMP1SyrlyVlXVaaw5ftEor+elluG7G z3oWuAQ/17VWWtEyWNRD2TLDr4crG0GoLwdFtBqCnwki3zgTUQFQ+DHmFUlw8OuOLTb4 a3yZ75jaC3ReJkzDkJd2ao2EO7PrWi8PPiu7cohIY4MGagHceDdFRXwd5Z6qTSYNuTLb MiAVy295EtNhlAHJRWp3DlofihoZBQSdmHeXw2GL/eeNYdrhJiZrcaIPjpp2VHQVVjpa tjK3cMpsYy5iohKtm6Nzutgw06kFnD4+M97coRADbgheIJq9riHQ0itf7RHMfEQENE3E xU1Q== 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=1DriUQWaxtAZKeveQD8Usa3n+i7++5rOgNlUWHQfXOs=; b=C2zZSCCg40OCUSdFAFtVn5vfCEDcZzI7Wax0aVavUf3F3Bv/VmlnRwXUC5UZg7/hDZ jDF1Wq4pkpIHpECyqBK5hfJLPYr2RruoDu4Sd974+agjNkSfQ14JiUJasx1UkGEym5DH z6EdLUPdOUf8I+ENLqSaczy7HdtdFxBQD3UrBHqt/EgQdggoRUS9NzzFCXJVQoqhK2UT Gto4fsJN+DgofNfNxQl+p2syEtS3SV6Q6DrV0YYfjtRYO0gvO0uPSERTxAEgF8AP62gz fbYHWKyP36YEWcItUgY1r1rmtc5HnSxM57veSFwswnmn/Mhj4KHnt+t/0b9dAsK2w2kz p5uQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=nkjhzaUf; 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-20020a056402278b00b004619867344csi15688321ede.0.2022.12.21.04.51.40; Wed, 21 Dec 2022 04:52:03 -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=nkjhzaUf; 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 S232380AbiLUMub (ORCPT + 99 others); Wed, 21 Dec 2022 07:50:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232067AbiLUMuX (ORCPT ); Wed, 21 Dec 2022 07:50:23 -0500 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAE2923149 for ; Wed, 21 Dec 2022 04:50:21 -0800 (PST) Received: by mail-ej1-x635.google.com with SMTP id ud5so36588087ejc.4 for ; Wed, 21 Dec 2022 04:50:21 -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=1DriUQWaxtAZKeveQD8Usa3n+i7++5rOgNlUWHQfXOs=; b=nkjhzaUfRMEi9ghebnUaQwIQlmqGl4xjc8nwG5r1nFx7RVq/OgGkh0jCBKHKK2qs+k 14xwWg5dnU4CT86bwEQDn1LG9qERLW8ndAKUMqCy2i5xS8+uVD4T2/6gXNWJOZvu26XX 5dGp5u+NNcjcjTS0B8/VOTKEmJclpQ9akydhs= 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=1DriUQWaxtAZKeveQD8Usa3n+i7++5rOgNlUWHQfXOs=; b=JfGNL1ldOmxj3xWmEQmaaoR0XYsU/x0xLOvMDA2qbmfOhjVeYSeQZTOqJhx7Fand91 g3MBHL2H/dqpM4PugXq4+wHYAcbiMUEhbKbaBeG93lOVk1YzgKh27p+Xs9Ag5Gyiak35 ZyvWDR2vFecyyY4MadsR6FBLBrYLEveu5kpJhEr1kUye/SJEYxxzlwDjSuEIpYFwP2Pu zKD/X5SEyfKCJZpzVghhmzvmwpdstMMD35FaMYGJn8kSHcK6DLqbMLoOH7GYclZzNVX9 CEbujqVXmBB9mSs2nzsM0KhyZKyuCynTq3wxAfv1bf7A+NgR/MGPai94YKWbEQq2mI3v XfDw== X-Gm-Message-State: AFqh2kozQjKnltpogSN8UxeGMUj60zhRn8i3uzFI0BZu0+9sI/1vZz70 wzhQ8PA9Cf3zM226V+Gc+V9uEG97Qxsxq9OpudE= X-Received: by 2002:a17:906:c34d:b0:78d:f455:b5de with SMTP id ci13-20020a170906c34d00b0078df455b5demr1170774ejb.30.1671627020458; Wed, 21 Dec 2022 04:50:20 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:4b82:b1f8:cb4f:fbbd]) by smtp.gmail.com with ESMTPSA id w7-20020a170906b18700b007c0b28b85c5sm7039250ejy.138.2022.12.21.04.50.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 04:50:19 -0800 (PST) From: Ricardo Ribalda Date: Wed, 21 Dec 2022 13:50:03 +0100 Subject: [PATCH v4 3/3] kexec: Introduce sysctl parameters kexec_load_limit_* MIME-Version: 1.0 Message-Id: <20221114-disable-kexec-reset-v4-3-ab809c8d988c@chromium.org> References: <20221114-disable-kexec-reset-v4-0-ab809c8d988c@chromium.org> In-Reply-To: <20221114-disable-kexec-reset-v4-0-ab809c8d988c@chromium.org> To: Jonathan Corbet , Philipp Rudo , Eric Biederman , "Guilherme G. Piccoli" Cc: kexec@lists.infradead.org, Ricardo Ribalda , Ross Zwisler , Steven Rostedt , "Joel Fernandes (Google)" , Sergey Senozhatsky , 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=7163; i=ribalda@chromium.org; h=from:subject:message-id; bh=HKgbfk2XXsC7dJWJ3vDw8GvYO5iTUMrHx/g5v9F5/qk=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjowEEp60hS8E28LMGFXbn1WFwG5VJGxaNqKNdEtHF /FGZVS2JAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY6MBBAAKCRDRN9E+zzrEiBgvD/ 4lyll/4tYvAwnei65g8L6jBQb8tXxk3e6u/bUNXDOj7Haf8vDdahHU+mlGE+PpOyPBNd0fGuGj95NO d6sAqgfWFINsn+VaqcKkVxjaxauoTEOBmijP2gLSXw9c8582/1W3GGNj35Al0Iuodxz2j3iGyWKjyT Z+EOPPHWLTRl7cZ2BZ3jk+3MXFX56jB1CUYfdZsv9VO0P/TZcTDcMYqj9qgNpW6Vwfh/4DFKy/9fvl K+k95b02TFli3A21fC1naUP4qd422sPux5aeyvnOgWFOU6+NThTvkwTOZbHGMP57H/NAYIaiGnGt01 wzkOebsrXbxtVrQKAsfXDlCcVmPb4Xd/0ekTfYvbgpRZLwUUNiqqywGi1JCLGtwcy2Id+Oqdj33WZc 5dpCialG9rhSxDWOD+MmQfII/oHsQOVFn5RqM9KBQqzpBTCMnNnaXNdQ+786Ru/V1Su+nILm2hnewD /R+SRr5FRBfuQFXeRvR+8gXM5U8vS5zywPMFsKfPfG+8Sif+E+e7FjsMEFmjAqYINso2TW/gzus2b8 loLzadi08rgs5Jz+F2GnykptWff4/WkgWDtXa1B3HfpyVzrpZaDWpTX7lr+J1E3ZqgufLxZxRd3r4e JhsrlXmriA5H/FysOlTnhQtCD5ibQAakqRd7IOwlCyYiMGLdzyHYogkucGKw== 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?1752828082577646507?= X-GMAIL-MSGID: =?utf-8?q?1752828082577646507?= 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 | 89 ++++++++++++++++++++++++++++- kernel/kexec_file.c | 11 ++-- 5 files changed, 116 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..6131b1aee165 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,20 @@ static struct ctl_table kexec_core_sysctls[] = { .extra1 = SYSCTL_ONE, .extra2 = SYSCTL_ONE, }, + { + .procname = "kexec_load_limit_panic", + .data = &load_limit_panic, + .maxlen = sizeof(load_limit_panic), + .mode = 0644, + .proc_handler = kexec_limit_handler, + }, + { + .procname = "kexec_load_limit_reboot", + .data = &load_limit_reboot, + .maxlen = sizeof(load_limit_reboot), + .mode = 0644, + .proc_handler = kexec_limit_handler, + }, { } }; @@ -952,13 +1020,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)