Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp3650085ybg; Sun, 7 Jun 2020 06:25:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzow7WcZDnc7O+HdEKc7kVEwn265p1WIdDSPJbpOt0ZnoALGZOpy8fXWeqHhuzYZEiw6lzZ X-Received: by 2002:a17:906:16d3:: with SMTP id t19mr16335473ejd.297.1591536313818; Sun, 07 Jun 2020 06:25:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591536313; cv=none; d=google.com; s=arc-20160816; b=KpUwNjZ0ijHNw8l75RXZz3DbmKrb5GCcZZ2deefkhq9eEOAoAjBVBfiMDupxELCg7N FinN+N3WovRGdZhtPJ8hkHU8C/uZuWNuzxyB9Wd3Lbyy8nFEz8MjqJMW2RDPXQ0g+8yT D/7K2paOe1eeesiv95oRrdEBpLvALYuWaj7/+TrrBPIO6/ikDNmIsLPWDnN2RYjUgu7/ Pxi0rx4nOPYixRwkwIPDDNGN6+avHxFmzDbxCOqfuGGsgnlRcsG8YnT1yhXnHVo0UuvM UARC1GcgVCPt0JIj56ZD919Az1yuYCCu+v4lvpCMU3R/XMWPyVf85biHFOaiMAq3fDpa Lorw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=qJgKJcJ5t3ffsReTUeTt8KoIHPaBrz+Px+Rs+T9ASFM=; b=y3ipR2oiIBgXqmTOJG+zntKOe0Y5xw/FWsFKq0lLJObgIiXlrnbsShOMrzuUmATc+w HHZcRBRgTEhsZAqHWNxgziXmN0Cu9r+8XEV/ej1tkAcCDmARe5psXRa52fmiiulj48ts cp0wlxgvgS+lsWBCjANYukmcOlPZimaKSh7juHSQhwti8+fT1n2+tmkBUmNhC4bvyuNy eDwMZqr901xKyjq/TnIo1KezdBDdYZQIA/7GY31YAZ/IWDwfXSCiMunsOc3TnfFMIZV1 tpLs6RE9Xl0NoppAmV8OvhmtkAgfcO1rInBvOd6R8xn+UPRb+fBHCan/4rOO6wWUZLab 1HOA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p18si6820252edm.288.2020.06.07.06.24.51; Sun, 07 Jun 2020 06:25:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726564AbgFGNWx convert rfc822-to-8bit (ORCPT + 99 others); Sun, 7 Jun 2020 09:22:53 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([146.101.78.151]:23674 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726465AbgFGNWw (ORCPT ); Sun, 7 Jun 2020 09:22:52 -0400 Received: from AcuMS.aculab.com (156.67.243.126 [156.67.243.126]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-157-dqJ-C61mOWemWDc1herPnQ-1; Sun, 07 Jun 2020 14:22:49 +0100 X-MC-Unique: dqJ-C61mOWemWDc1herPnQ-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) by AcuMS.aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Sun, 7 Jun 2020 14:22:48 +0100 Received: from AcuMS.Aculab.com ([fe80::43c:695e:880f:8750]) by AcuMS.aculab.com ([fe80::43c:695e:880f:8750%12]) with mapi id 15.00.1347.000; Sun, 7 Jun 2020 14:22:48 +0100 From: David Laight To: 'Szabolcs Nagy' , Christian Brauner CC: "torvalds@linux-foundation.org" , "linux-kernel@vger.kernel.org" , Kyle Evans , Victor Stinner , "viro@zeniv.linux.org.uk" , "linux-fsdevel@vger.kernel.org" , "linux-api@vger.kernel.org" , "fweimer@redhat.com" , "jannh@google.com" , "oleg@redhat.com" , "arnd@arndb.de" , "shuah@kernel.org" , "dhowells@redhat.com" , "ldv@altlinux.org" Subject: RE: [PATCH v5 1/3] open: add close_range() Thread-Topic: [PATCH v5 1/3] open: add close_range() Thread-Index: AQHWO0lrkRMjBAtF4kyptmA+TsanYKjNIo+Q Date: Sun, 7 Jun 2020 13:22:48 +0000 Message-ID: <46cd4282193641bf801fb150d482c624@AcuMS.aculab.com> References: <20200602204219.186620-1-christian.brauner@ubuntu.com> <20200602204219.186620-2-christian.brauner@ubuntu.com> <20200605145549.GC673948@port70.net> In-Reply-To: <20200605145549.GC673948@port70.net> Accept-Language: en-GB, en-US Content-Language: 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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Szabolcs Nagy > Sent: 05 June 2020 15:56 ... > currently there is no libc interface contract in place that > says which calls may use libc internal fds e.g. i've seen > > openlog(...) // opens libc internal syslog fd > ... > fork() > closefrom(...) // close syslog fd > open(...) // something that reuses the closed fd > syslog(...) // unsafe: uses the wrong fd > execve(...) > > syslog uses a libc internal fd that the user trampled on and > this can go bad in many ways depending on what libc apis are > used between closefrom (or equivalent) and exec. It is, of course, traditional that daemons only call close(0); close(1); close(2); Took us ages to discover that a misspelt fprintf() was adding data to the stdout buffer and eventually flushing 10k of ascii text into an inter-process pipe that had a 32bit field for 'message extension length'. FWIW isn't syslog() going to go badly wrong after fork() anyway? Unless libc's fork() calls closelog(). David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)