From patchwork Wed Jan 4 14:38:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 38959 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp5178549wrt; Wed, 4 Jan 2023 06:42:58 -0800 (PST) X-Google-Smtp-Source: AMrXdXtSVQgxPYZopx3NWbHWCe69OP36nD7nPqIisoBsQPnknwmkA0iP+Bb2vgU7Y8Sw6BuGeubU X-Received: by 2002:a05:6a21:3294:b0:9d:efbe:a122 with SMTP id yt20-20020a056a21329400b0009defbea122mr74173374pzb.50.1672843378655; Wed, 04 Jan 2023 06:42:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672843378; cv=none; d=google.com; s=arc-20160816; b=X3nSqWVr+wrPx87v7AF6JdmcuOUsB/LTXTosO2OMfXFUGNltbEBpqlyHs1b1D3apTE bx06ceesKIFdxSTRqOpVAwaxQOLsTUxQNiNhqJRiJfCy/fetTJ36Pd3Pl3adavX1qskk If3GAzXEuNxrDcrnhusim2XrmQA+1PXB47QnZAdSZwTb8qMfxN/gja5bC7fxPKUyz0Q5 gjvtSRKpvpmQk+3BFNHD7Sacg2XEw1cSv2wZRqEB718yvoYBRkdh7zGzQcPwD7lVu3RN RnMbSXdYhLI6UfkfTJStIQ9TdwKJmEn0SA3nQpmYQ0TI2z/hrC9SmZaK7b12MlEGtfFX vXEw== 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=CYYQgh/lv3T9poZ9Kbn1xfKKla/OcUPaY2NVZr8/1wI=; b=I/IesttV7gWm4FOaRPKNQYHtNF6nth0TPidCwlm+iXCY2BCBfcl50J0Y2YCYTzKSd+ rRWmYcckWteJEU7trHrCcQ2yzrF+C5Y6vexwtpn3d68ltg+8a0TZJWwAMdr8kv6uiPs4 9yIucS/VNgUOP/Ro46JpZsQZ2vS2UeOLcgBeNOs9oXpXktdQvib+njOgnZug6HFpxpH2 Xv/OOLizqI/pEuDjMLRZZyu6VJXebzVl+yXPSVbhaGgnThoQx1a1hNPOV+PQWVEYdgDl VMDxQ5yOoR+x5sFz9usvJZZkyhCNK6U7VGy3UVzWpduPxQmvFSMTenW17gEaMhvT3EgE ssjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=TPhzP6VD; 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 bm18-20020a656e92000000b0049ca23dd532si20925053pgb.109.2023.01.04.06.42.45; Wed, 04 Jan 2023 06:42:58 -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=TPhzP6VD; 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 S239354AbjADOjP (ORCPT + 99 others); Wed, 4 Jan 2023 09:39:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239301AbjADOjM (ORCPT ); Wed, 4 Jan 2023 09:39:12 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F4E26167 for ; Wed, 4 Jan 2023 06:39:10 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id tz12so83091307ejc.9 for ; Wed, 04 Jan 2023 06:39:10 -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=CYYQgh/lv3T9poZ9Kbn1xfKKla/OcUPaY2NVZr8/1wI=; b=TPhzP6VDMUU3QtDkGKBz2ODkHY5IHPZJLk2AHghZRhDppkwIzHLh+ClSZSi7dOkdEO djNbFLbX/qbVhko5HtmYgh+KwUPHIj6YbIq8IfqKDrqPxZwEVo1ZnOcnm84WOikjUIXN 84Nn49z3bmZGZyGjFWM0g31CC5lEjul+7e7vQ= 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=CYYQgh/lv3T9poZ9Kbn1xfKKla/OcUPaY2NVZr8/1wI=; b=4/5lzIax1ZRT/pm98zsO57kdRzz3uKB+Kw0fsLGOHHZa6PrPJgXAHLbyCDyiJNErm8 jkcrpB3f+BBJj8psFa6uRFB1yO08D3NhucCofMEBXG7+Qz6zonOB9aoWSk/j7mcseVLm 65r0rApw+ad4u5YprQLl+haiky1M5CVdaB/K1h0XsQIozLh+IZysYFie6c/iiTIPoKUb d5Cz2D6aEZUOafKgVDo+2jK3SGKEXCkJeh3t9SLnpiwfkrKYDTn092tCzBOwcVvFoMBo cLme7dItgzeJr0/ZdaUW9cJnNmwoLPPcD7rQD1I0WplsTawxy9G3Qbv2zc7H2myl5iQe vRyQ== X-Gm-Message-State: AFqh2kq0DjqVSqT5nshLilaCboBojsa3q+kXd/VlhmkonPlTGybpuV/M aTlJtfSAUOhafVNgx+m3AWo2HQ== X-Received: by 2002:a17:906:5dd2:b0:7c1:7010:f413 with SMTP id p18-20020a1709065dd200b007c17010f413mr44805532ejv.19.1672843148794; Wed, 04 Jan 2023 06:39:08 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:a438:c7da:62e0:36f4]) by smtp.gmail.com with ESMTPSA id c8-20020a170906924800b0078de26f66b9sm15386659ejx.114.2023.01.04.06.39.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 06:39:08 -0800 (PST) From: Ricardo Ribalda Date: Wed, 04 Jan 2023 15:38:46 +0100 Subject: [PATCH v6 1/3] Documentation: sysctl: Correct kexec_load_disabled MIME-Version: 1.0 Message-Id: <20221114-disable-kexec-reset-v6-1-6a8531a09b9a@chromium.org> References: <20221114-disable-kexec-reset-v6-0-6a8531a09b9a@chromium.org> In-Reply-To: <20221114-disable-kexec-reset-v6-0-6a8531a09b9a@chromium.org> To: Philipp Rudo , Eric Biederman , "Guilherme G. Piccoli" , Jonathan Corbet Cc: Ricardo Ribalda , linux-doc@vger.kernel.org, Sergey Senozhatsky , "Joel Fernandes (Google)" , Baoquan He , Petr Tesarik , kexec@lists.infradead.org, Bagas Sanjaya , Steven Rostedt , linux-kernel@vger.kernel.org, Ross Zwisler X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=1318; i=ribalda@chromium.org; h=from:subject:message-id; bh=2pZFS+1BHtUlFuNmvm1mTYxkgU9yharonO0OzNd1vYM=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjtY+EP67lwRrCO5L5k4Dp6xvXVoYkuhFXhgRbt/kG 8bQ+rx2JAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7WPhAAKCRDRN9E+zzrEiEwYD/ 4usIWKfOuuGi8xYMQsTa952RC/Gqq3NLfoSqb13IPaxmQxqWWUjQ9uDtxl6QD90QnBoAjD/tSFebtK EapNZosQxrdc+t7axxND9uY17FhOJIKscuu90wrCExbOXav9p2pBlZVk1U8k/WwDAJrH5qMpt7pUvw pGRdxVE80sFSCeFSJCcuNrY0XeAYjO2cxzIuLxLSx7O9za8wFCZF4BMRohyc7tsSyl2EVdZYcemr0R 4z2XLsWYVQRXjtccMgFRkfCGOOmNW/hXVuV11qDDGyf5CSjfO9R7+6laH01SA3fF0Uk/E8Q+3LCu59 6F5RMHfOoXh38K58UOC8w/U2l5RjiRF2XC4yfmrobAdgnYqmutRHi+Lug8kNkWndLNlewOVKt3Cd63 wlBc/bMdd6ccRlzZ1pU8IMBsdVp1LCIUWq+IttQU61DODNb9Eatwj6wxBX8Qnhg0PvGrK8Cvsaamfp bYOMgQZU49QK2hsbc/aWhMe4mAt26NsDxp87ifiQjgWtpCkBYvj6Su8gg8VEAehX3Nl/1FxQA05HsT xSHhehNI5G5pHHslJ5HupPSSbvcOEZO5knYX2C0pCmWn3Gji43SAmKZSHJ3DE3zeUe5bJZlTJLZHBw XTSGECyozGv6ERamTopSA8x3YabJeqxtU79aXb9q9mYqfk5MxwYuXUKki4aw== 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?1754103418335566930?= X-GMAIL-MSGID: =?utf-8?q?1754103418335566930?= kexec_load_disabled affects both ``kexec_load`` and ``kexec_file_load`` syscalls. Make it explicit. Reviewed-by: Steven Rostedt (Google) 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 Jan 4 14:38:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 38956 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp5177810wrt; Wed, 4 Jan 2023 06:41:33 -0800 (PST) X-Google-Smtp-Source: AMrXdXsPjhmidb2JKle0dHrFE2gXZMv7n1tCRUNSImdc6ENWx2ZJ/+1BozzgcrPYMZjH3ue9Mjs3 X-Received: by 2002:a05:6402:34f:b0:461:7c4e:c437 with SMTP id r15-20020a056402034f00b004617c4ec437mr43768412edw.1.1672843293030; Wed, 04 Jan 2023 06:41:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672843293; cv=none; d=google.com; s=arc-20160816; b=aR47MQCgam7CEbILivqdbutl21DXjWyV5E6yEWjDbB0W/DjybTO8CGvgrKpdTKB97T hxUOFlTP9NAc1pLPdUKeDOr2V8dJzdq54uerpsWNTRsvaWRza4ZtYPSHKZ1anacLtwT3 eGSzr9tLJTWsBp1nQpl0hBU4d2Ekv+ZeD2/YHWUVKroDNLgDUaAFjlkCkAD4cRAb+CL4 tfN557VgZSlaMnAFxfAPNLMkrvBOZHXLXHhWFvcxlog+unQcKzEIj8IerUw8YC1mYFBS rcWaUakOEAkc8i1X241fXEJ2VO91XRQ4hU8C2rqujQgwnu9h0Db61vP6YieJ6e0Da0Gy ofbA== 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=UgxvQK67tmMrLA74uOg//Gx6503PSr9SD0hLGo86OJA=; b=Lk284LXeCg4Q5joVx7MJZFR4Ef7CWYP0kck+R2ne3gvry5xAcI3+z2X9mm5fyleEp2 jGnlzF/DhFjeCOLWWhjFr4lOkriUnSw3IBO3WvlNt5ck+nla4x1CYGYDBLr0gdgPtOR1 I7oHhQj0SJlrelQZJqzFKFe61HjbIGQSZHUtj5WD7J4ILreFqYSN9PcE55jAVDLdng0W FbSkDN7f3KI1LfjLsIb+XMOuIRRvzJBTATsKHWcoymf8/tyiHI3zuxOlizC6E/urgoxW KAvQVzEUz5+P+oj04AwuhzhTskN71Zhne5rS14yctOvFVisn69nV8Q4shI9ojQjYqpBm EvpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=OsU1Dngz; 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 r11-20020a50d68b000000b00469b79303b6si29254526edi.195.2023.01.04.06.41.08; Wed, 04 Jan 2023 06:41:33 -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=OsU1Dngz; 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 S239547AbjADOjU (ORCPT + 99 others); Wed, 4 Jan 2023 09:39:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239349AbjADOjM (ORCPT ); Wed, 4 Jan 2023 09:39:12 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6363E7E for ; Wed, 4 Jan 2023 06:39:11 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id fy8so19059473ejc.13 for ; Wed, 04 Jan 2023 06:39:11 -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=UgxvQK67tmMrLA74uOg//Gx6503PSr9SD0hLGo86OJA=; b=OsU1DngzOr4hhp/EoveJQE3TgkyHrAPpIqNakGYzicuHh+CEyyLyykYhfaAoqGFAP0 LYbScr1P7QayvqjcETjQvA86XknilwM/8QYVJvo5EC3i5qtaTrRhxUBFdaiU4bPIhAxz Hbe9lGwRtmdSmOtj1sxtys51p9R+230EoGueY= 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=UgxvQK67tmMrLA74uOg//Gx6503PSr9SD0hLGo86OJA=; b=jRmNYNxT5Hbs7cZwDh05KLlZRMDnt1l49NxyE8Y9MmOSNNCYU18Htj8kPq8QMZTY+j Botk4YdgjWP+w57A+h7urR0JZ11OGca3iAfKQcaBJGt5Mn4WZ4z/e6gBKC+hMnoJD5qZ mTFOCUweKCP9hYF4/BwtVC08pJsxf0K/eQL99J4AjBwpwIbV9IO5Lct4USxSpP/PTt5B E0BO01kY4csPQJVkMPHnFmNmQrkITd3glcGwBeG9UsBS9KZccKtF6CPUgvEkCi9woNcF qg7tQXPJ7GyBHNKFwzAfiVXBqyP1T/BH0raymE+gpWHzDSVrgsMSYdA2ZDNWcg9IFjc+ YlVw== X-Gm-Message-State: AFqh2krzQEqDKLBoMeT1girfJ//Chu7i9mgyCNbz2nn1QdXusTGqo+fL 1WvHlHrEl1y5YIRjpw2liV09qw== X-Received: by 2002:a17:907:a643:b0:83c:7308:b2ed with SMTP id vu3-20020a170907a64300b0083c7308b2edmr41277617ejc.17.1672843150377; Wed, 04 Jan 2023 06:39:10 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:a438:c7da:62e0:36f4]) by smtp.gmail.com with ESMTPSA id c8-20020a170906924800b0078de26f66b9sm15386659ejx.114.2023.01.04.06.39.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 06:39:09 -0800 (PST) From: Ricardo Ribalda Date: Wed, 04 Jan 2023 15:38:47 +0100 Subject: [PATCH v6 2/3] kexec: Factor out kexec_load_permitted MIME-Version: 1.0 Message-Id: <20221114-disable-kexec-reset-v6-2-6a8531a09b9a@chromium.org> References: <20221114-disable-kexec-reset-v6-0-6a8531a09b9a@chromium.org> In-Reply-To: <20221114-disable-kexec-reset-v6-0-6a8531a09b9a@chromium.org> To: Philipp Rudo , Eric Biederman , "Guilherme G. Piccoli" , Jonathan Corbet Cc: Ricardo Ribalda , linux-doc@vger.kernel.org, Sergey Senozhatsky , "Joel Fernandes (Google)" , Baoquan He , Petr Tesarik , kexec@lists.infradead.org, Bagas Sanjaya , Steven Rostedt , linux-kernel@vger.kernel.org, Ross Zwisler X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=2784; i=ribalda@chromium.org; h=from:subject:message-id; bh=k6P1smlJYbqtcVyvGezj5oVw/cqtzE+zRS/qzT0ctCc=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjtY+F5BhkliZFvYK5Ym2wT15gzQ6IywHdyBQuZv9D Oz2Fl7SJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7WPhQAKCRDRN9E+zzrEiCV9D/ 43PHdTJ87hSQ5gRjDLnN9QhBf/0sdKtpQSIVJtwjRwJj0fKVXNwKAbxnZGaKGFbK0+D6XWur5dsPhx zICLrbRMjNO5zu2acdEIcX0Ixyc1goxQxCWSvLbPGI13Gu0zXck2k1aGNHQxbrHsLsoMWv1eJmz7ur 0A1lsCo+Tm3tAmEnvQh2aD6k3XqJloCXOAzXoiwo3JjNn7aUKZmMnNEOVMiMhnEORyLIkQanA6I6pL XJ8jguQA6h/Bp8Xn5ykknlVGxjJvu4Nn6rvEnUKm+kp7L1k8iiUK7HcFRf4VPocxKiILNgowAGfnlR mTGEFPqHMTv+Ht+GLfRhqEOd31vGL8VkT0ermM6YAqLuhXIONQn4Jaewcdw90K31Teiw5Y1mdal9tj J1IkZa48R7TpCMYFTXf7SibBowvNWa9Vrz8vbrM7SE3cjIUTs0JvqP6Vav0a2TmgMgKdcOPkNgDP6F EotJDSYyCD9L+VjV54ebwcd6Tw94km8BKQtiR8AdwBHagfrBuQIYUJtBL5nWYP7hP8HiQt4P4Ubj7c kk5rmipLfXeDwJNM5L+L3kUi38k3o9hch06PSlNgWkhmhBSPAlLZxWZ8qTXYLWRpyfFX35Qzx6p1xD bjTLM5g5f84UHd42O5GYOj3SQoPP2t4muxbQhIIms/wq5G20v9tluc/GAVQQ== 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?1754103328849276752?= X-GMAIL-MSGID: =?utf-8?q?1754103328849276752?= Both syscalls (kexec and kexec_file) do the same check, lets factor it out. Reviewed-by: Steven Rostedt (Google) 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 Jan 4 14:38:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 38958 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp5178061wrt; Wed, 4 Jan 2023 06:41:58 -0800 (PST) X-Google-Smtp-Source: AMrXdXt39RDrnlTGYyYXRhnbElQCKuO4pTTGxvgjR1M6uC01JZR/ithQhLDDFpIrISu/gTdCV6IW X-Received: by 2002:a17:907:3f9d:b0:7c1:1c4:5eaf with SMTP id hr29-20020a1709073f9d00b007c101c45eafmr59066771ejc.49.1672843317841; Wed, 04 Jan 2023 06:41:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672843317; cv=none; d=google.com; s=arc-20160816; b=ZyazcoEFcvserpaqeP/B/zyQ4BRqVJIqOf7drP4hHe7mpuVSxz1CWL6LxKq1fCiB/v +KYCbs7nz7NT+j5aLqRRlxukIdBAqBsb+cIsEHbE85Z7Lrjrp/S2mKLfdejS4ZxWT1Ye eQROE2HnYCtdwz4rzPQ2/iR+Fu4iOHkC2UB+HWI6kXz0yrqbCa2n1PFgL2ae8Dj6+4xc sxlcW/ZZpVgEVcjkgBbpOvh7EHcktL6nR02zmYoqVGvoxW7rvOqFZZZ4vQAWSd2/O3bE XiEX+T1Pp3foZQkiZCD0Yti0sD5Pw+R4nBj7MidPT0i4ntf0fkuGpzyt6kQHSLDdSST3 ffew== 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=7ktTgqCg5vZndbEsq2NE84RTVG7aeSaApbDApUiy3yI=; b=fZ4xEVcY4JygVLMa9s6JH7BkOgZAcV7vw8duxb3cb92ePy0lJ7JaDTzU6QVI/Kuepc pLoifYe9kSibTGyaZfNiJLUpxFiFTxSVL0ZkSB2qZMhX4wvg9wVdxO30LaXOVuiTm1YT IjK/Kn9XPheTqF3vjnn/Fho/3yb3X1Ko3KgOHm4gLCmwhV16EaeSAN1MEZdZObThoIZm mrojwDJwctFIxE1/s2hcjXDrDFNMB5hfkCCFQkFyBdnqGmGmKSra6ue8TvyEf7u7Jqu4 +LAhUl4NK7qAFB+tlPtar6M07nXT4nzURJniEIQjMA5kAH3eRu6DHk/T0WX89rdd6eF5 G+LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bAo5rEoM; 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 hz2-20020a1709072ce200b0084b9ac8f8a9si11949478ejc.959.2023.01.04.06.41.32; Wed, 04 Jan 2023 06:41:57 -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=bAo5rEoM; 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 S239592AbjADOj0 (ORCPT + 99 others); Wed, 4 Jan 2023 09:39:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239489AbjADOjO (ORCPT ); Wed, 4 Jan 2023 09:39:14 -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 4B9FDA45E for ; Wed, 4 Jan 2023 06:39:13 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id u9so83231676ejo.0 for ; Wed, 04 Jan 2023 06:39:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=7ktTgqCg5vZndbEsq2NE84RTVG7aeSaApbDApUiy3yI=; b=bAo5rEoMeLXb+zWJpWccSUbC/52Xl5JUcRb7B7ldPjmJu8yrGJebcgfu2mvn6DoQOH DJpreAUPSRM8Os5s1oTyh3CCfi6WZSJnNqxdwx043PELATrAMnUMkGjBMipqFxsD6I2u shiCmP+MHLcOSwobb1InBZKdfL043vctCbYng= 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=7ktTgqCg5vZndbEsq2NE84RTVG7aeSaApbDApUiy3yI=; b=MLffjluwUk3Ck+G/f+H6hoitObbbpItp1i3IoWbjSCpyFsORH4TIKPddfywTNSwyhc uRzGMl+9LACJ2ict6bTx/liURAoq5/XmvVW6/fPQOlmxBGrgATuLFgmc1NNYkol1WYct 7BaLkrWeQ//yY/8fnUnF1ZXGVTRGzMUxo9LWMsLxLk/O5rs0uoPrA+/nQviJBkZfZcoC gM+RTzBnDnnCXBNHmF3/dzt/KnKjnq0OzBAcFhXLC5w+m9zGSay2Yt7ryNXjqnsPyr9P d0eITIdTIMReIrBS4y9D2l8ri5ZPGo9VSCJogAKzeCgwVxPtIbOwHEXNbr2aqzWOzqJ7 7AdA== X-Gm-Message-State: AFqh2kqjv2mHaXujweNG8iUX1Pi4h12wlGpoGEPmAVPlv5aKZU+YwqyR joQ4/iTluyY0DmZzWg74uknIJg== X-Received: by 2002:a17:906:b150:b0:7c1:2931:2263 with SMTP id bt16-20020a170906b15000b007c129312263mr43585109ejb.71.1672843151848; Wed, 04 Jan 2023 06:39:11 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:a438:c7da:62e0:36f4]) by smtp.gmail.com with ESMTPSA id c8-20020a170906924800b0078de26f66b9sm15386659ejx.114.2023.01.04.06.39.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 06:39:11 -0800 (PST) From: Ricardo Ribalda Date: Wed, 04 Jan 2023 15:38:48 +0100 Subject: [PATCH v6 3/3] kexec: Introduce sysctl parameters kexec_load_limit_* MIME-Version: 1.0 Message-Id: <20221114-disable-kexec-reset-v6-3-6a8531a09b9a@chromium.org> References: <20221114-disable-kexec-reset-v6-0-6a8531a09b9a@chromium.org> In-Reply-To: <20221114-disable-kexec-reset-v6-0-6a8531a09b9a@chromium.org> To: Philipp Rudo , Eric Biederman , "Guilherme G. Piccoli" , Jonathan Corbet Cc: Ricardo Ribalda , linux-doc@vger.kernel.org, Sergey Senozhatsky , "Joel Fernandes (Google)" , Baoquan He , Petr Tesarik , kexec@lists.infradead.org, Bagas Sanjaya , Steven Rostedt , linux-kernel@vger.kernel.org, Ross Zwisler X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=7913; i=ribalda@chromium.org; h=from:subject:message-id; bh=pwr4lQSQU6e2iagP33ihhaoD9RG5CubbrBaEaThEAKM=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjtY+HjBoWaxGoO7sxgdVTlJcthgWB365UeesT8qSd hvqseBiJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY7WPhwAKCRDRN9E+zzrEiAunD/ 91AfbnoUWa9e8aD0UKHg+GAqqRrXozPx01fMTG3wC2iUZxj/n2uMz/Y8QbTHYctYbTfVMTpx/jHg2K cbSS6gGr5ybyMAggEcwWMSPfYWS/rVzPFf6T8G0NpDwWEnbQ4QjHDaULMlPg5AXL5uReOCp0qh/CjQ k2MK/1noz9a6dzcMqHd25iw6UGm2HWY4VXSD7on2U1hzxCAixuddN5gPd8lwBxwpueWdRaq3EIX+BI 0ECi9pmjTjN7BwiLeVDOPm8xI9hmn3SKhv/onx0MyBdYds4qYDZOgCxUWI/2/d+qa2V14UkKigfeQR g3c3YrWsOeWJTcCKad5PaGmNHk110c3wU8EZ5hCWcUXAMWyJbWXDh7GAOF6m8AVPtSsT2b++X9JQJw UUCys+nCBZmTEDOHNkS7ghuK3Q3YsjemCdfKa1LjHE1YSC18fK737LAKLRi3qv+vfFAQUX9HWBxWy7 u2hkB6tkUVgrTIwmEC9BzneUHH6HUJIffKaBjcCpSklvHyU0VFnXEkMbJFIy8JkDT31zzdfVe0jilF yyWg2218E4cEthc8vrS0HQuGe/Rl5rCO/l2Z7k4ZB//JKMuQX9c7W4RoBIMSEp0xHdOJwxtHOSflS/ xpS7m2cyXFO00X1x4m7hB6Mqmfn60Bhin0EGNy91xeKIdJLNMd5B15HPhzpA== 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?1754103354811322920?= X-GMAIL-MSGID: =?utf-8?q?1754103354811322920?= kexec allows replacing the current kernel with a different one. This is usually a source of concerns for sysadmins that want to harden a system. Linux already provides a way to disable loading new kexec kernel via kexec_load_disabled, but that control is very coard, it is all or nothing and does not make distinction between a panic kexec and a normal kexec. This patch introduces new sysctl parameters, with finner tunning 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 stricter value. With these new parameters on place, a system with loadpin and verity enabled, using the following kernel parameters: sysctl.kexec_load_limit_reboot=0 sysct.kexec_load_limit_panic=1 can have a good warranty that if initrd tries to load a panic kernel, a malitious user will have small chances to replace that kernel with a different one, even if they can trigger timeouts on the disk where the panic kernel lives. Reviewed-by: Steven Rostedt (Google) Signed-off-by: Ricardo Ribalda --- Documentation/admin-guide/sysctl/kernel.rst | 18 ++++++ include/linux/kexec.h | 2 +- kernel/kexec.c | 4 +- kernel/kexec_core.c | 87 ++++++++++++++++++++++++++++- kernel/kexec_file.c | 11 ++-- 5 files changed, 114 insertions(+), 8 deletions(-) diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst index 97394bd9d065..d5fb4b6ef405 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 normal +image. kptr_restrict ============= diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 182e0c11b87b..791e65829f86 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -407,7 +407,7 @@ extern int kimage_crash_copy_vmcoreinfo(struct kimage *image); extern struct kimage *kexec_image; extern struct kimage *kexec_crash_image; -bool kexec_load_permitted(void); +bool kexec_load_permitted(int kexec_image_type); #ifndef kexec_flush_icache_page #define kexec_flush_icache_page(page) diff --git a/kernel/kexec.c b/kernel/kexec.c index ce1bca874a8d..92d301f98776 100644 --- a/kernel/kexec.c +++ b/kernel/kexec.c @@ -190,10 +190,12 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments, static inline int kexec_load_check(unsigned long nr_segments, unsigned long flags) { + int image_type = (flags & KEXEC_ON_CRASH) ? + KEXEC_TYPE_CRASH : KEXEC_TYPE_DEFAULT; int result; /* We only trust the superuser with rebooting the system. */ - if (!kexec_load_permitted()) + if (!kexec_load_permitted(image_type)) return -EPERM; /* Permit LSMs and IMA to fail the kexec */ diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index a1efc70f4158..951541d78ca8 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -926,10 +926,64 @@ int kimage_load_segment(struct kimage *image, return result; } +struct kexec_load_limit { + /* Mutex protects the limit count. */ + struct mutex mutex; + int limit; +}; + +static struct kexec_load_limit load_limit_reboot = { + .mutex = __MUTEX_INITIALIZER(load_limit_reboot.mutex), + .limit = -1, +}; + +static struct kexec_load_limit load_limit_panic = { + .mutex = __MUTEX_INITIALIZER(load_limit_panic.mutex), + .limit = -1, +}; + struct kimage *kexec_image; struct kimage *kexec_crash_image; static int kexec_load_disabled; + #ifdef CONFIG_SYSCTL +static int kexec_limit_handler(struct ctl_table *table, int write, + void *buffer, size_t *lenp, loff_t *ppos) +{ + struct kexec_load_limit *limit = table->data; + int val; + struct ctl_table tmp = { + .data = &val, + .maxlen = sizeof(val), + .mode = table->mode, + }; + int ret; + + if (write) { + ret = proc_dointvec(&tmp, write, buffer, lenp, ppos); + if (ret) + return ret; + + if (val < 0) + return -EINVAL; + + mutex_lock(&limit->mutex); + if (limit->limit != -1 && val >= limit->limit) + ret = -EINVAL; + else + limit->limit = val; + mutex_unlock(&limit->mutex); + + return ret; + } + + mutex_lock(&limit->mutex); + val = limit->limit; + mutex_unlock(&limit->mutex); + + return proc_dointvec(&tmp, write, buffer, lenp, ppos); +} + static struct ctl_table kexec_core_sysctls[] = { { .procname = "kexec_load_disabled", @@ -941,6 +995,18 @@ static struct ctl_table kexec_core_sysctls[] = { .extra1 = SYSCTL_ONE, .extra2 = SYSCTL_ONE, }, + { + .procname = "kexec_load_limit_panic", + .data = &load_limit_panic, + .mode = 0644, + .proc_handler = kexec_limit_handler, + }, + { + .procname = "kexec_load_limit_reboot", + .data = &load_limit_reboot, + .mode = 0644, + .proc_handler = kexec_limit_handler, + }, { } }; @@ -952,13 +1018,30 @@ static int __init kexec_core_sysctl_init(void) late_initcall(kexec_core_sysctl_init); #endif -bool kexec_load_permitted(void) +bool kexec_load_permitted(int kexec_image_type) { + struct kexec_load_limit *limit; + /* * Only the superuser can use the kexec syscall and if it has not * been disabled. */ - return capable(CAP_SYS_BOOT) && !kexec_load_disabled; + if (!capable(CAP_SYS_BOOT) || kexec_load_disabled) + return false; + + /* Check limit counter and decrease it.*/ + limit = (kexec_image_type == KEXEC_TYPE_CRASH) ? + &load_limit_panic : &load_limit_reboot; + mutex_lock(&limit->mutex); + if (!limit->limit) { + mutex_unlock(&limit->mutex); + return false; + } + if (limit->limit != -1) + limit->limit--; + mutex_unlock(&limit->mutex); + + return true; } /* diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 29efa43ea951..70e1e99038ee 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(image_type)) 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)