Bug 292903 - libfetch: Segmentation fault when openssl.cnf has errors
Summary: libfetch: Segmentation fault when openssl.cnf has errors
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 16.0-CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: Dag-Erling Smørgrav
URL: https://reviews.freebsd.org/D55098
Keywords:
Depends on:
Blocks:
 
Reported: 2026-02-03 13:25 UTC by Miltiadis Margaronis
Modified: 2026-02-12 21:25 UTC (History)
2 users (show)

See Also:
des: mfc-stable15+
des: mfc-stable14+
des: mfc-stable13+


Attachments
patch to handle error return from SSL_CTX_new (530 bytes, patch)
2026-02-03 13:25 UTC, Miltiadis Margaronis
no flags Details | Diff
openssl.cnf which triggers the segfault (12.13 KB, text/plain)
2026-02-05 16:54 UTC, Miltiadis Margaronis
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Miltiadis Margaronis 2026-02-03 13:25:44 UTC
Created attachment 267734 [details]
patch to handle error return from SSL_CTX_new

When /etc/ssl/openssl.cnf cannot be parsed, SSL_CTX_new in common.c:1186 will return NULL, which will in turn cause a core dump later when SSL_CTX_set_mode attempts to access it.
The attached patch prints out the error message from OpenSSL and returns -1
Comment 1 Dag-Erling Smørgrav freebsd_committer freebsd_triage 2026-02-04 10:37:08 UTC
I'm unable to provoke a null return, but it doesn't hurt to check.
Comment 2 Miltiadis Margaronis 2026-02-04 11:44:28 UTC
You can trigger a NULL return by commenting out one of the sections.

In /etc/ssl/openssl.cnf you can comment out the openssl_init section and it will trigger the NULL return, because it is referenced above somewhere.
I guess the same applies to any of the file's sections.
Comment 3 Miltiadis Margaronis 2026-02-04 11:48:17 UTC
Here's output with and without the patch respectively:

$ LD_LIBRARY_PATH=/usr/obj/usr/src/amd64.amd64/lib/libfetch fetch http://www.usb.org/developers/devclass_docs/HID1_11.pdf
105004DFE4250000:error:0700007C:configuration file routines:CONF_modules_load:openssl conf references missing section:/usr/src/crypto/openssl/crypto/conf/conf_mod.c:163:openssl_conf=openssl_init
fetch: http://www.usb.org/developers/devclass_docs/HID1_11.pdf: Authentication error

$ fetch http://www.usb.org/developers/devclass_docs/HID1_11.pdf
Segmentation fault (core dumped)
Comment 4 Dag-Erling Smørgrav freebsd_committer freebsd_triage 2026-02-04 12:12:08 UTC
The question is, what did you do to your openssl.cnf to provoke this?  I tried an empty file, an unreadable file, and a readable file with various syntax errors, and none of them resulted in a null context.
Comment 5 Miltiadis Margaronis 2026-02-04 12:31:08 UTC
In my openssl.cnf, due to some etcupdate issue, one section, openssl_init, was missing.
This section is referenced by some line above:

openssl_conf = openssl_init

To fix my actual problem, I just added an empty openssl_init section. Literally just adding a line with
[ openssl_init ]
made it work.

To trigger the error to check the patch, I just change this line to
#[ openssl_init ]

and I get a coredump
Comment 6 Miltiadis Margaronis 2026-02-04 13:04:41 UTC
I emailed my openssl.cnf privately, I hope it helps.
Comment 7 Michael Osipov freebsd_committer freebsd_triage 2026-02-04 13:23:47 UTC
Obviously not observed: https://docs.openssl.org/3.6/man3/SSL_CTX_new/#return-values
Comment 8 Miltiadis Margaronis 2026-02-05 16:54:54 UTC
Created attachment 267822 [details]
openssl.cnf which triggers the segfault

openssl.cnf which causes the segmentation fault to happen.
It's the one in /usr/src/crypto/openssl/apps/openssl.cnf with 2 lines commented out:
#[openssl_init]
#providers = provider_sect
Comment 9 commit-hook freebsd_committer freebsd_triage 2026-02-07 14:25:24 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=4e160c6197f75fda3d5d5997ce893087058cf718

