Kernel: Rename /sys/kernel/variables => /sys/kernel/conf

The name "variables" is a bit awkward and what the directory entries are
really about is kernel configuration so let's make it clear with the new
name.
This commit is contained in:
Liav A 2023-08-12 13:57:13 +03:00 committed by Jelle Raaijmakers
parent 3151099b21
commit 751aae77bc
24 changed files with 99 additions and 99 deletions

View file

@ -102,7 +102,7 @@ Special restrictions on filesystem also apply:
- Write access is forbidden to the `/sys/kernel/power_state` node.
- Read accesses is forbidden by default to all nodes in `/sys/kernel` directory, except for:
`df`, `interrupts`, `keymap`, `memstat`, `processes`, `stats` and `uptime`.
- Write access is forbidden to kernel variables (which are located in `/sys/kernel/variables`).
- Write access is forbidden to kernel configuration variables (which are located in `/sys/kernel/conf`).
- Open access is forbidden to all device nodes except for `/dev/full`, `/dev/null`, `/dev/zero`, `/dev/random` and various
other TTY/PTY devices (not including Kernel virtual consoles).
- Executing SUID binaries is forbidden.

View file

@ -12,7 +12,7 @@ sysctl - configure kernel parameters at runtime
sysctl is a utility for managing kernel configuration parameters at runtime.
This requires root privileges, and can crash your system.
Available parameters are listed under /sys/kernel/variables/.
Available parameters are listed under /sys/kernel/conf/.
## Options

View file

