Re: [PATCH 1/2] unshare: Unsharing a thread does not require unsharing a vm

From: Eric W. Biederman
Date: Thu Aug 13 2015 - 12:34:37 EST


Oleg Nesterov <oleg@xxxxxxxxxx> writes:

> On 08/13, Eric W. Biederman wrote:
>> The only way killing CLONE_SIGHAND would be viable would be with a
>> config option. There are entire generations of linux where libpthreads
>> used this before CLONE_THREAD was implemented. Now perhaps no one cares
>> anymore, but there are a lot of historic binairies that used it, even to
>> the point where I know of at least one user outside of glibc's pthread
>> implementation.
>
> Heh. so we still need to keep it. Thanks.

Pretty much. It is possible to make this stuff go away when people stop
caring but it is a long process. I think I have almost killed
sys_sysctl. It seems to be disabled in most distributions.

>> Yes. A shared sighand_struct will have a shared ->mm. But a private
>> sighand_struct with count == 1 may also have a shared ->mm.
>
> Yes sure. This just means that we can check current_is_single_threaded()
> if CLONE_SIGHAND | CLONE_VM, signal->count check can be avoided.

As I pointed out in my follow we really can't because there is a case
where mm_users > 1 and sighand_count == 1. In which case using
current_is_single_threaded can cause unshare(SIGHAND) to fail.

>> So while I agree with you that the sighand->count could suffer a similar
>> fate as mm_users it does not.
>
> Ignoring the out-of-tree code ;)
>
> Nevermind, I won't really argue, this all is mostly cosmetic. And perhaps
> this sighand->count check in check_unshare_flags() makes this code look
> a bit better / more understandable.
>
> Still. How about the trivial *-fix.patch for -mm which simply does
>
> - if (unshare_flags & (CLONE_SIGHAND | CLONE_VM)) {
> + if (unshare_flags & CLONE_SIGHAND) {
> if (atomic_read(&current->sighand->count) > 1)
> return -EINVAL;
> }
>
> again, this doesn't really matter. To this "| CLONE_VM" looks
> very confusing to me.

Definitely cosmetic. This was my preserving of your flattened test
argument in around mm_users > 1 in check_unshare_flags().

It is unncessary given that we add CLONE_SIGHAND when CLONE_VM.
But to have a private mm_struct you definitely need a sighand_struct.

In the sense of document when these tests apply I think it makes a
teensy bit of sense to have the CLONE_VM there. But if you want to send
me a cosmetic patch that removes that I will add it to my tree, with the
other two patches.

Eric

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/