[Bug 274380] ctld -u segfaults if ctl.conf contains a chap section within a target

From: <bugzilla-noreply_at_freebsd.org>
Date: Mon, 09 Oct 2023 17:54:13 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=274380

            Bug ID: 274380
           Summary: ctld -u segfaults if ctl.conf contains a chap section
                    within a target
           Product: Base System
           Version: 15.0-CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: asomers@FreeBSD.org

When using the UCL configuration format, ctld segfaults if the configuration
file contains per-target chap settings.  This crash is observed on both
15.0-CURRENT and 13.2-RELEASE.

Stack Trace
===========

#0  uclparse_chap (auth_group=0x0, obj=obj@entry=0x2212d1a37940)
    at /usr/home/somers/src/freebsd.org/src/usr.sbin/ctld/uclparse.c:66
#1  0x0000014e7e066079 in uclparse_target (name=<optimized out>, 
    top=0x2212d1a37240)
    at /usr/home/somers/src/freebsd.org/src/usr.sbin/ctld/uclparse.c:762
#2  uclparse_toplevel (top=0x2212d1a371c0)
    at /usr/home/somers/src/freebsd.org/src/usr.sbin/ctld/uclparse.c:376
#3  uclparse_conf (newconf=newconf@entry=0x2212d1a320a0, 
    path=path@entry=0x14e7e050b3e "/etc/ctl.conf")
    at /usr/home/somers/src/freebsd.org/src/usr.sbin/ctld/uclparse.c:1007
#4  0x0000014e7e05b359 in conf_new_from_file (
    path=path@entry=0x14e7e050b3e "/etc/ctl.conf", oldconf=<optimized out>, 
    ucl=true) at /usr/home/somers/src/freebsd.org/src/usr.sbin/ctld/ctld.c:2719
#5  0x0000014e7e05a9d8 in main (argc=<optimized out>, argv=0x1569e170570)
    at /usr/home/somers/src/freebsd.org/src/usr.sbin/ctld/ctld.c:2804


Steps to Reproduce
==================

Create a /etc/ctl.conf file like this:
auth-group {
        myag {
                auth-type = none
        }
}
portal-group {
        pg0 {
                discovery-auth-group myag
                listen 0.0.0.0
        }
}
lun {
         example_1 { path = "/tmp/luns/lun.1" }
 }
 target {
         "iqn.2012-06.com.example:target1" {
                portal-group { name = pg0 }
                lun = [ { number = 1, name = example_1 } ]
                chap = [ 
                    {
                        user = "user_1"
                        secret = "secret_1"
                    }
                ]
        }
 }

Then start ctld like this:
# ctld -ut
Segmentation fault (core dumped)

-- 
You are receiving this mail because:
You are the assignee for the bug.