@ -202,13 +202,13 @@ set(KERNEL_SOURCES
FileSystem/SysFS/Subsystems/Kernel/Network/UDP.cpp
FileSystem/SysFS/Subsystems/Kernel/Constants/ConstantInformation.cpp
FileSystem/SysFS/Subsystems/Kernel/Constants/Directory.cpp
FileSystem/SysFS/Subsystems/Kernel/Variables/BooleanVariable.cpp
FileSystem/SysFS/Subsystems/Kernel/Variables/CapsLockRemap.cpp
FileSystem/SysFS/Subsystems/Kernel/Variables/CoredumpDirectory.cpp
FileSystem/SysFS/Subsystems/Kernel/Variables/Directory.cpp
FileSystem/SysFS/Subsystems/Kernel/Variables/DumpKmallocStack.cpp
FileSystem/SysFS/Subsystems/Kernel/Variables/StringVariable.cpp
FileSystem/SysFS/Subsystems/Kernel/Variables/UBSANDeadly.cpp
FileSystem/SysFS/Subsystems/Kernel/Configuration/BooleanVariable.cpp
FileSystem/SysFS/Subsystems/Kernel/Configuration/CapsLockRemap.cpp
FileSystem/SysFS/Subsystems/Kernel/Configuration/CoredumpDirectory.cpp
FileSystem/SysFS/Subsystems/Kernel/Configuration/Directory.cpp
FileSystem/SysFS/Subsystems/Kernel/Configuration/DumpKmallocStack.cpp
FileSystem/SysFS/Subsystems/Kernel/Configuration/StringVariable.cpp
FileSystem/SysFS/Subsystems/Kernel/Configuration/UBSANDeadly.cpp
FileSystem/VirtualFileSystem.cpp
Firmware/ACPI/Initialize.cpp
Firmware/ACPI/Parser.cpp

View file

@ -1,10 +1,10 @@
/*
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
* Copyright (c) 2022-2023, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/BooleanVariable.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Configuration/BooleanVariable.h>
#include <Kernel/Sections.h>
#include <Kernel/Tasks/Process.h>

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
* Copyright (c) 2022-2023, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

View file

@ -1,11 +1,11 @@
/*
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
* Copyright (c) 2022-2023, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/Devices/HID/Management.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/CapsLockRemap.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Configuration/CapsLockRemap.h>
#include <Kernel/Sections.h>
namespace Kernel {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
* Copyright (c) 2022-2023, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -8,7 +8,7 @@
#include <AK/RefPtr.h>
#include <AK/Types.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/BooleanVariable.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Configuration/BooleanVariable.h>
#include <Kernel/Library/UserOrKernelBuffer.h>
#include <Kernel/Locking/Spinlock.h>

View file

@ -1,10 +1,10 @@
/*
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
* Copyright (c) 2022-2023, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/CoredumpDirectory.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Configuration/CoredumpDirectory.h>
#include <Kernel/Sections.h>
#include <Kernel/Tasks/Coredump.h>

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
* Copyright (c) 2022-2023, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -8,7 +8,7 @@
#include <AK/RefPtr.h>
#include <AK/Types.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/StringVariable.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Configuration/StringVariable.h>
#include <Kernel/Library/UserOrKernelBuffer.h>
namespace Kernel {

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2022-2023, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Error.h>
#include <AK/Try.h>
#include <Kernel/FileSystem/SysFS/Component.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Configuration/CapsLockRemap.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Configuration/CoredumpDirectory.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Configuration/Directory.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Configuration/DumpKmallocStack.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Configuration/UBSANDeadly.h>
namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<SysFSKernelConfigurationDirectory> SysFSKernelConfigurationDirectory::must_create(SysFSDirectory const& parent_directory)
{
auto global_variables_directory = adopt_ref_if_nonnull(new (nothrow) SysFSKernelConfigurationDirectory(parent_directory)).release_nonnull();
MUST(global_variables_directory->m_child_components.with([&](auto& list) -> ErrorOr<void> {
list.append(SysFSCapsLockRemap::must_create(*global_variables_directory));
list.append(SysFSDumpKmallocStacks::must_create(*global_variables_directory));
list.append(SysFSUBSANDeadly::must_create(*global_variables_directory));
list.append(SysFSCoredumpDirectory::must_create(*global_variables_directory));
return {};
}));
return global_variables_directory;
}
UNMAP_AFTER_INIT SysFSKernelConfigurationDirectory::SysFSKernelConfigurationDirectory(SysFSDirectory const& parent_directory)
: SysFSDirectory(parent_directory)
{
}
}

View file

@ -0,0 +1,24 @@
/*
* Copyright (c) 2021-2023, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Types.h>
#include <Kernel/FileSystem/SysFS/Component.h>
#include <Kernel/FileSystem/SysFS/RootDirectory.h>
namespace Kernel {
class SysFSKernelConfigurationDirectory : public SysFSDirectory {
public:
static NonnullRefPtr<SysFSKernelConfigurationDirectory> must_create(SysFSDirectory const&);
virtual StringView name() const override { return "conf"sv; }
private:
explicit SysFSKernelConfigurationDirectory(SysFSDirectory const&);
};
}

View file

@ -1,10 +1,10 @@
/*
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
* Copyright (c) 2022-2023, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/DumpKmallocStack.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Configuration/DumpKmallocStack.h>
#include <Kernel/Sections.h>
#include <Kernel/Tasks/Process.h>

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
* Copyright (c) 2022-2023, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -8,7 +8,7 @@
#include <AK/RefPtr.h>
#include <AK/Types.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/BooleanVariable.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Configuration/BooleanVariable.h>
#include <Kernel/Library/UserOrKernelBuffer.h>
#include <Kernel/Locking/Spinlock.h>

View file

@ -1,10 +1,10 @@
/*
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
* Copyright (c) 2022-2023, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/StringVariable.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Configuration/StringVariable.h>
#include <Kernel/Sections.h>
#include <Kernel/Tasks/Process.h>

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
* Copyright (c) 2022-2023, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

View file

@ -1,11 +1,11 @@
/*
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
* Copyright (c) 2022-2023, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/UBSanitizer.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/UBSANDeadly.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Configuration/UBSANDeadly.h>
#include <Kernel/Sections.h>
namespace Kernel {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
* Copyright (c) 2022-2023, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -8,7 +8,7 @@
#include <AK/RefPtr.h>
#include <AK/Types.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/BooleanVariable.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Configuration/BooleanVariable.h>
#include <Kernel/Library/UserOrKernelBuffer.h>
namespace Kernel {

View file

@ -8,6 +8,7 @@
#include <AK/Try.h>
#include <Kernel/FileSystem/SysFS/Component.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/CPUInfo.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Configuration/Directory.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Constants/Directory.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Directory.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/DiskUsage.h>
@ -23,7 +24,6 @@
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Profile.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/SystemStatistics.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Uptime.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/Directory.h>
namespace Kernel {
@ -47,7 +47,7 @@ UNMAP_AFTER_INIT NonnullRefPtr<SysFSGlobalKernelStatsDirectory> SysFSGlobalKerne
list.append(SysFSJails::must_create(*global_kernel_stats_directory));
list.append(SysFSGlobalNetworkStatsDirectory::must_create(*global_kernel_stats_directory));
list.append(SysFSGlobalKernelVariablesDirectory::must_create(*global_kernel_stats_directory));
list.append(SysFSKernelConfigurationDirectory::must_create(*global_kernel_stats_directory));
return {};
}));
return global_kernel_stats_directory;

View file

@ -1,36 +0,0 @@
/*
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Error.h>
#include <AK/Try.h>
#include <Kernel/FileSystem/SysFS/Component.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/CapsLockRemap.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/CoredumpDirectory.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/Directory.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/DumpKmallocStack.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Variables/UBSANDeadly.h>
namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<SysFSGlobalKernelVariablesDirectory> SysFSGlobalKernelVariablesDirectory::must_create(SysFSDirectory const& parent_directory)
{
auto global_variables_directory = adopt_ref_if_nonnull(new (nothrow) SysFSGlobalKernelVariablesDirectory(parent_directory)).release_nonnull();
MUST(global_variables_directory->m_child_components.with([&](auto& list) -> ErrorOr<void> {
list.append(SysFSCapsLockRemap::must_create(*global_variables_directory));
list.append(SysFSDumpKmallocStacks::must_create(*global_variables_directory));
list.append(SysFSUBSANDeadly::must_create(*global_variables_directory));
list.append(SysFSCoredumpDirectory::must_create(*global_variables_directory));
return {};
}));
return global_variables_directory;
}
UNMAP_AFTER_INIT SysFSGlobalKernelVariablesDirectory::SysFSGlobalKernelVariablesDirectory(SysFSDirectory const& parent_directory)
: SysFSDirectory(parent_directory)
{
}
}

View file

@ -1,24 +0,0 @@
/*
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Types.h>
#include <Kernel/FileSystem/SysFS/Component.h>
#include <Kernel/FileSystem/SysFS/RootDirectory.h>
namespace Kernel {
class SysFSGlobalKernelVariablesDirectory : public SysFSDirectory {
public:
static NonnullRefPtr<SysFSGlobalKernelVariablesDirectory> must_create(SysFSDirectory const&);
virtual StringView name() const override { return "variables"sv; }
private:
explicit SysFSGlobalKernelVariablesDirectory(SysFSDirectory const&);
};
}

View file

@ -322,7 +322,7 @@ void KeyboardSettingsWidget::write_caps_lock_to_ctrl_sys_variable(bool caps_lock
ErrorOr<bool> KeyboardSettingsWidget::read_caps_lock_to_ctrl_sys_variable()
{
auto file = TRY(Core::File::open("/sys/kernel/variables/caps_lock_to_ctrl"sv, Core::File::OpenMode::Read));
auto file = TRY(Core::File::open("/sys/kernel/conf/caps_lock_to_ctrl"sv, Core::File::OpenMode::Read));
auto buffer = TRY(file->read_until_eof());
StringView contents_string((char const*)buffer.data(), min(1, buffer.size()));
return contents_string == "1";

View file

@ -29,7 +29,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Core::System::unveil("/bin/keymap", "x"));
TRY(Core::System::unveil("/bin/sysctl", "x"));
TRY(Core::System::unveil("/sys/kernel/keymap", "r"));
TRY(Core::System::unveil("/sys/kernel/variables/caps_lock_to_ctrl", "r"));
TRY(Core::System::unveil("/sys/kernel/conf/caps_lock_to_ctrl", "r"));
TRY(Core::System::unveil("/etc/Keyboard.ini", "r"));
TRY(Core::System::unveil(nullptr, nullptr));

View file

@ -501,7 +501,7 @@ static ErrorOr<void> create_tmp_coredump_directory()
static ErrorOr<void> set_default_coredump_directory()
{
dbgln("Setting /tmp/coredump as the coredump directory");
auto sysfs_coredump_directory_variable_fd = TRY(Core::System::open("/sys/kernel/variables/coredump_directory"sv, O_RDWR));
auto sysfs_coredump_directory_variable_fd = TRY(Core::System::open("/sys/kernel/conf/coredump_directory"sv, O_RDWR));
ScopeGuard close_on_exit([&] {
close(sysfs_coredump_directory_variable_fd);
});

View file

@ -14,7 +14,7 @@ static bool s_set_variable = false;
static DeprecatedString get_variable(StringView name)
{
auto path = DeprecatedString::formatted("/sys/kernel/variables/{}", name);
auto path = DeprecatedString::formatted("/sys/kernel/conf/{}", name);
auto file = Core::File::open(path, Core::File::OpenMode::Read);
if (file.is_error()) {
warnln("Failed to open {}: {}", path, file.error());
@ -42,7 +42,7 @@ static bool write_variable(StringView name, StringView value)
auto old_value = get_variable(name);
if (old_value.is_null())
return false;
auto path = DeprecatedString::formatted("/sys/kernel/variables/{}", name);
auto path = DeprecatedString::formatted("/sys/kernel/conf/{}", name);
auto file = Core::File::open(path, Core::File::OpenMode::Write);
if (file.is_error()) {
warnln("Failed to open {}: {}", path, file.error());
@ -80,7 +80,7 @@ static int handle_variables(Vector<StringView> const& variables)
static int handle_show_all()
{
Core::DirIterator di("/sys/kernel/variables", Core::DirIterator::SkipDots);
Core::DirIterator di("/sys/kernel/conf", Core::DirIterator::SkipDots);
if (di.has_error()) {
outln("DirIterator: {}", di.error());
return 1;