Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1557302rwi; Thu, 13 Oct 2022 15:53:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6VDiLwe7cyXEwo8Ha16k8kDSl4cW34otnIUW+9GMIK5lK+hJe5Dtooa6r16VjdlLakYb5N X-Received: by 2002:a63:ea43:0:b0:438:c056:3dc4 with SMTP id l3-20020a63ea43000000b00438c0563dc4mr1868586pgk.480.1665701603671; Thu, 13 Oct 2022 15:53:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665701603; cv=none; d=google.com; s=arc-20160816; b=xjBlntqhXrOeKRMQBAYWS9Fm6KBp8f6QmprQvjBsxqcfl+T+uQ9ZYmbBP9PNd6fbuR tJ9m9XuTeKv/T0iUSdGwLhra3NRn6C5GEk4PoMe6Y/fHZW699uTBS8rqYEq7W6hhfr3u avnhiM1i9/OMvEUuSHtLUTzpjUWT5tVLXUyvIx2f2s6dDnfkjEx3YAVyCPJ3vQhTXmvL 4uuwwSzsNM/c4I6lWumv3pBctgajY7rQBQYU0ufIFtoNr4zi0PNzpyM74Fcs2IRKzrP4 cHAWRdBJtKwC79K8h07X14HZztoigU8SO02JZL1z+oPLLhnQURVucwzQ21ZnTkdjiy6Z igGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:message-id:user-agent :references:in-reply-to:subject:cc:to:from:date:mime-version :dkim-signature:dkim-filter; bh=zW55gN1/6+8XP4kkPEapEF1AnUx4akoHzKRCGfyaIdo=; b=dC02SHBbtly3vF1V6DGsG9mwdEcom+jB0aO1gbJ3lQ3fUT40wWyvk5IKaAqePGhVMV Mle09L8OSI6yUH7cS2m1wn+Z1PgeV1okTrltQ9dC1xSwfpitNVR1XWOJ7ZFlK156Yq0t nN8wCAUGodbtgLH1P7S2FjiW5+DTLdbWvbbzyHgEP2lcE93QxZutD99w6UVnqPmQ7+ih sIlWXTKRDwAtSWGBdTqp3w5JbbWR3ZfGKLtoWPTfkNi44fYpwY7dtz1eXU6jQLtYGpJb FheBCXiXvPI/XVHaEVpcsJjgYlDA1Y8i05tMy6UE8ZDEGqcwV3pt3/+HGhurOwqjjigl c32Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=EqHOFwst; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q1-20020a056a00088100b0052b75c32fd2si843686pfj.48.2022.10.13.15.52.51; Thu, 13 Oct 2022 15:53:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=EqHOFwst; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229545AbiJMWPU (ORCPT + 99 others); Thu, 13 Oct 2022 18:15:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229462AbiJMWPR (ORCPT ); Thu, 13 Oct 2022 18:15:17 -0400 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF1D65A834 for ; Thu, 13 Oct 2022 15:15:14 -0700 (PDT) Received: from mail.ispras.ru (unknown [83.149.199.84]) by mail.ispras.ru (Postfix) with ESMTPSA id CF2B440D4004; Thu, 13 Oct 2022 22:15:09 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru CF2B440D4004 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1665699309; bh=zW55gN1/6+8XP4kkPEapEF1AnUx4akoHzKRCGfyaIdo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=EqHOFwstTXG4EcnbNLuoFt3KmBo16+7A/QRUptixHCj0clunGQepso1oPZY8FQpic v3QCELHjMV9Ny1fy78zPs8gohVBqkDwN6hTpU8gAPd1vDwIoj2Pddwin7Y/W1SA0MT H+VMEUchrQ9wglQoR3BN6Yty8EzH5roP3KVJdqcU= MIME-Version: 1.0 Date: Fri, 14 Oct 2022 01:15:09 +0300 From: Alexey Izbyshev To: Andrei Vagin Cc: Kees Cook , linux-kernel@vger.kernel.org, Andrei Vagin , Christian Brauner , Dmitry Safonov <0x7f454c46@gmail.com>, "Eric W. Biederman" , Florian Weimer Subject: Re: [PATCH 2/2] selftests/timens: add a test for vfork+exit In-Reply-To: References: <20220921003120.209637-1-avagin@google.com> <20220921003120.209637-2-avagin@google.com> <00ffd40b257346d26dfc0f03d144ec71@ispras.ru> User-Agent: Roundcube Webmail/1.4.4 Message-ID: <724cf9e4b07b7d25135f3f1427f1c9fc@ispras.ru> X-Sender: izbyshev@ispras.ru Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022-10-13 20:46, Andrei Vagin wrote: > On Sun, Oct 9, 2022 at 9:10 AM Alexey Izbyshev > wrote: >> >> On 2022-09-21 03:31, Andrei Vagin wrote: >> > From: Andrei Vagin > > > >> > + if (pid == 0) { >> > + char now_str[64]; >> > + char *cargv[] = {"exec", now_str, NULL}; >> > + char *cenv[] = {NULL}; >> > + >> > + // Check that we are still in the source timens. >> > + if (check("child before exec", &now)) >> > + return 1; >> >> I know this is just a test, but... >> >> Creating threads in a vfork()-child is quite dangerous (like most >> other >> things that touch the libc state, which is shared with the parent >> process). Here it works probably only because pthread_create() >> followed >> by pthread_join() restores everything into more-or-less the original >> state before returning control to the parent, but this is something >> that >> libcs don't guarantee and that can break at any moment. >> >> Also, returning from a vfork()-child is explicitly forbidden by the >> vfork() contract because the parent would then return to an invalid >> stack frame that could be arbitrarily clobbered by code executed in >> the >> child after main() returned. Moreover, if I'm not mistaken, on x86 >> with >> Intel CET-enabled glibc (assuming the support for CET is ever merged >> into the kernel) such return would cause the parent to always trap >> because the shadow stack will become inconsistent with the normal >> stack. >> Instead, _exit() should be used here... >> > > Hi Alexey, > > You are right, it isn't a good idea to create threads from the vfork-ed > process. Now, vfork isn't a special case in the kernel code, so I think > we can just remove the check() call from here. I have sent an updated > version of this patch, pls take a look at it. > Hi, Andrei, While I think you could just skip check_in_thread() in the vfork()-child instead of removing check() completely (the rest of the code in check() is unlikely to mess up the libc state), I agree that the test is still able to catch problems unconditionally affecting all CLONE_VM tasks thanks to check_in_thread() in the parent, so I don't see much point in holding it up further. Your v2 patch looks good enough to me, thanks! Alexey