From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id C5891385841E for ; Tue, 18 Apr 2023 20:49:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C5891385841E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681850963; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=awQMAy5TjCq6dlALJAZarrgYdlvjnbOA0p8w3xotV4k=; b=Cr6mQGiXOSpN6QjGAmKr2cBmJwGTj5pmL1VYzK9cMcqkFYWcFdHFdjm575S2O4I7pXYdjV PaYSByzyHbobudsEARww8uu8TqqjggwibEfX+4P37UL2QPodb/xo3rGlX5wt8kMWM/bpUe VmYwxPm5kmszYRRxcqRFmZ94MTkxwZc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-352-F_vYE9wcMuKvty1KjHIP_Q-1; Tue, 18 Apr 2023 16:49:20 -0400 X-MC-Unique: F_vYE9wcMuKvty1KjHIP_Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 101EE101A531; Tue, 18 Apr 2023 20:49:20 +0000 (UTC) Received: from redhat.com (unknown [10.2.16.177]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BE6491121314; Tue, 18 Apr 2023 20:49:19 +0000 (UTC) Date: Tue, 18 Apr 2023 15:49:17 -0500 From: Eric Blake To: Bruno Haible , cygwin@cygwin.com Subject: Re: posix_spawn facility Message-ID: References: <1752276.7aRn1RRit1@nimes> <5022555.upeRZZJTqa@nimes> MIME-Version: 1.0 In-Reply-To: User-Agent: NeoMutt/20230407 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, Apr 18, 2023 at 11:25:11AM +0200, Corinna Vinschen via Cygwin wrote: > Hi Bruno, > > On Apr 17 20:44, Bruno Haible via Cygwin wrote: > > Hi Corinna, Jumping in to this conversation a bit belatedly, but as someone on the Austin Group that can try to get an answer upstream... > But I'm not *that* happy with the change yet, for two reasons. > > First, the security risk outlined in > https://sourceware.org/bugzilla/show_bug.cgi?id=13134#c0 doesn't > actually exist on Cygwin, because we don't implement setuid/setgid > executables. You can set the mode bits, but they are not acted upon. The glibc bug points to the sample posix_spawn() implementation in POSIX XRAT - but that example implementation is non-normative and known buggy, so it is not safe to rely on it. Clarifying the wording in XRAT to explicitly mention that the example is NOT bullet-proof (and that implementations should do better) is probably worthwhile; I'll tackle that bug report. > > Second, the rational section in POSIX explains posix_spawn and > posix_spawnp, but it does *not* actually provide an example > implementation of posix_spawnp, only of posix_spawn. POSIX is silent as to whether posix_spawnp() has to fall back to 'sh' on ENOEXEC failure. The p suffix is indeed similar to execvp() (which DOES require a fallback to sh), but it could also just mean a PATH-search, and not the PATH-search-and-sh-fallback of execvp(). As we now have implementations in the wild that differ in behavior, and use security as a reason for the divergence, it is worth getting that clarified in POSIX. I'll file a bug against POSIX shortly, and reply again once it is up. My personal preference: sh fallback on ENOEXEC is useful in execvp(), but a bear to get right (see https://www.austingroupbugs.net/view.php?id=1645 where POSIX has a bug in requiring argv[0] to be the script's filename, which breaks busybox sh and is NOT what glibc does; meanwhile, musl intentionally does NOT do the sh fallback), so NOT doing it in posix_spawnp() would be reasonable; but we'll have to see what the rest of the Austin Group says. > > From the above bugzilla entry I take it that on glibc, both > functions tried to run the shell if the executable isn't recognized > (up to commits d96de9634a33 / 13adfa34aff). > > However, on Cygwin, only posix_spawnp does that,but not posix_spawn. > > In fact, I read the POSIX descriptions in terms of these functions quite > thoroughly, and at no point I see it mentioned that posix_spawnp shall > *not* work like exevlp/execvp. The crucial difference between posix_spawn > and posixc_spawnp is described in an interestingly vague way: > > posix_spawnp() interprets the second parameter more elaborately than > posix_spawn(). > > If I missed the point in the POSIX docs, please tell me. Yeah, it appears that POSIX is (accidentally) silent on whether posix_spawnp() has to do the sh fallback on ENOEXEC; but it seems quite reasonable that posix_spawn() being more like execle() must NOT do a sh fallback. > > So, again, the patch is simple. But it's kind of a pity that the change > in glibc has been made without a bigger discussion. Right now, it looks > like the glibc change to posix_spawn was correct, but the change to > posix_spawnp was arbitrary. > > Has anybody attempted to ask the Austin group to define this behaviour > in posix_spawnp more concise? Is there a protocel from the Austin > group? If not, wouldn't it be time to ask the Austin group? Doing that now ;) > > > Btw, there are two more functions in the posix_spawn family meanwhile: > > * posix_spawn_file_actions_addchdir_np > > implemented by glibc [1], musl libc, macOS, FreeBSD [2], Solaris ≥ 11.3 > > used by a few packages (Firefox, Chromium, Rust) > > * posix_spawn_file_actions_addfchdir_np > > implemented in glibc, musl libc > > but not used by any package so far [3]. > > > > The next POSIX will contain these functions (without the _np suffix).[4] > > Thanks for the pointers. I'm not sure I'll have the time to implement > them soon, but I put them on my list for 3.5.0. Patches welcome! > > > Thanks, > Corinna -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org