Repository navigation
Commit 8a14b3a
authored
fix(sandbox): skip read-only mounts during recursive chown of /sandbox (NVIDIA#2341)
* fix(sandbox): skip read-only mounts during recursive chown of /sandbox
The sandbox supervisor crashed with EROFS when the recursive chown of
/sandbox encountered read-only submounts. This is common in gVisor-based
Kubernetes deployments where read-only volume mounts are the only way to
enforce per-directory immutability (Landlock is unavailable under gVisor).
The fix adds two guards to the ownership walk:
1. Mount-boundary detection via st_dev comparison — paths on a different
filesystem than /sandbox are skipped entirely, avoiding the chown
call on nested read-only mounts.
2. EROFS tolerance — if chown still returns EROFS (e.g. the root mount
itself is read-only), the error is logged at debug level and startup
continues.
Symlink skipping (already present) is preserved and extracted into the
recursive walker for consistency.
Manually verified on a kind cluster with a read-only PVC mounted at
/sandbox/readonly-data: the pod starts successfully, writable paths are
owned by the sandbox user, and the read-only mount retains root
ownership. Kubernetes e2e test coverage is a separate follow-up.
Closes NVIDIA#2294
Signed-off-by: Varsha Prasad Narsing <[email protected]>
* refactor(sandbox): consolidate symlink check into chown_recursive
Move the per-child symlink guard from the directory iteration loop into
the top of chown_recursive, reusing the symlink_metadata call that is
already performed there. This centralizes all three skip guards
(symlink, mount boundary, EROFS) in one place and eliminates a redundant
symlink_metadata call per child entry.
Suggested-by: elezar
Signed-off-by: Varsha Prasad Narsing <[email protected]>
* fix(sandbox): recurse into children after EROFS and fix doc comment
When chown returns EROFS on a directory, the code previously returned
early without recursing into children. This skipped writable submounts
nested under a read-only directory on the same device (e.g., a writable
emptyDir inside a read-only ConfigMap mount sharing the same st_dev).
Now the EROFS case falls through to the directory recursion so that
writable children are still chowned.
Also fixes the doc comment which said EROFS errors are "logged as
warnings" when they are actually logged at debug level.
Signed-off-by: Varsha Prasad Narsing <[email protected]>
* fix(sandbox): allow similar_names clippy lint in chown test
Signed-off-by: Varsha Prasad Narsing <[email protected]>
* fix(sandbox): remove cross-device skip and inject chown for EROFS tests
Remove the unconditional st_dev boundary check that prevented chown on
writable PVC mounts with a different device ID. Rely solely on EROFS
errors to skip read-only paths while continuing traversal into children
and siblings.
Inject the chown operation into chown_recursive to enable unit testing
the EROFS recovery path without requiring root or mount privileges.
Signed-off-by: Varsha Prasad Narsing <[email protected]>
Signed-off-by: Varsha Prasad Narsing <[email protected]>
* style(sandbox): apply rustfmt to chown test closures
Signed-off-by: Varsha Prasad Narsing <[email protected]>
Signed-off-by: Varsha Prasad Narsing <[email protected]>
* fix(sandbox): stop descending into EROFS subtrees to prevent TOCTOU race
After chown returns EROFS, return immediately instead of recursing into
the read-only directory's children. Descending into a mount we cannot
own creates a TOCTOU window where an attacker could swap a child for a
symlink between symlink_metadata and chown (CWE-367/CWE-59). Siblings
of the EROFS path are still visited by the caller's loop.
Signed-off-by: Varsha Prasad Narsing <[email protected]>
Signed-off-by: Varsha Prasad Narsing <[email protected]>
* fix(sandbox): hard-error on root EROFS, log read_dir failures, eliminate double stat
Chown root directly in chown_sandbox_home so EROFS on /sandbox itself
is a hard startup error rather than being silently swallowed. Extract
chown_children to log read_dir failures instead of silently skipping
them. This also eliminates the redundant symlink_metadata syscall on
the root path.
Signed-off-by: Varsha Prasad Narsing <[email protected]>
Signed-off-by: Varsha Prasad Narsing <[email protected]>
---------
Signed-off-by: Varsha Prasad Narsing <[email protected]>
Signed-off-by: Varsha Prasad Narsing <[email protected]>1 parent 0674a00 commit 8a14b3a
1 file changed
Lines changed: 143 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1168 | 1168 | | |
1169 | 1169 | | |
1170 | 1170 | | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
1171 | 1177 | | |
1172 | 1178 | | |
1173 | | - | |
1174 | | - | |
1175 | 1179 | | |
1176 | 1180 | | |
1177 | 1181 | | |
| |||
1180 | 1184 | | |
1181 | 1185 | | |
1182 | 1186 | | |
1183 | | - | |
| 1187 | + | |
1184 | 1188 | | |
1185 | | - | |
1186 | | - | |
1187 | | - | |
1188 | | - | |
1189 | | - | |
1190 | | - | |
1191 | | - | |
1192 | | - | |
1193 | | - | |
1194 | | - | |
1195 | | - | |
1196 | | - | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
1197 | 1211 | | |
1198 | | - | |
1199 | 1212 | | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
1200 | 1244 | | |
1201 | 1245 | | |
1202 | 1246 | | |
| |||
2115 | 2159 | | |
2116 | 2160 | | |
2117 | 2161 | | |
| 2162 | + | |
| 2163 | + | |
| 2164 | + | |
| 2165 | + | |
| 2166 | + | |
| 2167 | + | |
| 2168 | + | |
| 2169 | + | |
| 2170 | + | |
| 2171 | + | |
| 2172 | + | |
| 2173 | + | |
| 2174 | + | |
| 2175 | + | |
| 2176 | + | |
| 2177 | + | |
| 2178 | + | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
| 2182 | + | |
| 2183 | + | |
| 2184 | + | |
| 2185 | + | |
| 2186 | + | |
| 2187 | + | |
| 2188 | + | |
| 2189 | + | |
| 2190 | + | |
| 2191 | + | |
| 2192 | + | |
| 2193 | + | |
| 2194 | + | |
| 2195 | + | |
| 2196 | + | |
| 2197 | + | |
| 2198 | + | |
| 2199 | + | |
| 2200 | + | |
| 2201 | + | |
| 2202 | + | |
| 2203 | + | |
| 2204 | + | |
| 2205 | + | |
| 2206 | + | |
| 2207 | + | |
| 2208 | + | |
| 2209 | + | |
| 2210 | + | |
| 2211 | + | |
| 2212 | + | |
| 2213 | + | |
| 2214 | + | |
| 2215 | + | |
| 2216 | + | |
| 2217 | + | |
| 2218 | + | |
| 2219 | + | |
| 2220 | + | |
| 2221 | + | |
| 2222 | + | |
| 2223 | + | |
| 2224 | + | |
| 2225 | + | |
| 2226 | + | |
| 2227 | + | |
| 2228 | + | |
| 2229 | + | |
| 2230 | + | |
| 2231 | + | |
| 2232 | + | |
| 2233 | + | |
| 2234 | + | |
| 2235 | + | |
| 2236 | + | |
| 2237 | + | |
| 2238 | + | |
| 2239 | + | |
| 2240 | + | |
| 2241 | + | |
| 2242 | + | |
| 2243 | + | |
| 2244 | + | |
2118 | 2245 | | |
2119 | 2246 | | |
2120 | 2247 | | |
| |||
0 commit comments