// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (C) 2017 Joe Lawrence <joe.lawrence@redhat.com>
*/
/* * livepatch-shadow-mod.c - Shadow variables, buggy module demo * * Purpose * ------- * * As a demonstration of livepatch shadow variable API, this module * introduces memory leak behavior that livepatch modules * livepatch-shadow-fix1.ko and livepatch-shadow-fix2.ko correct and * enhance. * * WARNING - even though the livepatch-shadow-fix modules patch the * memory leak, please load these modules at your own risk -- some * amount of memory may leaked before the bug is patched. * * * Usage * ----- * * Step 1 - Load the buggy demonstration module: * * insmod samples/livepatch/livepatch-shadow-mod.ko * * Watch dmesg output for a few moments to see new dummy being allocated * and a periodic cleanup check. (Note: a small amount of memory is * being leaked.) * * * Step 2 - Load livepatch fix1: * * insmod samples/livepatch/livepatch-shadow-fix1.ko * * Continue watching dmesg and note that now livepatch_fix1_dummy_free() * and livepatch_fix1_dummy_alloc() are logging messages about leaked * memory and eventually leaks prevented. * * * Step 3 - Load livepatch fix2 (on top of fix1): * * insmod samples/livepatch/livepatch-shadow-fix2.ko * * This module extends functionality through shadow variables, as a new * "check" counter is added to the dummy structure. Periodic dmesg * messages will log these as dummies are cleaned up. * * * Step 4 - Cleanup * * Unwind the demonstration by disabling the livepatch fix modules, then * removing them and the demo module: * * echo 0 > /sys/kernel/livepatch/livepatch_shadow_fix2/enabled * echo 0 > /sys/kernel/livepatch/livepatch_shadow_fix1/enabled * rmmod livepatch-shadow-fix2 * rmmod livepatch-shadow-fix1 * rmmod livepatch-shadow-mod
*/
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Joe Lawrence ");
MODULE_DESCRIPTION("Buggy module for shadow variable demo");
/* Allocate new dummies every second */ #define ALLOC_PERIOD 1 /* Check for expired dummies after a few new ones have been allocated */ #define CLEANUP_PERIOD (3 * ALLOC_PERIOD) /* Dummies expire after a few cleanup instances */ #define EXPIRE_PERIOD (4 * CLEANUP_PERIOD)
/* * Keep a list of all the dummies so we can clean up any residual ones * on module exit
*/ static LIST_HEAD(dummy_list); static DEFINE_MUTEX(dummy_list_mutex);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.