Commit e2c2b04
x86/shstk: Prevent deadlock during shstk sigreturn
[ Upstream commit 9874b29 ]
During sigreturn the shadow stack signal frame is popped. The kernel does
this by reading the shadow stack using normal read accesses. When it can't
assume the memory is shadow stack, it takes extra steps to makes sure it is
reading actual shadow stack memory and not other normal readable memory. It
does this by holding the mmap read lock while doing the access and checking
the flags of the VMA.
Unfortunately that is not safe. If the read of the shadow stack sigframe
hits a page fault, the fault handler will try to recursively grab another
mmap read lock. This normally works ok, but if a writer on another CPU is
also waiting, the second read lock could fail and cause a deadlock.
Fix this by doing the read of the userspace memory via gup. Embed it in the
get_shstk_data() helper.
Currently there is a check that skips the lookup work when the SSP can be
assumed to be on a shadow stack. While reorganizing the function, remove
the optimization to make the tricky code flows more common, such that
issues like this cannot escape detection for so long.
[Due to missing per-vma MM sequence counter, use a simpler GUP based
solution for the backport]
Cc: <stable@vger.kernel.org> # Depends on https://lore.kernel.org/all/20260504205924.536382-1-rick.p.edgecombe@intel.com/
Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>1 parent 21159d8 commit e2c2b04
1 file changed
Lines changed: 29 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
262 | 263 | | |
263 | 264 | | |
264 | 265 | | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
265 | 284 | | |
266 | 285 | | |
267 | 286 | | |
268 | 287 | | |
269 | | - | |
| 288 | + | |
270 | 289 | | |
271 | 290 | | |
272 | 291 | | |
| |||
296 | 315 | | |
297 | 316 | | |
298 | 317 | | |
299 | | - | |
300 | 318 | | |
301 | 319 | | |
302 | 320 | | |
| |||
308 | 326 | | |
309 | 327 | | |
310 | 328 | | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
| 329 | + | |
| 330 | + | |
316 | 331 | | |
317 | 332 | | |
318 | 333 | | |
319 | 334 | | |
320 | 335 | | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
329 | 340 | | |
330 | 341 | | |
| 342 | + | |
| 343 | + | |
331 | 344 | | |
332 | 345 | | |
333 | 346 | | |
| |||
340 | 353 | | |
341 | 354 | | |
342 | 355 | | |
343 | | - | |
344 | | - | |
| 356 | + | |
345 | 357 | | |
346 | 358 | | |
347 | 359 | | |
| |||
0 commit comments