Skip to content

Commit 78dce99

Browse files
Mikulas Patockagregkh
authored andcommitted
md: don't use flush_signals in userspace processes
commit f9c79bc upstream. The function flush_signals clears all pending signals for the process. It may be used by kernel threads when we need to prepare a kernel thread for responding to signals. However using this function for an userspaces processes is incorrect - clearing signals without the program expecting it can cause misbehavior. The raid1 and raid5 code uses flush_signals in its request routine because it wants to prepare for an interruptible wait. This patch drops flush_signals and uses sigprocmask instead to block all signals (including SIGKILL) around the schedule() call. The signals are not lost, but the schedule() call won't respond to them. Signed-off-by: Mikulas Patocka <[email protected]> Acked-by: NeilBrown <[email protected]> Signed-off-by: Shaohua Li <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 9b989b4 commit 78dce99

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

drivers/md/raid1.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ static void make_request(struct mddev *mddev, struct bio * bio)
10881088
*/
10891089
DEFINE_WAIT(w);
10901090
for (;;) {
1091-
flush_signals(current);
1091+
sigset_t full, old;
10921092
prepare_to_wait(&conf->wait_barrier,
10931093
&w, TASK_INTERRUPTIBLE);
10941094
if (bio_end_sector(bio) <= mddev->suspend_lo ||
@@ -1097,7 +1097,10 @@ static void make_request(struct mddev *mddev, struct bio * bio)
10971097
!md_cluster_ops->area_resyncing(mddev, WRITE,
10981098
bio->bi_iter.bi_sector, bio_end_sector(bio))))
10991099
break;
1100+
sigfillset(&full);
1101+
sigprocmask(SIG_BLOCK, &full, &old);
11001102
schedule();
1103+
sigprocmask(SIG_SETMASK, &old, NULL);
11011104
}
11021105
finish_wait(&conf->wait_barrier, &w);
11031106
}

drivers/md/raid5.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5279,12 +5279,15 @@ static void make_request(struct mddev *mddev, struct bio * bi)
52795279
* userspace, we want an interruptible
52805280
* wait.
52815281
*/
5282-
flush_signals(current);
52835282
prepare_to_wait(&conf->wait_for_overlap,
52845283
&w, TASK_INTERRUPTIBLE);
52855284
if (logical_sector >= mddev->suspend_lo &&
52865285
logical_sector < mddev->suspend_hi) {
5286+
sigset_t full, old;
5287+
sigfillset(&full);
5288+
sigprocmask(SIG_BLOCK, &full, &old);
52875289
schedule();
5290+
sigprocmask(SIG_SETMASK, &old, NULL);
52885291
do_prepare = true;
52895292
}
52905293
goto retry;

0 commit comments

Comments
 (0)