diff options
Diffstat (limited to 'kernel/fork.c')
-rw-r--r-- | kernel/fork.c | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/kernel/fork.c b/kernel/fork.c index 05c02dc586b1..51f138a131de 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
@@ -683,11 +683,19 @@ fail_nomem: | |||
683 | 683 | ||
684 | static int copy_fs(unsigned long clone_flags, struct task_struct *tsk) | 684 | static int copy_fs(unsigned long clone_flags, struct task_struct *tsk) |
685 | { | 685 | { |
686 | struct fs_struct *fs = current->fs; | ||
686 | if (clone_flags & CLONE_FS) { | 687 | if (clone_flags & CLONE_FS) { |
687 | atomic_inc(¤t->fs->count); | 688 | /* tsk->fs is already what we want */ |
689 | write_lock(&fs->lock); | ||
690 | if (fs->in_exec) { | ||
691 | write_unlock(&fs->lock); | ||
692 | return -EAGAIN; | ||
693 | } | ||
694 | fs->users++; | ||
695 | write_unlock(&fs->lock); | ||
688 | return 0; | 696 | return 0; |
689 | } | 697 | } |
690 | tsk->fs = copy_fs_struct(current->fs); | 698 | tsk->fs = copy_fs_struct(fs); |
691 | if (!tsk->fs) | 699 | if (!tsk->fs) |
692 | return -ENOMEM; | 700 | return -ENOMEM; |
693 | return 0; | 701 | return 0; |
@@ -1518,12 +1526,16 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp) | |||
1518 | { | 1526 | { |
1519 | struct fs_struct *fs = current->fs; | 1527 | struct fs_struct *fs = current->fs; |
1520 | 1528 | ||
1521 | if ((unshare_flags & CLONE_FS) && | 1529 | if (!(unshare_flags & CLONE_FS) || !fs) |
1522 | (fs && atomic_read(&fs->count) > 1)) { | 1530 | return 0; |
1523 | *new_fsp = copy_fs_struct(current->fs); | 1531 | |
1524 | if (!*new_fsp) | 1532 | /* don't need lock here; in the worst case we'll do useless copy */ |
1525 | return -ENOMEM; | 1533 | if (fs->users == 1) |
1526 | } | 1534 | return 0; |
1535 | |||
1536 | *new_fsp = copy_fs_struct(fs); | ||
1537 | if (!*new_fsp) | ||
1538 | return -ENOMEM; | ||
1527 | 1539 | ||
1528 | return 0; | 1540 | return 0; |
1529 | } | 1541 | } |
@@ -1639,8 +1651,13 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags) | |||
1639 | 1651 | ||
1640 | if (new_fs) { | 1652 | if (new_fs) { |
1641 | fs = current->fs; | 1653 | fs = current->fs; |
1654 | write_lock(&fs->lock); | ||
1642 | current->fs = new_fs; | 1655 | current->fs = new_fs; |
1643 | new_fs = fs; | 1656 | if (--fs->users) |
1657 | new_fs = NULL; | ||
1658 | else | ||
1659 | new_fs = fs; | ||
1660 | write_unlock(&fs->lock); | ||
1644 | } | 1661 | } |
1645 | 1662 | ||
1646 | if (new_mm) { | 1663 | if (new_mm) { |
@@ -1679,7 +1696,7 @@ bad_unshare_cleanup_sigh: | |||
1679 | 1696 | ||
1680 | bad_unshare_cleanup_fs: | 1697 | bad_unshare_cleanup_fs: |
1681 | if (new_fs) | 1698 | if (new_fs) |
1682 | put_fs_struct(new_fs); | 1699 | free_fs_struct(new_fs); |
1683 | 1700 | ||
1684 | bad_unshare_cleanup_thread: | 1701 | bad_unshare_cleanup_thread: |
1685 | bad_unshare_out: | 1702 | bad_unshare_out: |