@@ -8,6 +8,8 @@ MOD_LIVEPATCH1=test_klp_livepatch
88MOD_LIVEPATCH2=test_klp_syscall
99MOD_LIVEPATCH3=test_klp_callbacks_demo
1010MOD_REPLACE=test_klp_atomic_replace
11+ MOD_TARGET=test_klp_mod_target
12+ MOD_TARGET_PATCH=test_klp_mod_patch
1113
1214setup_config
1315
@@ -196,4 +198,102 @@ livepatch: '$MOD_REPLACE': unpatching complete
196198% rmmod $MOD_REPLACE "
197199
198200
201+ # - load a target module that provides /proc/test_klp_mod_target with
202+ # original output
203+ # - load a livepatch that patches the target module's show function
204+ # - verify the proc entry returns livepatched output
205+ # - disable and unload the livepatch
206+ # - verify the proc entry returns original output again
207+ # - unload the target module
208+
209+ start_test " module function patching"
210+
211+ load_mod $MOD_TARGET
212+
213+ if [[ " $( cat /proc/$MOD_TARGET ) " != " $MOD_TARGET : original output" ]] ; then
214+ echo -e " FAIL\n\n"
215+ die " livepatch kselftest(s) failed"
216+ fi
217+
218+ load_lp $MOD_TARGET_PATCH
219+
220+ if [[ " $( cat /proc/$MOD_TARGET ) " != " $MOD_TARGET_PATCH : this has been live patched" ]] ; then
221+ echo -e " FAIL\n\n"
222+ die " livepatch kselftest(s) failed"
223+ fi
224+
225+ disable_lp $MOD_TARGET_PATCH
226+ unload_lp $MOD_TARGET_PATCH
227+
228+ if [[ " $( cat /proc/$MOD_TARGET ) " != " $MOD_TARGET : original output" ]] ; then
229+ echo -e " FAIL\n\n"
230+ die " livepatch kselftest(s) failed"
231+ fi
232+
233+ unload_mod $MOD_TARGET
234+
235+ check_result " % insmod test_modules/$MOD_TARGET .ko
236+ $MOD_TARGET : test_klp_mod_target_init
237+ % insmod test_modules/$MOD_TARGET_PATCH .ko
238+ livepatch: enabling patch '$MOD_TARGET_PATCH '
239+ livepatch: '$MOD_TARGET_PATCH ': initializing patching transition
240+ livepatch: '$MOD_TARGET_PATCH ': starting patching transition
241+ livepatch: '$MOD_TARGET_PATCH ': completing patching transition
242+ livepatch: '$MOD_TARGET_PATCH ': patching complete
243+ % echo 0 > $SYSFS_KLP_DIR /$MOD_TARGET_PATCH /enabled
244+ livepatch: '$MOD_TARGET_PATCH ': initializing unpatching transition
245+ livepatch: '$MOD_TARGET_PATCH ': starting unpatching transition
246+ livepatch: '$MOD_TARGET_PATCH ': completing unpatching transition
247+ livepatch: '$MOD_TARGET_PATCH ': unpatching complete
248+ % rmmod $MOD_TARGET_PATCH
249+ % rmmod $MOD_TARGET
250+ $MOD_TARGET : test_klp_mod_target_exit"
251+
252+
253+ # - load a livepatch that targets a not-yet-loaded module
254+ # - load the target module: klp_module_coming patches it immediately
255+ # - verify the proc entry returns livepatched output
256+ # - disable and unload the livepatch
257+ # - verify the proc entry returns original output again
258+ # - unload the target module
259+
260+ start_test " module function patching (livepatch first)"
261+
262+ load_lp $MOD_TARGET_PATCH
263+ load_mod $MOD_TARGET
264+
265+ if [[ " $( cat /proc/$MOD_TARGET ) " != " $MOD_TARGET_PATCH : this has been live patched" ]] ; then
266+ echo -e " FAIL\n\n"
267+ die " livepatch kselftest(s) failed"
268+ fi
269+
270+ disable_lp $MOD_TARGET_PATCH
271+ unload_lp $MOD_TARGET_PATCH
272+
273+ if [[ " $( cat /proc/$MOD_TARGET ) " != " $MOD_TARGET : original output" ]] ; then
274+ echo -e " FAIL\n\n"
275+ die " livepatch kselftest(s) failed"
276+ fi
277+
278+ unload_mod $MOD_TARGET
279+
280+ check_result " % insmod test_modules/$MOD_TARGET_PATCH .ko
281+ livepatch: enabling patch '$MOD_TARGET_PATCH '
282+ livepatch: '$MOD_TARGET_PATCH ': initializing patching transition
283+ livepatch: '$MOD_TARGET_PATCH ': starting patching transition
284+ livepatch: '$MOD_TARGET_PATCH ': completing patching transition
285+ livepatch: '$MOD_TARGET_PATCH ': patching complete
286+ % insmod test_modules/$MOD_TARGET .ko
287+ livepatch: applying patch '$MOD_TARGET_PATCH ' to loading module '$MOD_TARGET '
288+ $MOD_TARGET : test_klp_mod_target_init
289+ % echo 0 > $SYSFS_KLP_DIR /$MOD_TARGET_PATCH /enabled
290+ livepatch: '$MOD_TARGET_PATCH ': initializing unpatching transition
291+ livepatch: '$MOD_TARGET_PATCH ': starting unpatching transition
292+ livepatch: '$MOD_TARGET_PATCH ': completing unpatching transition
293+ livepatch: '$MOD_TARGET_PATCH ': unpatching complete
294+ % rmmod $MOD_TARGET_PATCH
295+ % rmmod $MOD_TARGET
296+ $MOD_TARGET : test_klp_mod_target_exit"
297+
298+
199299exit 0
0 commit comments