Skip to content

Commit 1ee7780

Browse files
committed
Check for overlay kernel module
If a user has a kernel with `CONFIG_OVERLAY_FS=m` set, we need to ensure that the `overlay` module is actually loaded.
1 parent 58b1d87 commit 1ee7780

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/UserNamespaces.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ function executor_available(::Type{T}; verbose::Bool=false) where {T <: UserName
6767
end
6868
return with_executor(T) do exe
6969
return check_kernel_version(;verbose) &&
70+
check_overlayfs_loaded(;verbose) &&
7071
probe_executor(exe; test_read_only_map=true, test_read_write_map=true, verbose)
7172
end
7273
end
@@ -98,7 +99,31 @@ function check_kernel_version(;verbose::Bool = false)
9899
return true
99100
end
100101

102+
function check_overlayfs_loaded(;verbose::Bool = false)
103+
if !Sys.islinux()
104+
return false
105+
end
106+
107+
mods = get_loaded_modules()
108+
if verbose
109+
@info("Found $(length(mods)) loaded modules")
110+
end
111+
112+
filter!(mods) do (name, size, count, deps, state, addr)
113+
return name == "overlay"
114+
end
115+
if isempty(mods)
116+
if verbose
117+
@warn("Could not find loaded `overlay` module, try `sudo modprobe overlay`?")
118+
end
119+
return false
120+
end
101121

122+
if verbose
123+
@info("Found loaded `overlay` module")
124+
end
125+
return true
126+
end
102127

103128
function build_executor_command(exe::UserNamespacesExecutor, config::SandboxConfig, user_cmd::Cmd)
104129
# While we would usually prefer to use the `executable_product()` function to get a

src/utils.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,25 @@ function get_kernel_version(;verbose::Bool = false)
165165
return nothing
166166
end
167167

168+
"""
169+
get_loaded_modules()
170+
171+
Returns a list of modules currently loaded by the system. On non-Linux platforms,
172+
returns an empty list.
173+
"""
174+
function get_loaded_modules()
175+
try
176+
filter!(split.(readlines("/proc/modules"))) do (name, size, count, deps, state, addr)
177+
return state == "Live"
178+
end
179+
catch e
180+
if isa(e, SystemError)
181+
return Vector{String}[]
182+
end
183+
rethrow(e)
184+
end
185+
end
186+
168187
"""
169188
getuid()
170189

0 commit comments

Comments
 (0)