From nobody Thu Oct 08 20:43:58 2026 X-Original-To: dev-commits-src-all@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 4j125q4DK7z6wCqv for ; Thu, 08 Oct 2026 20:43:59 +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 "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4j125q1NJGz4bwd for ; Thu, 08 Oct 2026 20:43:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1791492239; 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=iEjf5Pb68YDbrYasyaDIUBzjvODODnWbstz5JEbWyl0=; b=DK/F9/+YkxqlkBKbhGyGvQhLnSsxkWbea24mEE1Y5phjU+UdBXOPX806cAHDrbOgQDNJq5 emAZEPyhc1ivXuf8hN8U61/85P7eKw1pyYbT/lbYSVJRVSNj19oMLvFdpQOHW+PFBJ7PSq AVkF58AlVBcW+o6U2HRvx0fbghKoQjk3ULm+WTmPiBfM+rIopTfiTYqflJ6AdmwdlwC3Jt oOQBhkBfkWkXVMEQjJK/FL4ruWGoK1sknhr45D7vrM+y3CWAoc0+swRhS6H5d7MA9K9P6+ nDMcLohVryKva75vqle3SEpm4v6UTR+PPYb5p0pJq7oGWNW/EU2JROAwccNCEw== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1791492239; b=owsFbmWb0fd6OYNXIV7OLM/qgD1AjDyFTVEFltIQ3wlARXiMRKgSQJwZbHJyOiRVnE7V7+ f3tMjFvlj50mY4DBZyRyEYkc8oziCN9Pr8/Sj37TuEaTFvYdtN+2ckmaZGKHKficGZyxZL eMf+jcVzNTOR5DOAwHMrxVZhEhoTeorPxXkMH2g8dbbjaPp0dGI2BEGVF7FHnsGuisBzPA 76EmBOmiMWJarOzKthIsjB5Mu/jBw4u8NVbtQ2BiOSRtRubuQtb3Ft46ARvEtWIJHZHfEA 0tCg4VaHQstnLSu7J2iyN+9eTZHqa4vEIRNb7mC0UentV2TScI3VwWiNnDh1zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1791492239; 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=iEjf5Pb68YDbrYasyaDIUBzjvODODnWbstz5JEbWyl0=; b=ZURsEbU2RrqKLoYAJHMsk9qJInqsOQaNcYEXaqJAE3wXdBROYJ+q7zB1Di1J6l+1gGcd56 SMXl69/n25e9nup1m7xxnFyA4iZai2a8X+iaf+A5QQtxrP557eqm7KsfTi05ruA9gNB0OP vc1zXeUVZDzQYnz1e+021eXLEcDX5tgH4C9q4epJexzV1yrCgz6ddZfOrEFgjGvnvxlBHU VPxmjMSBaF1Z+zpwfCr+e5z9uwiz+6iz3mtT9YZRg7XiLX8HHyUf0T1oKzHl+YwdECrdaw SP2i7Oxg3OV0X6n9LDsJe6p/A204NbQ3B4C0f5KlW0c93xeEYnf6cqhPf4Tq+A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4j125p6rnhzwRq for ; Thu, 08 Oct 2026 20:43:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 320f2 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 08 Oct 2026 20:43:58 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: d2521a4f31da - stable/15 - stand: Improve error handling when loading ELF files List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/stable/15 X-Git-Reftype: branch X-Git-Commit: d2521a4f31da47e1d460dbbf0665c741ee8b9843 Auto-Submitted: auto-generated Date: Thu, 08 Oct 2026 20:43:58 +0000 Message-Id: <6ac8008e.320f2.18630588@gitrepo.freebsd.org> The branch stable/15 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=d2521a4f31da47e1d460dbbf0665c741ee8b9843 commit d2521a4f31da47e1d460dbbf0665c741ee8b9843 Author: John Baldwin AuthorDate: 2026-07-31 17:51:37 +0000 Commit: John Baldwin CommitDate: 2026-10-08 20:42:32 +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 (cherry picked from commit 80ee17c0285e5520e9c1db6760e84b7727778df5) --- 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 786748c940bb..3db513435271 100644 --- a/stand/common/load_elf.c +++ b/stand/common/load_elf.c @@ -837,7 +837,6 @@ nosyms: if (module_verbose > MODULE_VERBOSE_SILENT) printf("\n"); - ret = lastaddr - firstaddr; fp->f_addr = firstaddr; php = NULL; @@ -900,25 +899,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)