git: 5a67aaf1fa2c - stable/13 - kern: mountroot: avoid fd leak in .md parsing

Kyle Evans kevans at FreeBSD.org
Sun Aug 29 16:59:58 UTC 2021


The branch stable/13 has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=5a67aaf1fa2cc4757d1cd62560563dcc2b88bdfc

commit 5a67aaf1fa2cc4757d1cd62560563dcc2b88bdfc
Author:     Kyle Evans <kevans at FreeBSD.org>
AuthorDate: 2021-07-20 10:23:11 +0000
Commit:     Kyle Evans <kevans at FreeBSD.org>
CommitDate: 2021-08-29 16:58:24 +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.
    
    Sponsored by:   NetApp, Inc.
    Sponsored by:   Klara, Inc.
    X-NetApp-PR:    #62
    
    (cherry picked from commit 23ecfa9d5bc4f04eb58e26018c2d15f032d5d742)
---
 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 a34ae3fe06e3..4f80104c311c 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);
 }


More information about the dev-commits-src-all mailing list