Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp863206rwb; Fri, 7 Oct 2022 05:16:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4xvHpgVS4itWbboCJhRF/hkVXqvHYL2B2AhSVkPxZ+2AaxHditvK0Ql0gTV3C7enM+sHON X-Received: by 2002:a05:6402:5106:b0:451:787c:9fcc with SMTP id m6-20020a056402510600b00451787c9fccmr4321439edd.164.1665145011767; Fri, 07 Oct 2022 05:16:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665145011; cv=none; d=google.com; s=arc-20160816; b=kHZ1gK276D37CuTNNhyoZPCYV13oKVAk8ReeM+snHNXCRARqQ6KxqtIBukv3fM0lze AMlRohoRV4yVPtwicNaesr8N8naPuLOUkgkD4veTs5dcEGpRyyoN6ammXwHmNCCk4k4H VYRCWFj/I53h4cNE17ApqMf4qczeVe8mik3uG80+ypiybpBXvOgUUz0gZ121ODIDJVnk SwvIdNkF/3hb4cJlCCd9EMS4DLOsCc/l2R6UoJzbiPr2n3pAcZpwtifZmao0Ur9qTTVw 3KNz0r2iY2BmZcFkg5pxEX+ot+oqExMFaTyctgfLtzt8NWSP/A66IImm7onJnqx4tWOH unrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=oLOy/xmeOTHQXPaeUV2d54ZfFfc7wI0UtP28onV8inI=; b=fVsEKl3hjHP4pSFHKyUMyQpYK2HmiCFiUYatdUDiWCfQRqSL+qi+qdqLTbC7eRB7hL lvWclOfj/96T4btcFuzwUJ4x+TUOnIwsrBV6iIokcegLH93YY/Ve2WU1ymiCmdEEsqc8 nRzFFuAkXSUBVyUVMMvU9EiRxZPrdm1x2lKsCAL3DQfNvoY6ygqN2BxWgfL6foznv2RA LgzlldhijDM7dfvmGuV87ZWbaT4cQ2CT2EHno6xaE2fsM3IGSsymrPM8wIg+67ozSrIB cq9L8dIF+PO/IqLpLAIztoh4dfQM3eWUXmzEFF6SgYnoOLk9txubGKHkLnRhDXW3fP3O kT1Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e11-20020aa7d7cb000000b0045935adb5b1si1792061eds.395.2022.10.07.05.16.02; Fri, 07 Oct 2022 05:16:51 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229675AbiJGL6S convert rfc822-to-8bit (ORCPT + 99 others); Fri, 7 Oct 2022 07:58:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229581AbiJGL6Q (ORCPT ); Fri, 7 Oct 2022 07:58:16 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10F6CD57E6 for ; Fri, 7 Oct 2022 04:58:12 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-25-ABR5MNZQOUi4UB5yYMDNEA-1; Fri, 07 Oct 2022 12:58:08 +0100 X-MC-Unique: ABR5MNZQOUi4UB5yYMDNEA-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Fri, 7 Oct 2022 12:58:06 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.040; Fri, 7 Oct 2022 12:58:06 +0100 From: David Laight To: 'Theodore Ts'o' , Kees Cook CC: Jorge Merlino , Christian Brauner , Eric Biederman , Jann Horn , Alexander Viro , Thomas Gleixner , Andy Lutomirski , "Sebastian Andrzej Siewior" , Andrew Morton , "linux-mm@kvack.org" , "linux-fsdevel@vger.kernel.org" , John Johansen , Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley , Eric Paris , Richard Haines , Casey Schaufler , Xin Long , "David S. Miller" , Todd Kjos , Ondrej Mosnacek , Prashanth Prahlad , Micah Morton , Fenghua Yu , Andrei Vagin , "linux-kernel@vger.kernel.org" , "apparmor@lists.ubuntu.com" , "linux-security-module@vger.kernel.org" , "selinux@vger.kernel.org" , "linux-hardening@vger.kernel.org" Subject: RE: [PATCH] Fix race condition when exec'ing setuid files Thread-Topic: [PATCH] Fix race condition when exec'ing setuid files Thread-Index: AQHY2e33//tmcksZekaHt2mlO/Dtmq4C0tkw Date: Fri, 7 Oct 2022 11:58:06 +0000 Message-ID: References: <202209131456.76A13BC5E4@keescook> <202210061301.207A20C8E5@keescook> In-Reply-To: Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 From: Theodore Ts'o > Sent: 07 October 2022 02:41 > > On Thu, Oct 06, 2022 at 01:20:35PM -0700, Kees Cook wrote: > > > > So the question, then, is "why are they trying to exec while actively > > spawning new threads?" That appears to be the core problem here, and as > > far as I can tell, the kernel has behaved this way for a very long time. > > I don't think the kernel should fix this, either, because it leads to a > > very weird state for userspace, where the thread spawner may suddenly > > die due to the exec happening in another thread. This really looks like > > something userspace needs to handle correctly (i.e. don't try to exec > > while actively spawning threads). > > One of the classic failure modes is when a threaded program calls a > library, and that library might try to do a fork/exec (or call > system(3) to run some command. e.g., such as running "lvm create ..." > or to spawn some kind of helper daemon. > > There are a number of stack overflow questions about this, and there > are some solutions to _some_ of the problems, such as using > pthread_atfork(), and knowing that you are about to call fork/exec, > and use some out of band mechanism to to make sure no threads get > spawned until the fork/exec is completed --- but if you don't know > that a library is going to do a fork/exec, well, life is tough. Or that a library thread is about to create a new thread. > One technique even advocated by a stack overflow article is "avoid > using threads whenver possible". :-/ Doesn't fork() only create the current thread in the new process? So by the time exec() runs there is a nice single threaded process with an fd table that isn't shared. For helpers there is always (a properly implemented) posix_spawn() :-) David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)