From patchwork Fri Jan 3 15:54:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 103999 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3503A3858D38 for ; Fri, 3 Jan 2025 16:28:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3503A3858D38 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RC7ybN/3 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 320FC3858C2B for ; Fri, 3 Jan 2025 15:54:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 320FC3858C2B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 320FC3858C2B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1735919688; cv=none; b=puugO69DYBXJjjq1FnIFbKlRQVdUtmGhLL6LYACTb9IBeKLz9peHZYYRHrNPFnONbB7UW0qgIgi2rrysnySn5GpWumt2bVLwVk3hIwNgZCyQgJlf4kXDb2UMlaCe7CFK3kl7QlTLKdITuY9FVYF5h/lh9liKwnJk9YhR9XQ1jWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1735919688; c=relaxed/simple; bh=5iyHHfBJYcwPUcDhsa4jg379zYoC4EutwYuw6fjloBU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=LPoYDXUIstq/bJE0rXN/q7n7coX7+CUdXiNZiILkWHa48BxBCUPJrTHoEpIrWRmn2SxJqVMwnpLmOTcfq31f1BPrQ6zXeUipp5CxcrcJmsu2eDqrNUkihJznzuM5mzbJ3/GcKo39qsQCDcaMALPlN3bHPBfm2xUcGQCZ5g0vBs0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1735919679; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=fBl8ws9vXynJ1njcg1+aqAuBe2EFNAWH/7+BeV2MhTU=; b=RC7ybN/3gyWsQ9SOPITCS6pJgkuLADR4f6R6RF9/HXY/ZtP3G5oIZRWPKmoGPdhGeUZX9u /UhP17O2SyRfZHOobV3fmxYEzGw0mi3UH8nqKILzZ0H5RQWwpijUOmDQcI8CNsgbsHpJDn V2FtlsfrPdRdAT8m4bK1djdhjIJ2O6k= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-418-XQzdpaHlMWuSnOLg9Dz0ZQ-1; Fri, 03 Jan 2025 10:54:38 -0500 X-MC-Unique: XQzdpaHlMWuSnOLg9Dz0ZQ-1 X-Mimecast-MFC-AGG-ID: XQzdpaHlMWuSnOLg9Dz0ZQ Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B523B1956048 for ; Fri, 3 Jan 2025 15:54:37 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.2]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EB0BE1956088 for ; Fri, 3 Jan 2025 15:54:36 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH] x86_64: Reset TID in TCB on clone that does not use CLONE_VM Date: Fri, 03 Jan 2025 16:54:34 +0100 Message-ID: <87jzbblwp1.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 6IR45yqRYZD9TuC6LFiB9EoJrOQ0vNbTKPkB9H_39Pk_1735919677 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org This eliminates a TCB layout dependency from the Chromium sandbox. (Chromium checks the TID in a private field in a recursive mutex and only tries to patch the TCB if the TID found there is different from the value it obtains via gettid.) Tested on x86_64-linux-gnu. Confirmed to un-break Google Chrome. --- sysdeps/unix/sysv/linux/x86_64/clone.S | 12 ++++++++++++ 1 file changed, 12 insertions(+) base-commit: cc74583f23657515b1d09d0765032422af71de52 diff --git a/sysdeps/unix/sysv/linux/x86_64/clone.S b/sysdeps/unix/sysv/linux/x86_64/clone.S index f3985e7f71..67a30405a2 100644 --- a/sysdeps/unix/sysv/linux/x86_64/clone.S +++ b/sysdeps/unix/sysv/linux/x86_64/clone.S @@ -23,6 +23,9 @@ #include #include +/* Neither nor are usable in assembler files. */ +#define CLONE_VM 0x00000100 + /* The userland implementation is: int clone (int (*fn)(void *arg), void *child_stack, int flags, void *arg, pid_t *parent_tid, void *tls, pid_t *child_tid); @@ -94,6 +97,15 @@ L(thread_start): the outermost frame obviously. */ xorl %ebp, %ebp + /* If a fork-style clone is performed, reset the TID in the TCB. + Without CLONE_VM, the TID is not shared and safe to re-use. */ + test $CLONE_VM, %edi + jnz 1f + movl $SYS_ify(gettid), %eax + syscall + movl %eax, %fs:TID +1: + /* Set up arguments for the function call. */ popq %rax /* Function to call. */ popq %rdi /* Argument. */