From nobody Fri Jul 31 17:57:35 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hBYgh3Vb6z6nFR6 for ; Fri, 31 Jul 2026 17:57:36 +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 "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hBYgh1LJBz45tk for ; Fri, 31 Jul 2026 17:57:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1785520656; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FQ3X3QZscPCkk8PWtwCWybKgWuJzxbSQlCLjB1qMtB8=; b=jkhQBiDm9nc4RE5wgB6AcNiWlT8oWsIk/i3HVK/QAJi6nwdIMX9uATHkStcJtzZkvPwwX9 4p2zbEiDftVlZh+Ju8A5WDccSLZhCbAsvYvdMGTw5y3Si1E8+9CqjB6M3SqIZnUlqXShB+ LlZt2cdJqbuXuOI/jY6MHxxkgmhYb36B4hlhintN1E7NLvPX1vV+LsfteKaK4gL8oLEWEg TDkXA6gv0FBdF8rRbttgdFevG3/ObEcg+jru8t3fAA3feYuIjLrN09lNpDSNFnznHpIRkP TkRXc4g3GXKAYQVD7Xv3vP6pUL3W8RSVSyoKqzsAeSlju3t2yjxmfgn8AfghUg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785520656; a=rsa-sha256; cv=none; b=J/R8HLkU7I9nu94fyP9khIuO0Woxw63krZK1Iw6vRIvh5nLh79LDiy2KODUCLHYCSbTb3Z 2pAl+pPkJAEovF+1VE6kP+5ZN4Jra9BmHMYm7r5ruik6pP0Wh4gOz9iSRzLQaktcW1fc3x lSlSq4PEjvq7Hy3VYCak5GF2pt1U1vb4OJ4itI+a6qvaQZRxRT9C8BQvubxjGUJII2TIOr peQbPQ7C62YUf9QtXld8PQE+tQXLtx7of3ZljIyVEuq3NrC/f8ywBQ2YGPN7VJoWP8DdAy 8OGby63htjoN8saLB8kQrzchV4hzsm8AsnpXwy/23s6+gz2hrCCqrz0vudu+JA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1785520656; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FQ3X3QZscPCkk8PWtwCWybKgWuJzxbSQlCLjB1qMtB8=; b=Z52G81If/QYIhgrK2N5ydoawcJ3KjGKvADx32JcmyKGp7cTRVHggI6jt1R3rO0404xMW77 4QB2EWse3HOcAAMsnrK4Invgd1LyfSX7FW63I9N4MLDX6d72ZgdbGweTo+Eg8TJaN+Sgwv vxhZmlRK0+jdw7olQoQwtcgJjUbQmq28rJT2Ek4b6D4uwqpaeaR4chWETPMFmAZS3FmaLy K0gABlfab67hoz3gAtIQp+4xaXLU6lihoNtxMk0Q/mzSd5NUQQSmCV5K2QfrU8gzOTd6vU pZuXHPVARxm1wSAKdqlw+e/EVGGTs7qZto9+ZakUT7kDSe1Zk1ilVEP97Kv5xQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hBYgg5Hmzz1964 for ; Fri, 31 Jul 2026 17:57:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3f0c3 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 31 Jul 2026 17:57:35 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 80ee17c0285e - main - stand: Improve error handling when loading ELF files List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 80ee17c0285e5520e9c1db6760e84b7727778df5 Auto-Submitted: auto-generated Date: Fri, 31 Jul 2026 17:57:35 +0000 Message-Id: <6a6ce20f.3f0c3.5bbc2627@gitrepo.freebsd.org> The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=80ee17c0285e5520e9c1db6760e84b7727778df5 commit 80ee17c0285e5520e9c1db6760e84b7727778df5 Author: John Baldwin AuthorDate: 2026-07-31 17:51:37 +0000 Commit: John Baldwin CommitDate: 2026-07-31 17:51:37 +0000 stand: Improve error handling when loading ELF files Previously all the 'goto out' statements after the image was loaded into memory returned success rather than an error. This is despite comments indicating some of these conditions were in fact errors, and some of these error conditions (such as missing PT_DYNAMIC) are treated as errors in the kernel linker. In addition, when failing to looking up the symbols for the linker set, those cases returned failure leaking memory (though it's clear from the original code from commit ca49b3342d1e that only the second failure was intended to be an actual error). To avoid more confusion, move the assignment of `ret` to just before the `out` label so that `goto out` always returns an error. This is a more consistent pattern with other code in the tree that tends to use labels for the error case. Restructure some other code to avoid a few bogus errors. Specifically, a symbol table is not required so don't treat lack of a symbol table as an error. Also, if the start symbol for the module metadata linker set is not found, don't treat that as an error either. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D58540 --- stand/common/load_elf.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/stand/common/load_elf.c b/stand/common/load_elf.c index 97467094750c..14fc0893f088 100644 --- a/stand/common/load_elf.c +++ b/stand/common/load_elf.c @@ -838,7 +838,6 @@ nosyms: if (module_verbose > MODULE_VERBOSE_SILENT) printf("\n"); - ret = lastaddr - firstaddr; fp->f_addr = firstaddr; php = NULL; @@ -901,25 +900,28 @@ nosyms: break; } } - if (ef->hashtab == NULL || ef->symtab == NULL || - ef->strtab == NULL || ef->strsz == 0) - goto out; - COPYOUT(ef->hashtab, &ef->nbuckets, sizeof(ef->nbuckets)); - COPYOUT(ef->hashtab + 1, &ef->nchains, sizeof(ef->nchains)); - ef->buckets = ef->hashtab + 2; - ef->chains = ef->buckets + ef->nbuckets; - - if (__elfN(lookup_symbol)(ef, "__start_set_modmetadata_set", &sym, - STT_NOTYPE) != 0) - return 0; - p_start = sym.st_value + ef->off; - if (__elfN(lookup_symbol)(ef, "__stop_set_modmetadata_set", &sym, - STT_NOTYPE) != 0) - return 0; - p_end = sym.st_value + ef->off; + if (ef->hashtab != NULL && ef->symtab != NULL && + ef->strtab != NULL && ef->strsz != 0) { + COPYOUT(ef->hashtab, &ef->nbuckets, sizeof(ef->nbuckets)); + COPYOUT(ef->hashtab + 1, &ef->nchains, sizeof(ef->nchains)); + ef->buckets = ef->hashtab + 2; + ef->chains = ef->buckets + ef->nbuckets; + } - if (__elfN(parse_modmetadata)(fp, ef, p_start, p_end) == 0) - goto out; + /* Don't emit a warning if there is no symbol table. */ + if (ef->buckets != 0 && __elfN(lookup_symbol)(ef, + "__start_set_modmetadata_set", &sym, STT_NOTYPE) == 0) { + p_start = sym.st_value + ef->off; + if (__elfN(lookup_symbol)(ef, "__stop_set_modmetadata_set", + &sym, STT_NOTYPE) != 0) + goto out; + p_end = sym.st_value + ef->off; + + if (__elfN(parse_modmetadata)(fp, ef, p_start, p_end) != 0) + goto out; + } + + ret = lastaddr - firstaddr; out: if (dp)