From nobody@FreeBSD.org  Wed Jan 29 14:03:26 2014
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTPS id 11BE28FC
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 29 Jan 2014 14:03:26 +0000 (UTC)
Received: from oldred.freebsd.org (oldred.freebsd.org [IPv6:2001:1900:2254:206a::50:4])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx1.freebsd.org (Postfix) with ESMTPS id F1BFB1C91
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 29 Jan 2014 14:03:25 +0000 (UTC)
Received: from oldred.freebsd.org ([127.0.1.6])
	by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id s0TE3PbX032057
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 29 Jan 2014 14:03:25 GMT
	(envelope-from nobody@oldred.freebsd.org)
Received: (from nobody@localhost)
	by oldred.freebsd.org (8.14.5/8.14.5/Submit) id s0TE3PVi032056;
	Wed, 29 Jan 2014 14:03:25 GMT
	(envelope-from nobody)
Message-Id: <201401291403.s0TE3PVi032056@oldred.freebsd.org>
Date: Wed, 29 Jan 2014 14:03:25 GMT
From: Svatopluk Kraus <onwahe@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: sigcode not synced on executable stack on icache not coherent archs
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         186236
>Category:       kern
>Synopsis:       [kernel] [patch] sigcode not synced on executable stack on icache not coherent archs
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jan 29 14:10:00 UTC 2014
>Closed-Date:    
>Last-Modified:  Sun May 04 04:56:58 UTC 2014
>Originator:     Svatopluk Kraus
>Release:        current
>Organization:
>Environment:
>Description:
When sigcode (signal trampoline) is copied to user stack during exec, no icache syncing is called. This is problem on architectures where icache is not coherent.
>How-To-Repeat:
I have noticed the problem after fork(), when parent process was immediately sending signal to child process. As a cache problem, the problem displayed itself rarely.
>Fix:
I'm attaching simple patch. Another approche is to map user stack without exec privilege, copy sigcode, and then remap the stack with exec privilege.

Patch attached with submission follows:

Index: sys/kern/kern_exec.c
===================================================================
--- sys/kern/kern_exec.c	(revision 261262)
+++ sys/kern/kern_exec.c	(working copy)
@@ -1264,9 +1264,12 @@
 	/*
 	 * install sigcode
 	 */
-	if (szsigcode != 0)
+	if (szsigcode != 0) {
 		copyout(p->p_sysent->sv_sigcode, ((caddr_t)arginfo -
 		    szsigcode), szsigcode);
+		vm_sync_icache(&(p->p_vmspace->vm_map), ((vm_offset_t)arginfo -
+		    szsigcode), szsigcode);
+	}
 
 	/*
 	 * Copy the image path for the rtld.


>Release-Note:
>Audit-Trail:
>Unformatted:
