From owner-dev-commits-src-main@freebsd.org Wed Jul 21 15:18:33 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 45D4E664DED; Wed, 21 Jul 2021 15:18:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GVK3Y1Fttz3Btg; Wed, 21 Jul 2021 15:18:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0E51320373; Wed, 21 Jul 2021 15:18:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 16LFIWrZ099860; Wed, 21 Jul 2021 15:18:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 16LFIWrf099859; Wed, 21 Jul 2021 15:18:32 GMT (envelope-from git) Date: Wed, 21 Jul 2021 15:18:32 GMT Message-Id: <202107211518.16LFIWrf099859@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 23ecfa9d5bc4 - main - kern: mountroot: avoid fd leak in .md parsing MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 23ecfa9d5bc4f04eb58e26018c2d15f032d5d742 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Jul 2021 15:18:33 -0000 The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=23ecfa9d5bc4f04eb58e26018c2d15f032d5d742 commit 23ecfa9d5bc4f04eb58e26018c2d15f032d5d742 Author: Kyle Evans AuthorDate: 2021-07-20 10:23:11 +0000 Commit: Kyle Evans CommitDate: 2021-07-21 15:18:09 +0000 kern: mountroot: avoid fd leak in .md parsing parse_dir_md() opens /dev/mdctl but only closes the resulting fd on success, not upon failure of the ioctl or when we exceed the md unit max. Reviewed by: kib (slightly previous version) Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. X-NetApp-PR: #62 Differential Revision: https://reviews.freebsd.org/D31229 --- sys/kern/vfs_mountroot.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sys/kern/vfs_mountroot.c b/sys/kern/vfs_mountroot.c index 65d52cc68bcd..48753b8c6a96 100644 --- a/sys/kern/vfs_mountroot.c +++ b/sys/kern/vfs_mountroot.c @@ -580,6 +580,7 @@ parse_dir_md(char **conf) int error, fd, len; td = curthread; + fd = -1; error = parse_token(conf, &tok); if (error) @@ -635,9 +636,9 @@ parse_dir_md(char **conf) root_mount_mddev = mdio->md_unit; printf(MD_NAME "%u attached to %s\n", root_mount_mddev, mdio->md_file); - error = kern_close(td, fd); - out: + if (fd >= 0) + (void)kern_close(td, fd); free(mdio, M_TEMP); return (error); }