Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8993439ybi; Tue, 23 Jul 2019 19:38:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqztOKnWx2B+w+lrV0w5n13q9OPTL3hc829GxlPdzkjGaFk7DYldplvIIiOv1A2eeIKMUdrG X-Received: by 2002:a65:464d:: with SMTP id k13mr71446667pgr.99.1563935928567; Tue, 23 Jul 2019 19:38:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563935928; cv=none; d=google.com; s=arc-20160816; b=mFsPuJ6R52tNNwAc3u16GfinCoKqJ9jIJQYhP3kNVf7SSI4Kuzx5KJJFcTNaXvpuKC H0zx67pgkp6i6HqKOOEbIGQjxDE2mxseH8dbWpvn+VseZlMfn4BFvupBig2FBbvOmiy2 LTrPbpwWc6/ycl63IBHXzhSyOwoUI0Qps0BoVzjajOj2XEn/rLO0oExcxKGoJfQxe2bM 2Ouo/kyCXMNNiRNCwdRFWpI7IoaBkbO2t+f0Pcn1zcOg+HBraQLothjmH1OuJDaf5fgg xTcsSqy0yN5pRpTg6qVF3W34lCeFc1ZTqlaj8klSP8tAPyppzaox+XvXdtRc0g+a7E7m 8Lbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=jAiZPrMI5z+IihscCcIFul7RWiYwhIVNfkxt/TRJPXU=; b=IoAtAJwqIAaegBqRbs4BE/U/iq4agxX5DaikD3t+3yshDwv8ZCdD/8gQ6GDydyovG+ tgTVwdoPmbKF5vFL4uGcSzz5V0ivI9+oKrWL4F7ZC9Lf7Oatv9p9FVKnCcBvB4pFVA7w ob4jaMFyCU1RDJZmqXE4xQgY6IR8sNN21YRtTmD9vdHMrx+F4THvIFpUOXyzxSIm/ARD 2jIOJ/3m0oAoahbcql55nJXXlmNzWrJAoMf0VCtPgv1Qt3ocyDDaCSrbo1Iv/tbF77XA YuORH8Vg3S/4hEZb0sISS+srkFAljIcG7yySmrE7JGLxWzvGpbpaumRaC13t2CZjFBTR CLaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="s3/5UQJq"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q10si11532484pls.42.2019.07.23.19.38.33; Tue, 23 Jul 2019 19:38:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="s3/5UQJq"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387544AbfGXC2n (ORCPT + 99 others); Tue, 23 Jul 2019 22:28:43 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:36044 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725763AbfGXC2n (ORCPT ); Tue, 23 Jul 2019 22:28:43 -0400 Received: by mail-pg1-f196.google.com with SMTP id l21so20369393pgm.3; Tue, 23 Jul 2019 19:28:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jAiZPrMI5z+IihscCcIFul7RWiYwhIVNfkxt/TRJPXU=; b=s3/5UQJqE8iRn1S309zvi9848XiPzqSVIqENT7vN1QHeVle3BtzW+tunGQZr5lJu/n zaadKXsJbG5A6s0TQqzSmDzZyxJ/LWo+pm1eXuZAOvoiUMa5l4sk94T1VxvGAqFl+sxJ fcJ6Y/O6+eG39Rcc1qNwxZlUNhxJqBWjBktpWFmrdDhBgslFTiIuFNjBSWtJvzGVVQ53 7vL/2abo0KgzpFIYVhYY/gGDbD6XA6v3uAMVICme2gKMDSA3IEFpp4ZsFEdIUUje0o45 rk/IFP95tyjYJSEf6PDPzk64rkaXsiGQeefF0bFAGdTIAI++WpQwGgppDnCoNxOVNIYy 147w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jAiZPrMI5z+IihscCcIFul7RWiYwhIVNfkxt/TRJPXU=; b=mhfqF9GKK0Z/FW/f0cEIH0Rd7BPVH+5hsX3LI0aqI+yxhrtsrxjXHTPGg44CedDfTg HGU8F4JSjxfJLxZ/aVs4nGjz0LyNHyyjJE1f30ZADbl819fNezBw+hvEmX5S17tsESAH ZYZMPxuEfUQb5+EGDpqNMGfTqeBsjwF2Sf4Iat5MTBj5D/JpWDGIWWk6Lnaf/YoL9cuN 1SKaLC+DgkBPrh7TqVnqifjCfOxDF/LC/HJdQqdM4YEb2iQCh1tHFQW1T8j6ZqLXMzju WA5mniEoTmnWM+8MM92c+VFoiOY96rxoJc9gxB+2KLIRmSfD+GagS2VUJAW2himDI0Cf gvfw== X-Gm-Message-State: APjAAAUKuCgoTXwm/W5wOGxKruShmEt0oLwuZLcVD3mC2tUsghSTw3RI 1oBT6BqTQHP8nJdQaqvuJJlRGa9MKSqQyX4nvE8= X-Received: by 2002:a63:7245:: with SMTP id c5mr65365954pgn.11.1563935322024; Tue, 23 Jul 2019 19:28:42 -0700 (PDT) MIME-Version: 1.0 References: <20190715134655.4076-1-sashal@kernel.org> <20190715134655.4076-39-sashal@kernel.org> <87v9vs43pq.fsf@xmission.com> In-Reply-To: From: Steve French Date: Tue, 23 Jul 2019 21:28:31 -0500 Message-ID: Subject: Re: [PATCH AUTOSEL 5.2 039/249] signal/cifs: Fix cifs_put_tcp_session to call send_sig instead of force_sig To: "Eric W. Biederman" Cc: ronnie sahlberg , Sasha Levin , LKML , Stable , Namjae Jeon , Jeff Layton , linux-cifs Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I did some additional testing and it looks like the "allow_signal" change may be safe enough # git diff -a diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index a4830ced0f98..a15a6e738eb5 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -1113,6 +1113,7 @@ cifs_demultiplex_thread(void *p) mempool_resize(cifs_req_poolp, length + cifs_min_rcv); set_freezable(); + allow_signal(SIGKILL); while (server->tcpStatus != CifsExiting) { if (try_to_freeze()) continue; See below: root@smf-Thinkpad-P51:~/cifs-2.6/fs/cifs# insmod ./cifs.ko root@smf-Thinkpad-P51:~/cifs-2.6/fs/cifs# mount -t cifs //localhost/scratch /mnt -o username=sfrench Password for sfrench@//localhost/scratch: ************ root@smf-Thinkpad-P51:~/cifs-2.6/fs/cifs# ps -A | grep cifsd 5176 ? 00:00:00 cifsd root@smf-Thinkpad-P51:~/cifs-2.6/fs/cifs# kill -9 5176 root@smf-Thinkpad-P51:~/cifs-2.6/fs/cifs# ls /mnt 0444 dir0750 dir0754 newfile root@smf-Thinkpad-P51:~/cifs-2.6/fs/cifs# umount /mnt root@smf-Thinkpad-P51:~/cifs-2.6/fs/cifs# ps -A | grep cifsd root@smf-Thinkpad-P51:~/cifs-2.6/fs/cifs# rmmod cifs On Tue, Jul 23, 2019 at 9:19 PM Steve French wrote: > > Pavel noticed I missed a line from the attempt to do a similar patch > to Eric's suggestion > (it still didn't work though - although "allow_signal" does albeit is > possibly dangerous as user space can kill cifsd) > > # git diff -a > diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c > index a4830ced0f98..8758dff18c15 100644 > --- a/fs/cifs/connect.c > +++ b/fs/cifs/connect.c > @@ -1104,6 +1104,7 @@ cifs_demultiplex_thread(void *p) > struct task_struct *task_to_wake = NULL; > struct mid_q_entry *mids[MAX_COMPOUND]; > char *bufs[MAX_COMPOUND]; > + sigset_t mask, oldmask; > > current->flags |= PF_MEMALLOC; > cifs_dbg(FYI, "Demultiplex PID: %d\n", task_pid_nr(current)); > @@ -1113,6 +1114,9 @@ cifs_demultiplex_thread(void *p) > mempool_resize(cifs_req_poolp, length + cifs_min_rcv); > > set_freezable(); > + sigfillset(&mask); > + sigdelset(&mask, SIGKILL); > + sigprocmask(SIG_BLOCK, &mask, &oldmask); > while (server->tcpStatus != CifsExiting) { > if (try_to_freeze()) > continue; > > On Tue, Jul 23, 2019 at 9:02 PM Steve French wrote: > > > > On Tue, Jul 23, 2019 at 8:32 PM Eric W. Biederman wrote: > > > > > > Steve French writes: > > > > > > > Very easy to see what caused the regression with this global change: > > > > > > > > mount (which launches "cifsd" thread to read the socket) > > > > umount (which kills the "cifsd" thread) > > > > rmmod (rmmod now fails since "cifsd" thread is still active) > > > > > > > > mount launches a thread to read from the socket ("cifsd") > > > > umount is supposed to kill that thread (but with the patch > > > > "signal/cifs: Fix cifs_put_tcp_session to call send_sig instead of > > > > force_sig" that no longer works). So the regression is that after > > > > unmount you still see the "cifsd" thread, and the reason that cifsd > > > > thread is still around is that that patch no longer force kills the > > > > process (see line 2652 of fs/cifs/connect.c) which regresses module > > > > removal. > > > > > > > > - force_sig(SIGKILL, task); > > > > + send_sig(SIGKILL, task, 1); > > > > > > > > The comment in the changeset indicates "The signal SIGKILL can not be > > > > ignored" but obviously it can be ignored - at least on 5.3-rc1 it is > > > > being ignored. > > > > > > > > If send_sig(SIGKILL ...) doesn't work and if force_sig(SIGKILL, task) > > > > is removed and no longer possible - how do we kill a helper process > > > > ... > > > > > > I think I see what is happening. It looks like as well as misuinsg > > > force_sig, cifs is also violating the invariant that keeps SIGKILL out > > > of the blocked signal set. > > > > > > For that force_sig will act differently. I did not consider it because > > > that is never supposed to happen. > > > > > > Can someone test this code below and confirm the issue goes away? > > > > > > diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c > > > index 5d6d44bfe10a..2a782ebc7b65 100644 > > > --- a/fs/cifs/transport.c > > > +++ b/fs/cifs/transport.c > > > @@ -347,6 +347,7 @@ __smb_send_rqst(struct TCP_Server_Info *server, int num_rqst, > > > */ > > > > > > sigfillset(&mask); > > > + sigdelset(&mask, SIGKILL); > > > sigprocmask(SIG_BLOCK, &mask, &oldmask); > > > > > > /* Generate a rfc1002 marker for SMB2+ */ > > > > > > > > > Eric > > > > I just tried your suggestion and it didn't work. I also tried doing > > a similar thing on the thread we are trying to kills ("cifsd" - ie > > which is blocked in the function cifs_demultiplex_thread waiting to > > read from the socket) > > # git diff -a > > diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c > > index a4830ced0f98..b73062520a17 100644 > > --- a/fs/cifs/connect.c > > +++ b/fs/cifs/connect.c > > @@ -1104,6 +1104,7 @@ cifs_demultiplex_thread(void *p) > > struct task_struct *task_to_wake = NULL; > > struct mid_q_entry *mids[MAX_COMPOUND]; > > char *bufs[MAX_COMPOUND]; > > + sigset_t mask; > > > > current->flags |= PF_MEMALLOC; > > cifs_dbg(FYI, "Demultiplex PID: %d\n", task_pid_nr(current)); > > @@ -1113,6 +1114,8 @@ cifs_demultiplex_thread(void *p) > > mempool_resize(cifs_req_poolp, length + cifs_min_rcv); > > > > set_freezable(); > > + sigfillset(&mask); > > + sigdelset(&mask, SIGKILL); > > while (server->tcpStatus != CifsExiting) { > > if (try_to_freeze()) > > continue; > > > > > > That also didn't work. The only thing I have been able to find > > which worked was: > > > > diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c > > index a4830ced0f98..e74f04163fc9 100644 > > --- a/fs/cifs/connect.c > > +++ b/fs/cifs/connect.c > > @@ -1113,6 +1113,7 @@ cifs_demultiplex_thread(void *p) > > mempool_resize(cifs_req_poolp, length + cifs_min_rcv); > > > > set_freezable(); > > + allow_signal(SIGKILL); > > while (server->tcpStatus != CifsExiting) { > > if (try_to_freeze()) > > continue; > > > > > > That fixes the problem ... but ... as Ronnie and others have noted it > > would allow a userspace process to make the mount unusable (all you > > would have to do would be to do a kill -9 of the "cifsd" process from > > some userspace process like bash and the mount would be unusable - so > > this sounds dangerous. > > > > Is there an alternative that, in the process doing the unmount in > > kernel, would allow us to do the equivalent of: > > "allow_signal(SIGKILL, " > > In otherwords, to minimize the risk of some userspace process killing > > cifsd, could we delay enabling allow_signal(SIGKILL) till the unmount > > begins by doing it for a different process (have the unmount process > > enable signals for the cifsd process). Otherwise is there a way to > > force kill a process from the kernel as we used to do - without > > running the risk of a user space process killing cifsd (which is bad). > > > > -- > > Thanks, > > > > Steve > > > > -- > Thanks, > > Steve -- Thanks, Steve