Commit fe05a56
Francesco Lavra
filesystem: Impose global recursion limit when resolving symbolic links
Mutual recursion between filesystem_resolve_sstring() and
filesystem_follow_links() consumes ~540 bytes on the kernel stack per
level. SYMLINK_HOPS_MAX=8 limits each individual follow_links call but each
nested intermediate path component gets its own hop counter with no global
recursion limit. This causes a stack overflow when handling a stat()
syscall with a sufficiently deep symlink chain.
Fix this issue by modifying filesystem_follow_links() so that the hop count
variable is a function parameter (whose value is incremented at each
recursion level) instead of a local variable.
Modify the SYMLINK_HOPS_MAX constant from 8 to 40 (which matches the
corresponding constant in the Linux kernel), since this constant now
represents the limit on the cumulative number of links (instead of the
number of "consecutive" links) when resolving a filesystem path.1 parent 6d1691a commit fe05a56
2 files changed
Lines changed: 18 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1164 | 1164 | | |
1165 | 1165 | | |
1166 | 1166 | | |
1167 | | - | |
1168 | | - | |
| 1167 | + | |
| 1168 | + | |
1169 | 1169 | | |
1170 | | - | |
1171 | | - | |
1172 | 1170 | | |
1173 | 1171 | | |
1174 | 1172 | | |
| |||
1206 | 1204 | | |
1207 | 1205 | | |
1208 | 1206 | | |
1209 | | - | |
| 1207 | + | |
1210 | 1208 | | |
1211 | 1209 | | |
1212 | 1210 | | |
| |||
1244 | 1242 | | |
1245 | 1243 | | |
1246 | 1244 | | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
1247 | 1252 | | |
1248 | 1253 | | |
1249 | 1254 | | |
| |||
1252 | 1257 | | |
1253 | 1258 | | |
1254 | 1259 | | |
1255 | | - | |
| 1260 | + | |
1256 | 1261 | | |
1257 | 1262 | | |
1258 | 1263 | | |
| |||
1263 | 1268 | | |
1264 | 1269 | | |
1265 | 1270 | | |
1266 | | - | |
| 1271 | + | |
1267 | 1272 | | |
1268 | | - | |
| 1273 | + | |
1269 | 1274 | | |
1270 | 1275 | | |
1271 | 1276 | | |
1272 | 1277 | | |
1273 | 1278 | | |
1274 | 1279 | | |
1275 | 1280 | | |
1276 | | - | |
1277 | 1281 | | |
1278 | 1282 | | |
1279 | 1283 | | |
1280 | 1284 | | |
1281 | 1285 | | |
1282 | 1286 | | |
| 1287 | + | |
| 1288 | + | |
1283 | 1289 | | |
1284 | | - | |
1285 | | - | |
| 1290 | + | |
| 1291 | + | |
1286 | 1292 | | |
1287 | 1293 | | |
1288 | 1294 | | |
1289 | 1295 | | |
1290 | | - | |
1291 | | - | |
1292 | | - | |
1293 | | - | |
1294 | | - | |
1295 | 1296 | | |
1296 | 1297 | | |
1297 | 1298 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
274 | 274 | | |
275 | 275 | | |
276 | 276 | | |
277 | | - | |
| 277 | + | |
278 | 278 | | |
279 | 279 | | |
280 | 280 | | |
| |||
0 commit comments