mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 14:53:58 -04:00
Pull non-MM updates from Andrew Morton:
- "panic: sys_info: Refactor and fix a potential issue" (Andy Shevchenko)
fixes a build issue and does some cleanup in ib/sys_info.c
- "Implement mul_u64_u64_div_u64_roundup()" (David Laight)
enhances the 64-bit math code on behalf of a PWM driver and beefs up
the test module for these library functions
- "scripts/gdb/symbols: make BPF debug info available to GDB" (Ilya Leoshkevich)
makes BPF symbol names, sizes, and line numbers available to the GDB
debugger
- "Enable hung_task and lockup cases to dump system info on demand" (Feng Tang)
adds a sysctl which can be used to cause additional info dumping when
the hung-task and lockup detectors fire
- "lib/base64: add generic encoder/decoder, migrate users" (Kuan-Wei Chiu)
adds a general base64 encoder/decoder to lib/ and migrates several
users away from their private implementations
- "rbree: inline rb_first() and rb_last()" (Eric Dumazet)
makes TCP a little faster
- "liveupdate: Rework KHO for in-kernel users" (Pasha Tatashin)
reworks the KEXEC Handover interfaces in preparation for Live Update
Orchestrator (LUO), and possibly for other future clients
- "kho: simplify state machine and enable dynamic updates" (Pasha Tatashin)
increases the flexibility of KEXEC Handover. Also preparation for LUO
- "Live Update Orchestrator" (Pasha Tatashin)
is a major new feature targeted at cloud environments. Quoting the
cover letter:
This series introduces the Live Update Orchestrator, a kernel
subsystem designed to facilitate live kernel updates using a
kexec-based reboot. This capability is critical for cloud
environments, allowing hypervisors to be updated with minimal
downtime for running virtual machines. LUO achieves this by
preserving the state of selected resources, such as memory,
devices and their dependencies, across the kernel transition.
As a key feature, this series includes support for preserving
memfd file descriptors, which allows critical in-memory data, such
as guest RAM or any other large memory region, to be maintained in
RAM across the kexec reboot.
Mike Rappaport merits a mention here, for his extensive review and
testing work.
- "kexec: reorganize kexec and kdump sysfs" (Sourabh Jain)
moves the kexec and kdump sysfs entries from /sys/kernel/ to
/sys/kernel/kexec/ and adds back-compatibility symlinks which can
hopefully be removed one day
- "kho: fixes for vmalloc restoration" (Mike Rapoport)
fixes a BUG which was being hit during KHO restoration of vmalloc()
regions
* tag 'mm-nonmm-stable-2025-12-06-11-14' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: (139 commits)
calibrate: update header inclusion
Reinstate "resource: avoid unnecessary lookups in find_next_iomem_res()"
vmcoreinfo: track and log recoverable hardware errors
kho: fix restoring of contiguous ranges of order-0 pages
kho: kho_restore_vmalloc: fix initialization of pages array
MAINTAINERS: TPM DEVICE DRIVER: update the W-tag
init: replace simple_strtoul with kstrtoul to improve lpj_setup
KHO: fix boot failure due to kmemleak access to non-PRESENT pages
Documentation/ABI: new kexec and kdump sysfs interface
Documentation/ABI: mark old kexec sysfs deprecated
kexec: move sysfs entries to /sys/kernel/kexec
test_kho: always print restore status
kho: free chunks using free_page() instead of kfree()
selftests/liveupdate: add kexec test for multiple and empty sessions
selftests/liveupdate: add simple kexec-based selftest for LUO
selftests/liveupdate: add userspace API selftests
docs: add documentation for memfd preservation via LUO
mm: memfd_luo: allow preserving memfd
liveupdate: luo_file: add private argument to store runtime state
mm: shmem: export some functions to internal.h
...
277 lines
6.6 KiB
C
277 lines
6.6 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#include <linux/limits.h>
|
|
#include <signal.h>
|
|
|
|
#include "kselftest.h"
|
|
#include "cgroup_util.h"
|
|
|
|
static int idle_process_fn(const char *cgroup, void *arg)
|
|
{
|
|
(void)pause();
|
|
return 0;
|
|
}
|
|
|
|
static int do_migration_fn(const char *cgroup, void *arg)
|
|
{
|
|
int object_pid = (int)(size_t)arg;
|
|
|
|
if (setuid(TEST_UID))
|
|
return EXIT_FAILURE;
|
|
|
|
// XXX checking /proc/$pid/cgroup would be quicker than wait
|
|
if (cg_enter(cgroup, object_pid) ||
|
|
cg_wait_for_proc_count(cgroup, 1))
|
|
return EXIT_FAILURE;
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|
|
static int do_controller_fn(const char *cgroup, void *arg)
|
|
{
|
|
const char *child = cgroup;
|
|
const char *parent = arg;
|
|
|
|
if (setuid(TEST_UID))
|
|
return EXIT_FAILURE;
|
|
|
|
if (!cg_read_strstr(child, "cgroup.controllers", "cpuset"))
|
|
return EXIT_FAILURE;
|
|
|
|
if (cg_write(parent, "cgroup.subtree_control", "+cpuset"))
|
|
return EXIT_FAILURE;
|
|
|
|
if (cg_read_strstr(child, "cgroup.controllers", "cpuset"))
|
|
return EXIT_FAILURE;
|
|
|
|
if (cg_write(parent, "cgroup.subtree_control", "-cpuset"))
|
|
return EXIT_FAILURE;
|
|
|
|
if (!cg_read_strstr(child, "cgroup.controllers", "cpuset"))
|
|
return EXIT_FAILURE;
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|
|
/*
|
|
* Migrate a process between two sibling cgroups.
|
|
* The success should only depend on the parent cgroup permissions and not the
|
|
* migrated process itself (cpuset controller is in place because it uses
|
|
* security_task_setscheduler() in cgroup v1).
|
|
*
|
|
* Deliberately don't set cpuset.cpus in children to avoid definining migration
|
|
* permissions between two different cpusets.
|
|
*/
|
|
static int test_cpuset_perms_object(const char *root, bool allow)
|
|
{
|
|
char *parent = NULL, *child_src = NULL, *child_dst = NULL;
|
|
char *parent_procs = NULL, *child_src_procs = NULL, *child_dst_procs = NULL;
|
|
const uid_t test_euid = TEST_UID;
|
|
int object_pid = 0;
|
|
int ret = KSFT_FAIL;
|
|
|
|
parent = cg_name(root, "cpuset_test_0");
|
|
if (!parent)
|
|
goto cleanup;
|
|
parent_procs = cg_name(parent, "cgroup.procs");
|
|
if (!parent_procs)
|
|
goto cleanup;
|
|
if (cg_create(parent))
|
|
goto cleanup;
|
|
|
|
child_src = cg_name(parent, "cpuset_test_1");
|
|
if (!child_src)
|
|
goto cleanup;
|
|
child_src_procs = cg_name(child_src, "cgroup.procs");
|
|
if (!child_src_procs)
|
|
goto cleanup;
|
|
if (cg_create(child_src))
|
|
goto cleanup;
|
|
|
|
child_dst = cg_name(parent, "cpuset_test_2");
|
|
if (!child_dst)
|
|
goto cleanup;
|
|
child_dst_procs = cg_name(child_dst, "cgroup.procs");
|
|
if (!child_dst_procs)
|
|
goto cleanup;
|
|
if (cg_create(child_dst))
|
|
goto cleanup;
|
|
|
|
if (cg_write(parent, "cgroup.subtree_control", "+cpuset"))
|
|
goto cleanup;
|
|
|
|
if (cg_read_strstr(child_src, "cgroup.controllers", "cpuset") ||
|
|
cg_read_strstr(child_dst, "cgroup.controllers", "cpuset"))
|
|
goto cleanup;
|
|
|
|
/* Enable permissions along src->dst tree path */
|
|
if (chown(child_src_procs, test_euid, -1) ||
|
|
chown(child_dst_procs, test_euid, -1))
|
|
goto cleanup;
|
|
|
|
if (allow && chown(parent_procs, test_euid, -1))
|
|
goto cleanup;
|
|
|
|
/* Fork a privileged child as a test object */
|
|
object_pid = cg_run_nowait(child_src, idle_process_fn, NULL);
|
|
if (object_pid < 0)
|
|
goto cleanup;
|
|
|
|
/* Carry out migration in a child process that can drop all privileges
|
|
* (including capabilities), the main process must remain privileged for
|
|
* cleanup.
|
|
* Child process's cgroup is irrelevant but we place it into child_dst
|
|
* as hacky way to pass information about migration target to the child.
|
|
*/
|
|
if (allow ^ (cg_run(child_dst, do_migration_fn, (void *)(size_t)object_pid) == EXIT_SUCCESS))
|
|
goto cleanup;
|
|
|
|
ret = KSFT_PASS;
|
|
|
|
cleanup:
|
|
if (object_pid > 0) {
|
|
(void)kill(object_pid, SIGTERM);
|
|
(void)clone_reap(object_pid, WEXITED);
|
|
}
|
|
|
|
cg_destroy(child_dst);
|
|
free(child_dst_procs);
|
|
free(child_dst);
|
|
|
|
cg_destroy(child_src);
|
|
free(child_src_procs);
|
|
free(child_src);
|
|
|
|
cg_destroy(parent);
|
|
free(parent_procs);
|
|
free(parent);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int test_cpuset_perms_object_allow(const char *root)
|
|
{
|
|
return test_cpuset_perms_object(root, true);
|
|
}
|
|
|
|
static int test_cpuset_perms_object_deny(const char *root)
|
|
{
|
|
return test_cpuset_perms_object(root, false);
|
|
}
|
|
|
|
/*
|
|
* Migrate a process between parent and child implicitely
|
|
* Implicit migration happens when a controller is enabled/disabled.
|
|
*
|
|
*/
|
|
static int test_cpuset_perms_subtree(const char *root)
|
|
{
|
|
char *parent = NULL, *child = NULL;
|
|
char *parent_procs = NULL, *parent_subctl = NULL, *child_procs = NULL;
|
|
const uid_t test_euid = TEST_UID;
|
|
int object_pid = 0;
|
|
int ret = KSFT_FAIL;
|
|
|
|
parent = cg_name(root, "cpuset_test_0");
|
|
if (!parent)
|
|
goto cleanup;
|
|
parent_procs = cg_name(parent, "cgroup.procs");
|
|
if (!parent_procs)
|
|
goto cleanup;
|
|
parent_subctl = cg_name(parent, "cgroup.subtree_control");
|
|
if (!parent_subctl)
|
|
goto cleanup;
|
|
if (cg_create(parent))
|
|
goto cleanup;
|
|
|
|
child = cg_name(parent, "cpuset_test_1");
|
|
if (!child)
|
|
goto cleanup;
|
|
child_procs = cg_name(child, "cgroup.procs");
|
|
if (!child_procs)
|
|
goto cleanup;
|
|
if (cg_create(child))
|
|
goto cleanup;
|
|
|
|
/* Enable permissions as in a delegated subtree */
|
|
if (chown(parent_procs, test_euid, -1) ||
|
|
chown(parent_subctl, test_euid, -1) ||
|
|
chown(child_procs, test_euid, -1))
|
|
goto cleanup;
|
|
|
|
/* Put a privileged child in the subtree and modify controller state
|
|
* from an unprivileged process, the main process remains privileged
|
|
* for cleanup.
|
|
* The unprivileged child runs in subtree too to avoid parent and
|
|
* internal-node constraing violation.
|
|
*/
|
|
object_pid = cg_run_nowait(child, idle_process_fn, NULL);
|
|
if (object_pid < 0)
|
|
goto cleanup;
|
|
|
|
if (cg_run(child, do_controller_fn, parent) != EXIT_SUCCESS)
|
|
goto cleanup;
|
|
|
|
ret = KSFT_PASS;
|
|
|
|
cleanup:
|
|
if (object_pid > 0) {
|
|
(void)kill(object_pid, SIGTERM);
|
|
(void)clone_reap(object_pid, WEXITED);
|
|
}
|
|
|
|
cg_destroy(child);
|
|
free(child_procs);
|
|
free(child);
|
|
|
|
cg_destroy(parent);
|
|
free(parent_subctl);
|
|
free(parent_procs);
|
|
free(parent);
|
|
|
|
return ret;
|
|
}
|
|
|
|
|
|
#define T(x) { x, #x }
|
|
struct cpuset_test {
|
|
int (*fn)(const char *root);
|
|
const char *name;
|
|
} tests[] = {
|
|
T(test_cpuset_perms_object_allow),
|
|
T(test_cpuset_perms_object_deny),
|
|
T(test_cpuset_perms_subtree),
|
|
};
|
|
#undef T
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
char root[PATH_MAX];
|
|
int i;
|
|
|
|
ksft_print_header();
|
|
ksft_set_plan(ARRAY_SIZE(tests));
|
|
if (cg_find_unified_root(root, sizeof(root), NULL))
|
|
ksft_exit_skip("cgroup v2 isn't mounted\n");
|
|
|
|
if (cg_read_strstr(root, "cgroup.subtree_control", "cpuset"))
|
|
if (cg_write(root, "cgroup.subtree_control", "+cpuset"))
|
|
ksft_exit_skip("Failed to set cpuset controller\n");
|
|
|
|
for (i = 0; i < ARRAY_SIZE(tests); i++) {
|
|
switch (tests[i].fn(root)) {
|
|
case KSFT_PASS:
|
|
ksft_test_result_pass("%s\n", tests[i].name);
|
|
break;
|
|
case KSFT_SKIP:
|
|
ksft_test_result_skip("%s\n", tests[i].name);
|
|
break;
|
|
default:
|
|
ksft_test_result_fail("%s\n", tests[i].name);
|
|
break;
|
|
}
|
|
}
|
|
|
|
ksft_finished();
|
|
}
|