Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1350250rwi; Thu, 13 Oct 2022 12:24:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7e9fwgR4x7iaOD1ubAyERswIXAk5rWKxpqVwYF2NYM7crWVQgpmEJtvSZHmx1gJvFt2LTg X-Received: by 2002:a05:6a00:1bc3:b0:562:ab5f:af2 with SMTP id o3-20020a056a001bc300b00562ab5f0af2mr1138245pfw.58.1665689042408; Thu, 13 Oct 2022 12:24:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665689042; cv=none; d=google.com; s=arc-20160816; b=hEJBKoXOLdo2snhVVZDUHe9hNxatSwdGv/CgVux2YQJBlGxPorOR+IdROn8NmXpfl3 bCaB4ZBowRisVvmVJHyi87ioUemXdBfPN+LJdUJ/Hi6EvfU2Z1KtjW3hdOZt9Ug0J7d4 E0PJe1xAJAFB/qQs2BYc48DV8fGl4rwO4/tLXgnE1nzT0o+ORUgMyHUqDKkb7Rn4TEOz ZBWnI+F6+EuVkh6/QRUtM0iO+m1uHEV+1bTlybMeJn345X5HPfnHohotl1Bh6fwxevkt 8U4ygs3GNw6O7NMq2IP57y0BWPw/RVMmMtiP5UF7yqUXBfP2cxAokdqVNMnFvwQXq6YY k4kA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=8ev4pPnANTRpeGlWtdz4fwBlwIXvv8bPS1IfQVbJRl8=; b=X999mcU5P+UWYiZuoEJXjNkx9RFtjnLZZUSscs5pllEtRUovkmEPQuD+y8Gz0CYpNa FCg08RY3sc8lPEIF7+91/jbBuKJNb0hWsVgWwcgUGULR8WFk7NSPmeC66XH2Z3SMpVM/ ghEsqOaCxXd34FVipySbJQLczWg6PMkSnMG1jq5tb6O4Okwr2BsOZzO6CXstAmcaEVJ0 GbIqq/DOdSqDoZbLrx25KRKLPbh40SWCiEr314FVcyW6MjnKjv4jVX2CxpwfI8a+3he4 QCl5JOXo5g/lw36YyhnvGJFSmkQjpLDY74/dnBHdPgbbv/tjY4md0I40a+oz1ziyRynO /GKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=spEOO6U7; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b20-20020a170902b61400b0017a0e8713cesi466275pls.452.2022.10.13.12.23.50; Thu, 13 Oct 2022 12:24:02 -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=@google.com header.s=20210112 header.b=spEOO6U7; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229660AbiJMRqu (ORCPT + 99 others); Thu, 13 Oct 2022 13:46:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229751AbiJMRqr (ORCPT ); Thu, 13 Oct 2022 13:46:47 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8D9A144E2E for ; Thu, 13 Oct 2022 10:46:43 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id iv17so1664626wmb.4 for ; Thu, 13 Oct 2022 10:46:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=8ev4pPnANTRpeGlWtdz4fwBlwIXvv8bPS1IfQVbJRl8=; b=spEOO6U76Nh6i2+6RoX9Spc8ZrWUfpMBxYdZg71DhbEAxdLbP3OZ0lxY94eUlOO1pk i/2p78lMKLurk9qO/g7dEC28Z+ovo4pr0ykuK/9l+jUciDL+RVNbU2FFSlwUzmJJWpJi 6n/1XZ/bR+uMlXdjyNGJgoejGPsh0E3kkFnJCiImPKr1thc28I3CysJL2AVoZ3b77zuP iSqg7yPPekTQ6qo03HSD5rzjLm8Th92dlmRc6Ei3QIjVrlY78jlFsP2aqAP6UwAquPLS 3ScNR52QTymv8NTo2dcKAvJPtm2LxJQKZePuwYnyjAZvhBEBou9f5vB0txfCJRDOTIR1 UEzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8ev4pPnANTRpeGlWtdz4fwBlwIXvv8bPS1IfQVbJRl8=; b=i23XniWSYBV85IaR/SEYQKBePVewoD1AjZkanul7UvL6yPvChku7IpcEU+GFSdeekc blTyRfqxs9G6K7g5NlHWDxSUwX18S+qpw6a2LeJhmz0NYqSVXp08mLfKPktjiPwbtjf+ lmJ98nFnZi/wEwa0hyC0+yHtnDjU0t1p8DlXzaBB2SWzJSNxYRZD71YUhvC+efnCsuWs pM/yYXou9uCpjNkRESImk9iK6r14Bvek7zzEoRMstvAdRtnH/9UWRxbV/8n1rL+qC4Er +KrBWaI5W4nzXgU0AZ32c6Dv1DnGp1nHBOce5QlsbaEkXZtF6PZ5hoYf+zf5zPXnndVJ yTew== X-Gm-Message-State: ACrzQf1aU5W85Gibwte/AmSEnuUuyBDVqCb4Icav1nwiIrq9miehcUF9 6o/SoBNKUVmP/DRDMx9xOxETytLX+MjULtpjJLjbzg== X-Received: by 2002:a05:600c:310b:b0:3b4:c618:180d with SMTP id g11-20020a05600c310b00b003b4c618180dmr705289wmo.25.1665683202009; Thu, 13 Oct 2022 10:46:42 -0700 (PDT) MIME-Version: 1.0 References: <20220921003120.209637-1-avagin@google.com> <20220921003120.209637-2-avagin@google.com> <00ffd40b257346d26dfc0f03d144ec71@ispras.ru> In-Reply-To: <00ffd40b257346d26dfc0f03d144ec71@ispras.ru> From: Andrei Vagin Date: Thu, 13 Oct 2022 10:46:30 -0700 Message-ID: Subject: Re: [PATCH 2/2] selftests/timens: add a test for vfork+exit To: Alexey Izbyshev Cc: Kees Cook , linux-kernel@vger.kernel.org, Andrei Vagin , Christian Brauner , Dmitry Safonov <0x7f454c46@gmail.com>, "Eric W. Biederman" , Florian Weimer Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 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. Thanks, Andrei