Skip to content

Make the user mode driver code a better citizen

Eric W. Biederman bpf linux-fsdevel linux-mm linux-security-module lkml mm-commits oe-kbuild-all stable 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest posting 2/20 of 16 patches 1 replyIn review
  2. v3 posting 1/216 patches 14 repliesSuperseded
  3. v215 patches 23 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v114 patches24 repliesSuperseded

Patches in v3 posting 2/2 No applies recorded yet

None of the 16 patches the cover letter announces are in this archive.

Reviews trailers per patch

PatchGreg Kroah-Hartman
SeriesR-b R-b R-b R-b R-b R-b R-b R-b R-b R-b R-b R-b R-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [merged][PATCH v3 00/16] Make the user mode driver code a better citizen

I have merged all of this into my exec-next tree.

The code is also available on the frozen branch:

git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace.git usermode-driver-cleanup

The range-diff from the last posted version is below.

I was asked "Is there a simpler version of this code that could be used for backports?". The honest answer is not really.

Fundamentally do_execve_file as it existed prior to this set of changes breaks a lot of invariants in exec. The choices are either track down all of the invariants it violates and fix it, or reorganize the code so that do_execve_file is unnecessary. Reorganizing the code was the path I found simplest and most reliable. I don't think anyone has tracked down all of the constraints the code violated.

There is an issue clearly pointed out by Tetsuo Handa that in theory if there is too long of a delay between closing the file after writing it and flush_delayed_fput might not synchronize the file synchronously. I can not trigger it, and this is the same code path the initramfs relies upon. So I think calling flush_delayed_fput is good enough for this set of changes.

If and when a generally accepted way to remove the theoreticaly race it will be trivial to fix flush_delayed_fput or replace it and none of the other logic changes.

Declaring this set of changes done now, allows the work that depends upon this change to proceed.

Eric

---

1: 8fee10be3e7e ! 1: 5fec25f2cb95 umh: Capture the pid in umh_pipe_setup
@@ Commit message

v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
+ Link: https://lkml.kernel.org/r/[email protected]

+ Acked-by: Alexei Starovoitov <[email protected]>
+ Tested-by: Alexei Starovoitov <[email protected]>

## include/linux/umh.h ##
2: 2d97bc5269dd ! 2: b044fa2ae50d umh: Move setting PF_UMH into umh_pipe_setup
@@ Commit message

v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
+ Link: https://lkml.kernel.org/r/[email protected]

+ Acked-by: Alexei Starovoitov <[email protected]>
+ Tested-by: Alexei Starovoitov <[email protected]>

## kernel/umh.c ##
3: 974e2b827aca ! 3: 3a171042aeab umh: Rename the user mode driver helpers for clarity
@@ Commit message

v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
+ Link: https://lkml.kernel.org/r/[email protected]

+ Acked-by: Alexei Starovoitov <[email protected]>
+ Tested-by: Alexei Starovoitov <[email protected]>

## kernel/umh.c ##
4: 6c8f72f8eb49 ! 4: 21d598280675 umh: Remove call_usermodehelper_setup_file.
@@ Commit message

v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
+ Link: https://lkml.kernel.org/r/[email protected]

+ Acked-by: Alexei Starovoitov <[email protected]>
+ Tested-by: Alexei Starovoitov <[email protected]>

## include/linux/umh.h ##
5: cbf6c2b5a04a ! 5: 884c5e683b67 umh: Separate the user mode driver and the user mode helper support
@@ Commit message

v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
+ Link: https://lkml.kernel.org/r/[email protected]

+ Acked-by: Alexei Starovoitov <[email protected]>
+ Tested-by: Alexei Starovoitov <[email protected]>

## include/linux/bpfilter.h ##
6: b68617fd4ee3 ! 6: 74be2d3b80af umd: For clarity rename umh_info umd_info
@@ Commit message

v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
+ Link: https://lkml.kernel.org/r/[email protected]

+ Acked-by: Alexei Starovoitov <[email protected]>
+ Tested-by: Alexei Starovoitov <[email protected]>

## include/linux/bpfilter.h ##
7: 6881acff5f6a ! 7: 1199c6c3da51 umd: Rename umd_info.cmdline umd_info.driver_name
@@ Commit message

v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
+ Link: https://lkml.kernel.org/r/[email protected]

+ Acked-by: Alexei Starovoitov <[email protected]>
+ Tested-by: Alexei Starovoitov <[email protected]>

## include/linux/usermode_driver.h ##
8: cd210622ff6f ! 8: e2dc9bf3f527 umd: Transform fork_usermode_blob into fork_usermode_driver
@@ Commit message
[1] https://lore.kernel.org/linux-fsdevel/[email protected]/
v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
+ Link: https://lkml.kernel.org/r/[email protected]

