From patchwork Wed Nov 11 11:23:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arjun Shankar X-Patchwork-Id: 41015 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 40C7A398794B; Wed, 11 Nov 2020 11:23:35 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from aloka.lostca.se (aloka.lostca.se [178.63.46.202]) by sourceware.org (Postfix) with ESMTPS id D83383987917 for ; Wed, 11 Nov 2020 11:23:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D83383987917 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=lostca.se Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arjun.is@lostca.se Received: from aloka.lostca.se (aloka [127.0.0.1]) by aloka.lostca.se (Postfix) with ESMTP id 043A31C1BB for ; Wed, 11 Nov 2020 11:23:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=lostca.se; h=date:from:to :subject:message-id:mime-version:content-type :content-transfer-encoding; s=howrah; bh=nL109YyC02BPtMvgZuEZJVi VBxo=; b=AQkIG5WaIhryvywFwJ534oEEHMzXYy4XPQpOhwPWJedt9hX5aNVNoNB xX94hZdPOq554yUCEX+i2HVxljiZoSSZ3F71+wIN2Stc2IFEinjXISNYCSkiuyMW XsAuYx+/TKfZWUqrAYPrMIcvaFvwKz7ONlKaH5BuMnNUszY+fLMM= Received: from localhost (unknown [IPv6:2a01:4f8:120:624c::25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aloka.lostca.se (Postfix) with ESMTPSA id B6B6B1C1BA for ; Wed, 11 Nov 2020 11:23:30 +0000 (UTC) Date: Wed, 11 Nov 2020 11:23:30 +0000 From: Arjun Shankar To: libc-alpha@sourceware.org Subject: [COMMITTED] Use O_CLOEXEC in sysconf [BZ #26791] Message-ID: <20201111112329.GA16678@aloka.lostca.se> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" From: Maximilian Krüger If sysconf is used in multithreaded processes, various file descriptors may leak due to missing O_CLOEXEC. This commit adds the flag. --- This patch came in as a bug report. I have built and tested it on x86_64 and committed it to master since it is an obvious fix. sysdeps/unix/sysv/linux/sysconf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sysdeps/unix/sysv/linux/sysconf.c b/sysdeps/unix/sysv/linux/sysconf.c index 7958a74164..9c5a4cb1a4 100644 --- a/sysdeps/unix/sysv/linux/sysconf.c +++ b/sysdeps/unix/sysv/linux/sysconf.c @@ -81,7 +81,7 @@ __sysconf (int name) if (procfname != NULL) { - int fd = __open_nocancel (procfname, O_RDONLY); + int fd = __open_nocancel (procfname, O_RDONLY | O_CLOEXEC); if (fd != -1) { /* This is more than enough, the file contains a single integer. */