There are a few system calls (pselect, ppoll, etc) which replace a task sigmask while they are running in a kernel-space When a task calls one of these syscalls, the kernel saves a current sigmask in task->saved_sigmask and sets a syscall sigmask. On syscall-exit-stop, ptrace traps a task before restoring the saved_sigmask, so PTRACE_GETSIGMASK returns the syscall sigmask and PTRACE_SETSIGMASK does nothing, because its sigmask is replaced by saved_sigmask, when the task returns to user-space. This patch fixes this problem. PTRACE_GETSIGMASK returns saved_sigmask if it's set. PTRACE_SETSIGMASK drops the TIF_RESTORE_SIGMASK flag.
Showing the changes to include/linux (1 of 2 files). Show all
Unified · Split
| @@ -418,10 +418,20 @@ static inline void set_restore_sigmask(void) · 417 unmodified lines | |||
| 418 | set_thread_flag(TIF_RESTORE_SIGMASK); | 418 | set_thread_flag(TIF_RESTORE_SIGMASK); |
| 419 | WARN_ON(!test_thread_flag(TIF_SIGPENDING)); | 419 | WARN_ON(!test_thread_flag(TIF_SIGPENDING)); |
| 420 | } | 420 | } |
| 421 | |||
| 422 | static inline void clear_tsk_restore_sigmask(struct task_struct *tsk) | ||
| 423 | { | ||
| 424 | clear_tsk_thread_flag(tsk, TIF_RESTORE_SIGMASK); | ||
| 425 | } | ||
| 426 | |||
| 421 | static inline void clear_restore_sigmask(void) | 427 | static inline void clear_restore_sigmask(void) |
| 422 | { | 428 | { |
| 423 | clear_thread_flag(TIF_RESTORE_SIGMASK); | 429 | clear_thread_flag(TIF_RESTORE_SIGMASK); |
| 424 | } | 430 | } |
| 431 | static inline bool test_tsk_restore_sigmask(struct task_struct *tsk) | ||
| 432 | { | ||
| 433 | return test_tsk_thread_flag(tsk, TIF_RESTORE_SIGMASK); | ||
| 434 | } | ||
| 425 | static inline bool test_restore_sigmask(void) | 435 | static inline bool test_restore_sigmask(void) |
| 426 | { | 436 | { |
| 427 | return test_thread_flag(TIF_RESTORE_SIGMASK); | 437 | return test_thread_flag(TIF_RESTORE_SIGMASK); |
| @@ -439,6 +449,10 @@ static inline void set_restore_sigmask(void) · 11 unmodified lines | |||
| 439 | current->restore_sigmask = true; | 449 | current->restore_sigmask = true; |
| 440 | WARN_ON(!test_thread_flag(TIF_SIGPENDING)); | 450 | WARN_ON(!test_thread_flag(TIF_SIGPENDING)); |
| 441 | } | 451 | } |
| 452 | static inline void clear_tsk_restore_sigmask(struct task_struct *tsk) | ||
| 453 | { | ||
| 454 | tsk->restore_sigmask = false; | ||
| 455 | } | ||
| 442 | static inline void clear_restore_sigmask(void) | 456 | static inline void clear_restore_sigmask(void) |
| 443 | { | 457 | { |
| 444 | current->restore_sigmask = false; | 458 | current->restore_sigmask = false; |
| @@ -447,6 +461,10 @@ static inline bool test_restore_sigmask(void) · 2 unmodified lines | |||
| 447 | { | 461 | { |
| 448 | return current->restore_sigmask; | 462 | return current->restore_sigmask; |
| 449 | } | 463 | } |
| 464 | static inline bool test_tsk_restore_sigmask(struct task_struct *tsk) | ||
| 465 | { | ||
| 466 | return tsk->restore_sigmask; | ||
| 467 | } | ||
| 450 | static inline bool test_and_clear_restore_sigmask(void) | 468 | static inline bool test_and_clear_restore_sigmask(void) |
| 451 | { | 469 | { |
| 452 | if (!current->restore_sigmask) | 470 | if (!current->restore_sigmask) |