Received: by 2002:a05:622a:1442:b0:3a5:28ea:c4b9 with SMTP id v2csp746497qtx; Thu, 17 Nov 2022 07:24:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf4FNLxyIH/L1/bAwwQNEfbd5ctNZ5gqGhFh2gNt5tVlCTJXgze1iEWAV7XvpxqTSNEhbOac X-Received: by 2002:a17:90a:710b:b0:218:725:c820 with SMTP id h11-20020a17090a710b00b002180725c820mr3302417pjk.170.1668698669207; Thu, 17 Nov 2022 07:24:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668698669; cv=none; d=google.com; s=arc-20160816; b=E3lS/Ptn5kEm6F660suwYpxqqohr4HM41CwTtYA1owEqShTSN/pDVN/vqCSJDW85nm nQHc9SJzqzZ9vnvlp3gfIHtcxKPM9fSVGq0944ytTFGgA/f+aybMCCeUGxJ0MxBYVzck KNPmi1W31ZiBzUcDvQZFWORsCiXEA+23Gj0ueyZ4GbWTRz+cd8GXx4HTjze3ZLnV3sFG 8V+QPiV1SZkUfc35Sd4/CKirfrFmiUP7D9rBoC+2RNo0vaz1GP9dr8TyfMUGpuGlPkPp CtiUtpLejnuopuKAJuu6QTIcFw58kox2ukKOQLPRpPMspGjaTrnGn4V8y4miFbVy3jYa aJiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=0mda3tRJT+iEZZZtBKUMBVJCht+1W2dmNcWwzB9SAAk=; b=cdCN7K25JP4MqtG1QJ7vI5ILbQgBENYMvPGDa8mjgbhtM585an5k/vsJFkXPyqMsW9 YPiWHQU8iEAhhHdNnSFP6twl/Ow29keScRabEnlHgDhbxO9P14NzpyqNI83i5FKtce7D WaPgqXhyquWGBUk1gsDKY01LdP0OM2BB/BeMjmePMN8m8AEJg1DcnVQm1cgn1gXekeRX uImN9i0wvBsb0bZzeF/4lS7R0kUlcRzufI45AgEgDCm3B193JVAcDAeVW+CyLcCBaBKa kodHJh+xg6S+1R9F/k61UsPz2dRapp5RZ8k0+n47a7SdKMHbyt2nKSu9yWYW0FYxuTVj A44g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=enDxqfxX; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s4-20020a170903214400b0016dcf421fe9si1011587ple.486.2022.11.17.07.24.16; Thu, 17 Nov 2022 07:24:29 -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=enDxqfxX; 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 S240624AbiKQPVB (ORCPT + 92 others); Thu, 17 Nov 2022 10:21:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240107AbiKQPUK (ORCPT ); Thu, 17 Nov 2022 10:20:10 -0500 Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66F66781AA for ; Thu, 17 Nov 2022 07:15:21 -0800 (PST) Received: by mail-il1-x129.google.com with SMTP id i5so1030376ilc.12 for ; Thu, 17 Nov 2022 07:15:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=0mda3tRJT+iEZZZtBKUMBVJCht+1W2dmNcWwzB9SAAk=; b=enDxqfxXT+UPRRkUoQ0pVpD4o1W5OZKMjO8TbYuZUg/EpmK5WvwM+tyhjnAfthIuWA P1j//kNZxtlDxkx1Ioxdba0X6zL6huywLOEp9wSSg0WWthpiEWIZElc0JsinjKRrMbeo hdAvB7d/tZJAv25MpanKHPy42mT2MjorJ44DA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0mda3tRJT+iEZZZtBKUMBVJCht+1W2dmNcWwzB9SAAk=; b=kZghLsOkQFxuk1ElCsmwsJ7ZKtj3z1C7SlCyOj9iz4mSjU3XmMB3e5Vb5Dx7O2YDKJ 2MuUG5lH8PrMmAWAZVfAOBBb1uHjAgoFVXKLcQoQDIldYP4ibO9WBRlNALtwx25R/7of PNJ6wcbl8NpaSq2tht5i7U2Y5jkdRxVt/22fFYGvEMlInLgO6NAOg8AiAKUTOV0/UBiZ DXIfKLqDARCT9A1MmECDv8PRZnPggvxRfhAlb6dUdVI8C6vkHAethLdw9A0bzn8iVbAD ncitV27KgNFdqaqipAn4yVEMP3thUXaL61eC4Q4F9IEZMO8aoKEV6g9cuwlk467rrvpC xjPA== X-Gm-Message-State: ANoB5pku1nYJgQCjySDCXv5vjF4SYKkjzGYZ4tzOGkaCLObYAvPWJf/v QKjp02I4rEHq0eaGt9lnnzKOR6aHgR5KUw== X-Received: by 2002:a92:d03:0:b0:302:988e:4ea7 with SMTP id 3-20020a920d03000000b00302988e4ea7mr1349452iln.224.1668698120555; Thu, 17 Nov 2022 07:15:20 -0800 (PST) Received: from mail-io1-f46.google.com (mail-io1-f46.google.com. [209.85.166.46]) by smtp.gmail.com with ESMTPSA id o7-20020a056e02092700b003027f923d29sm417215ilt.39.2022.11.17.07.15.18 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Nov 2022 07:15:19 -0800 (PST) Received: by mail-io1-f46.google.com with SMTP id q21so1570404iod.4 for ; Thu, 17 Nov 2022 07:15:18 -0800 (PST) X-Received: by 2002:a02:c897:0:b0:374:100a:b0c7 with SMTP id m23-20020a02c897000000b00374100ab0c7mr1243939jao.185.1668698118410; Thu, 17 Nov 2022 07:15:18 -0800 (PST) MIME-Version: 1.0 References: <20221114-disable-kexec-reset-v1-0-fb51d20cf871@chromium.org> <20221114-disable-kexec-reset-v1-2-fb51d20cf871@chromium.org> <20221117160650.16e06b37@rotkaeppchen> In-Reply-To: <20221117160650.16e06b37@rotkaeppchen> From: Ricardo Ribalda Date: Thu, 17 Nov 2022 16:15:07 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v1 2/2] kexec: Introduce kexec_reboot_disabled To: Philipp Rudo Cc: Eric Biederman , Jonathan Corbet , Sergey Senozhatsky , linux-kernel@vger.kernel.org, kexec@lists.infradead.org, Ross Zwisler , linux-doc@vger.kernel.org, "Joel Fernandes (Google)" , Steven Rostedt Content-Type: text/plain; charset="UTF-8" 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 Hi Philipp Thanks for your review! On Thu, 17 Nov 2022 at 16:07, Philipp Rudo wrote: > > Hi Ricardo, > > all in all I think this patch makes sense. However, there is one point > I don't like... > > On Mon, 14 Nov 2022 14:18:39 +0100 > Ricardo Ribalda wrote: > > > Create a new toogle that disables LINUX_REBOOT_CMD_KEXEC, reducing the > > attack surface to a system. > > > > Without this toogle, an attacker can only reboot into a different kernel > > if they can create a panic(). > > > > Signed-off-by: Ricardo Ribalda > > > > diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst > > index 97394bd9d065..25d019682d33 100644 > > --- a/Documentation/admin-guide/sysctl/kernel.rst > > +++ b/Documentation/admin-guide/sysctl/kernel.rst > > @@ -462,6 +462,17 @@ altered. > > Generally used together with the `modules_disabled`_ sysctl. > > > > > > +kexec_reboot_disabled > > +===================== > > + > > +A toggle indicating if ``LINUX_REBOOT_CMD_KEXEC`` has been disabled. > > +This value defaults to 0 (false: ``LINUX_REBOOT_CMD_KEXEC`` enabled), > > +but can be set to 1 (true: ``LINUX_REBOOT_CMD_KEXEC`` disabled). > > +Once true, kexec can no longer be used for reboot and the toggle > > +cannot be set back to false. > > +This toggle does not affect the use of kexec during a crash. > > + > > + > > kptr_restrict > > ============= > > > > diff --git a/include/linux/kexec.h b/include/linux/kexec.h > > index 41a686996aaa..15c3fad8918b 100644 > > --- a/include/linux/kexec.h > > +++ b/include/linux/kexec.h > > @@ -407,6 +407,7 @@ 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; > > +extern int kexec_reboot_disabled; > > > > #ifndef kexec_flush_icache_page > > #define kexec_flush_icache_page(page) > > diff --git a/kernel/kexec.c b/kernel/kexec.c > > index cb8e6e6f983c..43063f803d81 100644 > > --- a/kernel/kexec.c > > +++ b/kernel/kexec.c > > @@ -196,6 +196,10 @@ static inline int kexec_load_check(unsigned long nr_segments, > > if (!capable(CAP_SYS_BOOT) || kexec_load_disabled) > > return -EPERM; > > > > + /* Check if the system admin has disabled kexec reboot. */ > > + if (!(flags & KEXEC_ON_CRASH) && kexec_reboot_disabled) > > + return -EPERM; > > ... Allowing to load a crashkernel doesn't make sense in my opinion. If > an attacker is capable of creating a malicious kernel, planting it on > the victims system and then find a way to boot it via kexec this > attacker also knows how to load the malicious kernel as crashkernel and > trigger a panic. So you haven't really gained anything. That's why I > would simply drop this hunk (and the corresponding one from > kexec_file_load) and let users who worry about this use a combination of > kexec_load_disabled and kexec_reboot_disabled. If for whatever reason your sysadmin configured kexec_reboot_disabed it can be nice that when a user try to load it they get a warning. It is easier to debug than waiting two steps later when they run kexec -e.... That is why I added it. But i am also ok removing it > > Thanks > Philipp > > > + > > /* Permit LSMs and IMA to fail the kexec */ > > result = security_kernel_load_data(LOADING_KEXEC_IMAGE, false); > > if (result < 0) > > diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c > > index ca2743f9c634..fe82e2525705 100644 > > --- a/kernel/kexec_core.c > > +++ b/kernel/kexec_core.c > > @@ -929,6 +929,7 @@ int kimage_load_segment(struct kimage *image, > > struct kimage *kexec_image; > > struct kimage *kexec_crash_image; > > int kexec_load_disabled; > > +int kexec_reboot_disabled; > > #ifdef CONFIG_SYSCTL > > static struct ctl_table kexec_core_sysctls[] = { > > { > > @@ -941,6 +942,16 @@ static struct ctl_table kexec_core_sysctls[] = { > > .extra1 = SYSCTL_ONE, > > .extra2 = SYSCTL_ONE, > > }, > > + { > > + .procname = "kexec_reboot_disabled", > > + .data = &kexec_reboot_disabled, > > + .maxlen = sizeof(int), > > + .mode = 0644, > > + /* only handle a transition from default "0" to "1" */ > > + .proc_handler = proc_dointvec_minmax, > > + .extra1 = SYSCTL_ONE, > > + .extra2 = SYSCTL_ONE, > > + }, > > { } > > }; > > > > @@ -1138,7 +1149,7 @@ int kernel_kexec(void) > > > > if (!kexec_trylock()) > > return -EBUSY; > > - if (!kexec_image) { > > + if (!kexec_image || kexec_reboot_disabled) { > > error = -EINVAL; > > goto Unlock; > > } > > diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c > > index 45637511e0de..583fba6de5cb 100644 > > --- a/kernel/kexec_file.c > > +++ b/kernel/kexec_file.c > > @@ -333,6 +333,11 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd, > > if (!capable(CAP_SYS_BOOT) || kexec_load_disabled) > > return -EPERM; > > > > + /* Check if the system admin has disabled kexec reboot. */ > > + if (!(flags & (KEXEC_FILE_ON_CRASH | KEXEC_FILE_UNLOAD)) > > + && kexec_reboot_disabled) > > + return -EPERM; > > + > > /* Make sure we have a legal set of flags */ > > if (flags != (flags & KEXEC_FILE_FLAGS)) > > return -EINVAL; > > > -- Ricardo Ribalda