commit 4e160c6197f75fda3d5d5997ce893087058cf718
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-02-07 14:24:40 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-02-07 14:24:40 +0000

    libfetch: Check for failure to create SSL context

    * Drop the ssl_meth member, there is no reason to hang on to it.

    * Replace deprecated SSLv23_client_method() with TLS_client_method().

    * Check the return value from SSL_CTX_new().

    MFC after:      1 week
    PR:             292903
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D55098

 lib/libfetch/common.c | 10 +++++++---
 lib/libfetch/common.h |  1 -
 2 files changed, 7 insertions(+), 4 deletions(-)
Comment 10 commit-hook freebsd_committer freebsd_triage 2026-02-11 20:39:35 UTC
A commit in branch stable/15 references this bug:

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

commit d653f474e901b1d43657b8955247d1bbd1c3d248
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-02-07 14:24:40 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-02-11 13:54:39 +0000

    libfetch: Check for failure to create SSL context

    * Drop the ssl_meth member, there is no reason to hang on to it.

    * Replace deprecated SSLv23_client_method() with TLS_client_method().

    * Check the return value from SSL_CTX_new().

    MFC after:      1 week
    PR:             292903
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D55098

    (cherry picked from commit 4e160c6197f75fda3d5d5997ce893087058cf718)

 lib/libfetch/common.c | 10 +++++++---
 lib/libfetch/common.h |  1 -
 2 files changed, 7 insertions(+), 4 deletions(-)
Comment 11 commit-hook freebsd_committer freebsd_triage 2026-02-11 20:41:36 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=4781aeb5b9cb564a53fee8128f6827402deaf9df

commit 4781aeb5b9cb564a53fee8128f6827402deaf9df
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-02-07 14:24:40 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-02-11 13:54:41 +0000

    libfetch: Check for failure to create SSL context

    * Drop the ssl_meth member, there is no reason to hang on to it.

    * Replace deprecated SSLv23_client_method() with TLS_client_method().

    * Check the return value from SSL_CTX_new().

    MFC after:      1 week
    PR:             292903
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D55098

    (cherry picked from commit 4e160c6197f75fda3d5d5997ce893087058cf718)

 lib/libfetch/common.c | 10 +++++++---
 lib/libfetch/common.h |  1 -
 2 files changed, 7 insertions(+), 4 deletions(-)
Comment 12 commit-hook freebsd_committer freebsd_triage 2026-02-11 20:42:38 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=767f1ebcf75e85912b65f9a117c9ab4f76ce71c0

commit 767f1ebcf75e85912b65f9a117c9ab4f76ce71c0
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-02-07 14:24:40 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-02-11 13:54:33 +0000

    libfetch: Check for failure to create SSL context

    * Drop the ssl_meth member, there is no reason to hang on to it.

    * Replace deprecated SSLv23_client_method() with TLS_client_method().

    * Check the return value from SSL_CTX_new().

    MFC after:      1 week
    PR:             292903
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D55098

    (cherry picked from commit 4e160c6197f75fda3d5d5997ce893087058cf718)

 lib/libfetch/common.c | 10 +++++++---
 lib/libfetch/common.h |  1 -
 2 files changed, 7 insertions(+), 4 deletions(-)
Comment 13 commit-hook freebsd_committer freebsd_triage 2026-02-12 21:25:22 UTC
A commit in branch releng/14.4 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=53e0a1d1ff9b9a8bd27fa65e0f84ca95f0e41298

commit 53e0a1d1ff9b9a8bd27fa65e0f84ca95f0e41298
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-02-07 14:24:40 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2026-02-12 21:24:34 +0000

    libfetch: Check for failure to create SSL context

    * Drop the ssl_meth member, there is no reason to hang on to it.

    * Replace deprecated SSLv23_client_method() with TLS_client_method().

    * Check the return value from SSL_CTX_new().

    Approved by:    re (cperciva)
    MFC after:      1 week
    PR:             292903
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D55098

    (cherry picked from commit 4e160c6197f75fda3d5d5997ce893087058cf718)
    (cherry picked from commit 4781aeb5b9cb564a53fee8128f6827402deaf9df)

 lib/libfetch/common.c | 10 +++++++---
 lib/libfetch/common.h |  1 -
 2 files changed, 7 insertions(+), 4 deletions(-)