linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@tv-sign.ru>
To: Andrew Morton <akpm@osdl.org>
Cc: ebiederm@xmission.com, torvalds@osdl.org,
	linux-kernel@vger.kernel.org, janak@us.ibm.com,
	viro@ftp.linux.org.uk, hch@lst.de, mtk-manpages@gmx.net,
	ak@muc.de, paulus@samba.org
Subject: [PATCH] implement unshare(CLONE_SIGHAND) for single-thread case
Date: Sat, 18 Mar 2006 16:13:24 +0300	[thread overview]
Message-ID: <441C0774.C5FA688D@tv-sign.ru> (raw)
In-Reply-To: 20060317125607.78a5dbe4.akpm@osdl.org

on top of (already merged)
	unshare-use-rcu_assign_pointer-when-setting-sighand.patch
depends on
	convert-sighand_cache-to-use-slab_destroy_by_rcu.patch

Implement unshare(CLONE_SIGHAND) for single-thread case.

I think it is not possible to do it for multithread case without
complication of copy_process().

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>

--- MM/kernel/fork.c~	2006-03-18 16:23:23.000000000 +0300
+++ MM/kernel/fork.c	2006-03-18 17:00:39.000000000 +0300
@@ -1483,18 +1483,24 @@ static int unshare_namespace(unsigned lo
 }
 
 /*
- * Unsharing of sighand for tasks created with CLONE_SIGHAND is not
- * supported yet
+ * Unsharing of sighand is only supported for single-thread applications
  */
 static int unshare_sighand(unsigned long unshare_flags, struct sighand_struct **new_sighp)
 {
-	struct sighand_struct *sigh = current->sighand;
-
 	if ((unshare_flags & CLONE_SIGHAND) &&
-	    (sigh && atomic_read(&sigh->count) > 1))
-		return -EINVAL;
-	else
-		return 0;
+			atomic_read(&current->sighand->count) > 1) {
+
+		if (!thread_group_empty(current))
+			return -EINVAL;
+
+		*new_sighp = kmem_cache_alloc(sighand_cachep, GFP_KERNEL);
+		if (unlikely(*new_sighp == NULL))
+			return -ENOMEM;
+
+		atomic_set(&(*new_sighp)->count, 1);
+	}
+
+	return 0;
 }
 
 /*
@@ -1579,7 +1585,18 @@ asmlinkage long sys_unshare(unsigned lon
 	if ((err = unshare_semundo(unshare_flags, &new_ulist)))
 		goto bad_unshare_cleanup_fd;
 
-	if (new_fs || new_ns || new_sigh || new_mm || new_fd || new_ulist) {
+	if (new_sigh) {
+		sigh = current->sighand;
+		write_lock_irq(&tasklist_lock);
+		spin_lock(&sigh->siglock);
+		memcpy(new_sigh->action, sigh->action, sizeof(sigh->action));
+		rcu_assign_pointer(current->sighand, new_sigh);
+		spin_unlock(&sigh->siglock);
+		write_unlock_irq(&tasklist_lock);
+		new_sigh = sigh;
+	}
+
+	if (new_fs || new_ns || new_mm || new_fd || new_ulist) {
 
 		task_lock(current);
 
@@ -1595,12 +1612,6 @@ asmlinkage long sys_unshare(unsigned lon
 			new_ns = ns;
 		}
 
-		if (new_sigh) {
-			sigh = current->sighand;
-			rcu_assign_pointer(current->sighand, new_sigh);
-			new_sigh = sigh;
-		}
-
 		if (new_mm) {
 			mm = current->mm;
 			active_mm = current->active_mm;

  parent reply	other threads:[~2006-03-18 13:16 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-16 16:49 [PATCH] unshare: Cleanup up the sys_unshare interface before we are committed Eric W. Biederman
2006-03-16 17:31 ` [PATCH] unshare: Use rcu_assign_pointer when setting sighand Eric W. Biederman
2006-03-17  6:48   ` Paul E. McKenney
2006-03-17 17:44   ` Oleg Nesterov
2006-03-17 20:56     ` Andrew Morton
2006-03-18 13:12       ` Oleg Nesterov
2006-03-18 15:43         ` Janak Desai
2006-03-18 17:24           ` Oleg Nesterov
2006-03-18 17:41             ` [PATCH] for 2.6.16, disable unshare_vm() Oleg Nesterov
2006-03-18 18:10               ` Linus Torvalds
2006-03-18 18:29                 ` Ulrich Drepper
2006-03-18 18:48                 ` Janak Desai
2016-03-14 13:15             ` unshare(CLONE_VM) Re: [PATCH] unshare: Use rcu_assign_pointer when setting sighand Julian Smith
2016-03-14 18:35               ` Linus Torvalds
2006-03-18 13:13       ` Oleg Nesterov [this message]
2006-03-18 15:10       ` [PATCH] unshare: Error if passed unsupported flags Eric W. Biederman
2006-03-18 15:33         ` Janak Desai
2006-03-18 16:29       ` [PATCH] unshare: Use rcu_assign_pointer when setting sighand Janak Desai
2006-03-16 19:40 ` [PATCH] unshare: Cleanup up the sys_unshare interface before we are committed Michael Kerrisk
2006-03-16 20:33 ` Andrew Morton
2006-03-16 20:41   ` Linus Torvalds
2006-03-16 21:58     ` Eric W. Biederman
2006-03-16 22:19       ` Andrew Morton
2006-03-16 21:36   ` Janak Desai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=441C0774.C5FA688D@tv-sign.ru \
    --to=oleg@tv-sign.ru \
    --cc=ak@muc.de \
    --cc=akpm@osdl.org \
    --cc=ebiederm@xmission.com \
    --cc=hch@lst.de \
    --cc=janak@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mtk-manpages@gmx.net \
    --cc=paulus@samba.org \
    --cc=torvalds@osdl.org \
    --cc=viro@ftp.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).