Commit fd881d0
rseq: Fix segfault on registration when rseq_cs is non-zero
The rseq_cs field is documented as being set to 0 by user-space prior to
registration, however this is not currently enforced by the kernel. This
can result in a segfault on return to user-space if the value stored in
the rseq_cs field doesn't point to a valid struct rseq_cs.
The correct solution to this would be to fail the rseq registration when
the rseq_cs field is non-zero. However, some older versions of glibc
will reuse the rseq area of previous threads without clearing the
rseq_cs field and will also terminate the process if the rseq
registration fails in a secondary thread. This wasn't caught in testing
because in this case the leftover rseq_cs does point to a valid struct
rseq_cs.
What we can do is clear the rseq_cs field on registration when it's
non-zero which will prevent segfaults on registration and won't break
the glibc versions that reuse rseq areas on thread creation.
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20250306211223.109455-1-mjeanson@efficios.com1 parent 82354fc commit fd881d0
1 file changed
Lines changed: 48 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
239 | 262 | | |
240 | 263 | | |
241 | 264 | | |
| |||
244 | 267 | | |
245 | 268 | | |
246 | 269 | | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
254 | 275 | | |
255 | 276 | | |
256 | 277 | | |
257 | 278 | | |
| 279 | + | |
258 | 280 | | |
259 | 281 | | |
260 | 282 | | |
| |||
330 | 352 | | |
331 | 353 | | |
332 | 354 | | |
333 | | - | |
| 355 | + | |
334 | 356 | | |
335 | 357 | | |
336 | 358 | | |
| |||
341 | 363 | | |
342 | 364 | | |
343 | 365 | | |
344 | | - | |
| 366 | + | |
345 | 367 | | |
346 | | - | |
| 368 | + | |
347 | 369 | | |
348 | 370 | | |
349 | 371 | | |
| |||
375 | 397 | | |
376 | 398 | | |
377 | 399 | | |
378 | | - | |
| 400 | + | |
379 | 401 | | |
380 | 402 | | |
381 | 403 | | |
382 | | - | |
| 404 | + | |
383 | 405 | | |
384 | 406 | | |
385 | 407 | | |
| |||
453 | 475 | | |
454 | 476 | | |
455 | 477 | | |
| 478 | + | |
456 | 479 | | |
457 | 480 | | |
458 | 481 | | |
| |||
507 | 530 | | |
508 | 531 | | |
509 | 532 | | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
510 | 546 | | |
511 | 547 | | |
512 | 548 | | |
| |||
0 commit comments