From owner-svn-src-head@freebsd.org  Tue Nov 17 12:33:12 2020
Return-Path: <owner-svn-src-head@freebsd.org>
Delivered-To: svn-src-head@mailman.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
 by mailman.nyi.freebsd.org (Postfix) with ESMTP id A96842EBA37;
 Tue, 17 Nov 2020 12:33:12 +0000 (UTC)
 (envelope-from alfredo@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org
 [IPv6:2610:1c1:1:606c::19:3])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
 client-signature RSA-PSS (4096 bits) client-digest SHA256)
 (Client CN "mxrelay.nyi.freebsd.org",
 Issuer "Let's Encrypt Authority X3" (verified OK))
 by mx1.freebsd.org (Postfix) with ESMTPS id 4Cb52J4RYPz4bTq;
 Tue, 17 Nov 2020 12:33:12 +0000 (UTC)
 (envelope-from alfredo@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2610:1c1:1:6068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8B4F11FE38;
 Tue, 17 Nov 2020 12:33:12 +0000 (UTC)
 (envelope-from alfredo@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.37])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0AHCXCpR042939;
 Tue, 17 Nov 2020 12:33:12 GMT (envelope-from alfredo@FreeBSD.org)
Received: (from alfredo@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0AHCXCkR042938;
 Tue, 17 Nov 2020 12:33:12 GMT (envelope-from alfredo@FreeBSD.org)
Message-Id: <202011171233.0AHCXCkR042938@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: alfredo set sender to
 alfredo@FreeBSD.org using -f
From: "Alfredo Dal'Ava Junior" <alfredo@FreeBSD.org>
Date: Tue, 17 Nov 2020 12:33:12 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-head@freebsd.org
Subject: svn commit: r367760 - head/sys/powerpc/powerpc
X-SVN-Group: head
X-SVN-Commit-Author: alfredo
X-SVN-Commit-Paths: head/sys/powerpc/powerpc
X-SVN-Commit-Revision: 367760
X-SVN-Commit-Repository: base
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-head@freebsd.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: SVN commit messages for the src tree for head/-current
 <svn-src-head.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/svn-src-head>,
 <mailto:svn-src-head-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-head/>
List-Post: <mailto:svn-src-head@freebsd.org>
List-Help: <mailto:svn-src-head-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/svn-src-head>,
 <mailto:svn-src-head-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Tue, 17 Nov 2020 12:33:12 -0000

Author: alfredo
Date: Tue Nov 17 12:33:12 2020
New Revision: 367760
URL: https://svnweb.freebsd.org/changeset/base/367760

Log:
  [POWERPC] fix signal race condition
  
  r367416 should have called save_fpu() before kern_sigprocmask to avoid
  race condition
  
  Thanks jhibbits and bdragon for pointing it out
  
  Reviewed by:	jhibbits
  Sponsored by:	Eldorado Research Institute (eldorado.org.br)
  Differential Revision:	https://reviews.freebsd.org/D27241

Modified:
  head/sys/powerpc/powerpc/exec_machdep.c

Modified: head/sys/powerpc/powerpc/exec_machdep.c
==============================================================================
--- head/sys/powerpc/powerpc/exec_machdep.c	Tue Nov 17 12:04:29 2020	(r367759)
+++ head/sys/powerpc/powerpc/exec_machdep.c	Tue Nov 17 12:33:12 2020	(r367760)
@@ -334,8 +334,6 @@ sys_sigreturn(struct thread *td, struct sigreturn_args
 	if (error != 0)
 		return (error);
 
-	kern_sigprocmask(td, SIG_SETMASK, &uc.uc_sigmask, NULL, 0);
-
 	/* 
 	 * Save FPU state if needed. User may have changed it on
 	 * signal handler 
@@ -343,6 +341,8 @@ sys_sigreturn(struct thread *td, struct sigreturn_args
 	if (uc.uc_mcontext.mc_srr1 & PSL_FP)
 		save_fpu(td);
 
+	kern_sigprocmask(td, SIG_SETMASK, &uc.uc_sigmask, NULL, 0);
+
 	CTR3(KTR_SIG, "sigreturn: return td=%p pc=%#x sp=%#x",
 	     td, uc.uc_mcontext.mc_srr0, uc.uc_mcontext.mc_gpr[1]);
 
@@ -836,8 +836,6 @@ freebsd32_sigreturn(struct thread *td, struct freebsd3
 	if (error != 0)
 		return (error);
 
-	kern_sigprocmask(td, SIG_SETMASK, &uc.uc_sigmask, NULL, 0);
-
 	/*
 	 * Save FPU state if needed. User may have changed it on
 	 * signal handler
@@ -845,6 +843,7 @@ freebsd32_sigreturn(struct thread *td, struct freebsd3
 	if (uc.uc_mcontext.mc_srr1 & PSL_FP)
 		save_fpu(td);
 
+	kern_sigprocmask(td, SIG_SETMASK, &uc.uc_sigmask, NULL, 0);
 
 	CTR3(KTR_SIG, "sigreturn: return td=%p pc=%#x sp=%#x",
 	     td, uc.uc_mcontext.mc_srr0, uc.uc_mcontext.mc_gpr[1]);