+ Acked-by: Alexei Starovoitov <[email protected]>
+ Tested-by: Alexei Starovoitov <[email protected]>

## include/linux/usermode_driver.h ##
9: 74d65aaf2cab ! 9: 55e6074e3fa6 umh: Stop calling do_execve_file
@@ Commit message

v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
+ Link: https://lkml.kernel.org/r/[email protected]

+ Acked-by: Alexei Starovoitov <[email protected]>
+ Tested-by: Alexei Starovoitov <[email protected]>

## include/linux/umh.h ##
10: 58a9854274a1 ! 10: 25cf336de51b exec: Remove do_execve_file
@@ Commit message
[1] https://lore.kernel.org/linux-fsdevel/[email protected]/
v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
+ Link: https://lkml.kernel.org/r/[email protected]

+ Acked-by: Alexei Starovoitov <[email protected]>
+ Tested-by: Alexei Starovoitov <[email protected]>

## fs/exec.c ##
11: c45ae16a18c9 ! 11: 0fe3c63148ef bpfilter: Move bpfilter_umh back into init data
@@ Commit message

v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
+ Link: https://lkml.kernel.org/r/[email protected]

+ Acked-by: Alexei Starovoitov <[email protected]>
+ Tested-by: Alexei Starovoitov <[email protected]>

## net/bpfilter/bpfilter_umh_blob.S ##
12: 43b41b9d52a0 ! 12: 1c340ead18ee umd: Track user space drivers with struct pid
@@ Commit message

v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
+ Link: https://lkml.kernel.org/r/[email protected]

+ Acked-by: Alexei Starovoitov <[email protected]>
+ Tested-by: Alexei Starovoitov <[email protected]>

## include/linux/usermode_driver.h ##
13: 653476c24a30 ! 13: 38fd525a4c61 exit: Factor thread_group_exited out of pidfd_poll
@@ Metadata
## Commit message ##
exit: Factor thread_group_exited out of pidfd_poll

- Create an independent helper thread_group_exited report return true
+ Create an independent helper thread_group_exited which returns true
when all threads have passed exit_notify in do_exit. AKA all of the threads are at least zombies and might be dead or completely gone.

- Create this helper by taking the logic out of pidfd_poll where
- it is already tested, and adding a missing READ_ONCE on
- the read of task->exit_state.
+ Create this helper by taking the logic out of pidfd_poll where it is
+ already tested, and adding a READ_ONCE on the read of
+ task->exit_state.

I will be changing the user mode driver code to use this same logic to know when a user mode driver needs to be restarted.
@@ Commit message
Place the new helper thread_group_exited in kernel/exit.c and EXPORT it so it can be used by modules.

+ Link: https://lkml.kernel.org/r/[email protected]
+ Acked-by: Christian Brauner <[email protected]>
+ Acked-by: Alexei Starovoitov <[email protected]>
+ Tested-by: Alexei Starovoitov <[email protected]>

## include/linux/sched/signal.h ##
@@ kernel/exit.c: COMPAT_SYSCALL_DEFINE5(waitid,
+ * thread_group_exited - check that a thread group has exited
+ * @pid: tgid of thread group to be checked.
+ *
-+ * Test if thread group is has exited (all threads are zombies, dead
-+ * or completely gone).
++ * Test if the thread group represented by tgid has exited (all
++ * threads are zombies, dead or completely gone).
+ *
+ * Return: true if the thread group has exited. false otherwise.
+ */
14: 7ad037d12723 ! 14: e80eb1dc868b bpfilter: Take advantage of the facilities of struct pid
@@ Commit message

v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
+ Link: https://lkml.kernel.org/r/[email protected]

+ Acked-by: Alexei Starovoitov <[email protected]>
+ Tested-by: Alexei Starovoitov <[email protected]>

## include/linux/bpfilter.h ##
15: e50cf5e57a62 ! 15: 8c2f52663973 umd: Remove exit_umh
@@ Commit message

v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
+ Link: https://lkml.kernel.org/r/[email protected]

+ Acked-by: Alexei Starovoitov <[email protected]>
+ Tested-by: Alexei Starovoitov <[email protected]>

## include/linux/sched.h ##
16: 32e057d8aa4a ! 16: 33c326014fe6 umd: Stop using split_argv
@@ Commit message
call_usermodehelper_setup.

v1: https://lkml.kernel.org/r/[email protected]
+ Link: https://lkml.kernel.org/r/[email protected]
+ Acked-by: Alexei Starovoitov <[email protected]>
+ Tested-by: Alexei Starovoitov <[email protected]>

## kernel/usermode_driver.c ##