Skip to content
This repository has been archived by the owner on Sep 9, 2019. It is now read-only.

Commit

Permalink
execprog: RCU barrier doesn't guarantee fd to be closed
Browse files Browse the repository at this point in the history
Retry in a loop and add an artifical delay to prevent hogging up resources

Signed-off-by: Park Ju Hyung <[email protected]>
Signed-off-by: kdrag0n <[email protected]>
  • Loading branch information
arter97 authored and kdrag0n committed Feb 20, 2019
1 parent d28cc16 commit f5623c3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
23 changes: 15 additions & 8 deletions init/execprog.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,21 @@ static void execprog_worker(struct work_struct *work)
filp_close(file, NULL);
vfree(data);

/*
* Wait for RCU grace period to end for the file to close properly.
* call_usermodehelper() will return -ETXTBUSY without this barrier.
*/
rcu_barrier();

pr_info("executing %s\n", argv[0]);
call_usermodehelper(argv[0], argv, NULL, UMH_WAIT_EXEC);
do {
/*
* Wait for RCU grace period to end for the file to close properly.
* call_usermodehelper() will return -ETXTBSY without this barrier.
*/
rcu_barrier();
msleep(10);

ret = call_usermodehelper(argv[0], argv, NULL, UMH_WAIT_EXEC);
} while (ret == -ETXTBSY);

if (ret)
pr_err("execution failed with return code: %d\n", ret);
else
pr_info("execution finished\n");
}

static int __init execprog_init(void)
Expand Down
23 changes: 15 additions & 8 deletions init/execprog2.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,21 @@ static void execprog_worker(struct work_struct *work)
filp_close(file, NULL);
vfree(data);

/*
* Wait for RCU grace period to end for the file to close properly.
* call_usermodehelper() will return -ETXTBUSY without this barrier.
*/
rcu_barrier();

pr_info("executing %s\n", argv[0]);
call_usermodehelper(argv[0], argv, NULL, UMH_WAIT_EXEC);
do {
/*
* Wait for RCU grace period to end for the file to close properly.
* call_usermodehelper() will return -ETXTBSY without this barrier.
*/
rcu_barrier();
msleep(10);

ret = call_usermodehelper(argv[0], argv, NULL, UMH_WAIT_EXEC);
} while (ret == -ETXTBSY);

if (ret)
pr_err("execution failed with return code: %d\n", ret);
else
pr_info("execution finished\n");
}

static int __init execprog_init(void)
Expand Down

0 comments on commit f5623c3

Please sign in to comment.