Bug 292811 - sys/kern/imgact_elf.c:2722:18: error: variable 'structsize' is uninitialized when passed as a const pointer argument here
Summary: sys/kern/imgact_elf.c:2722:18: error: variable 'structsize' is uninitialized ...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 16.0-CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: Mark Johnston
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-01-29 19:14 UTC by Wolfram Schneider
Modified: 2026-04-16 16:49 UTC (History)
2 users (show)

See Also:


Attachments
Initialize structsize to 0 in note_procstat_auxv (350 bytes, patch)
2026-04-06 07:09 UTC, Giorgi Tchankvetadze
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Wolfram Schneider freebsd_committer freebsd_triage 2026-01-29 19:14:33 UTC
I tried to run `make buildkernel' with clang21 on macOS. I get the error:

--- imgact_elf.o ---
sys/kern/imgact_elf.c:2722:18: error: variable 'structsize' is uninitialized when passed as a const pointer argument here
[-Werror,-Wuninitialized-const-pointer]
 2722 |                 sbuf_bcat(sb, &structsize, sizeof(structsize));

clang21 is right, it is not a good idea to copy an uninitialized local int variable.
Comment 1 Giorgi Tchankvetadze 2026-04-06 07:09:07 UTC
Created attachment 269403 [details]
Initialize structsize to 0 in note_procstat_auxv

The attached patch resolves the uninitialized variable warning and prevents potential stack data leakage into ELF notes.
Comment 2 Giorgi Tchankvetadze 2026-04-06 07:12:44 UTC
(In reply to Wolfram Schneider from comment #0)

Can confirm this issue is still present on 16.0-CURRENT. I hit this exact same build failure while cross-compiling on Fedora Linux. Initializing the variable to 0 solved the issue
Comment 3 commit-hook freebsd_committer freebsd_triage 2026-04-08 14:04:54 UTC
A commit in branch main references this bug:

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

commit 8a68c2509c00ae0dbeab64064bb600cfac787a73
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2026-04-08 04:19:56 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-04-08 14:04:29 +0000

    imgact_elf: Unconditionally initialize a variable in a note handler

    In the sb == NULL case, we are computing the size of the note using a
    dummy sbuf drain handler which counts bytes and discards the contents of
    the buffer, so the fact that "structsize" is uninitialized doesn't
    matter.  But, the compiler may complain about this, so we might as well
    just initialize it unconditionally to silence the warning, as other
    handlers already do.

    PR:             292811
    MFC after:      1 week

 sys/kern/imgact_elf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Comment 4 commit-hook freebsd_committer freebsd_triage 2026-04-16 15:57:47 UTC
A commit in branch stable/15 references this bug:

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

commit 1379cde85f6177fa457aec9bd7a100424a990a60
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2026-04-08 04:19:56 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-04-16 15:56:26 +0000

    imgact_elf: Unconditionally initialize a variable in a note handler

    In the sb == NULL case, we are computing the size of the note using a
    dummy sbuf drain handler which counts bytes and discards the contents of
    the buffer, so the fact that "structsize" is uninitialized doesn't
    matter.  But, the compiler may complain about this, so we might as well
    just initialize it unconditionally to silence the warning, as other
    handlers already do.

    PR:             292811
    MFC after:      1 week

    (cherry picked from commit 8a68c2509c00ae0dbeab64064bb600cfac787a73)

 sys/kern/imgact_elf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Comment 5 commit-hook freebsd_committer freebsd_triage 2026-04-16 16:48:54 UTC
A commit in branch stable/14 references this bug:

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

commit 62fbb17e0dd03ece12e3e4baad5d0c65bdbde3da
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2026-04-08 04:19:56 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-04-16 16:48:20 +0000

    imgact_elf: Unconditionally initialize a variable in a note handler

    In the sb == NULL case, we are computing the size of the note using a
    dummy sbuf drain handler which counts bytes and discards the contents of
    the buffer, so the fact that "structsize" is uninitialized doesn't
    matter.  But, the compiler may complain about this, so we might as well
    just initialize it unconditionally to silence the warning, as other
    handlers already do.

    PR:             292811
    MFC after:      1 week

    (cherry picked from commit 8a68c2509c00ae0dbeab64064bb600cfac787a73)

 sys/kern/imgact_elf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)