From nobody Fri Oct 09 00:20:46 2026 X-Original-To: dev-commits-src-branches@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 4j16vy4dBBz6Z2BH for ; Fri, 09 Oct 2026 00:20:46 +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 4j16vy2vqLz4LfF for ; Fri, 09 Oct 2026 00:20:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1791505246; 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=gUm2iZ4I3Hei7T8B5tPaoUKtxTTX9MU3QzkmKB82H1I=; b=M+s2kcWyALBRwgSdEfiMdADfhtF062LaPl3Uwk21wcO8xpF9HhuWBWX2zlPftxbxB4JpWD T4nLTKmW3Ys0FlCeDoayTiHlUB4tgDZlcloIHizSWT4XYCWQU5aKzETaTeCGfliFN8u36d 9kRMQ50pVtxe6f+2pKvix8ENU3Ls7FmTpRN84C+430HFdJGDLfKgWFEtCkGdPyqWVfRbbs cKWUKRZifMBLgZ4UI0HcWl7Kuprb3JIV+wL7bwpiP+VPkmU3bSV88Dr+VVUCuxLW02VAOs ZwBhxsmI/gDOMbLjBjbWYxhWTKbI89wSAqMqIbRZtwVeb4GG/s5TFPdcdLdlpQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1791505246; b=tvwTqT/Sv3Jla1cRiw6m6Z2y4ihLFxqvMIQ1K5DUpwCluKFG/2E3Bub1m+68d55xT+SLqu /RUGHucy54PkU/tXK7XVl9jln25c81FX90Iz1gRwVYF5dCZbRLWNeGDpf/CJ+2lnVdrXwm oe8ZXOLcBPgC19Z4jkBQnXgRRt7A5T7jlYcx6Brs0PHt4uv2nOSwKKFqpLV3INzz3/7ATM smz17a7Y10yxlPNFoTx1rhUL4DLHcYRbxmWzn5y8oVwjFJWgebFXChZ/8baxOiRWH+GN8c K4IU0d7zxH14mXHbIsIy8osQtwZ/JlH5IqCDv5w4XTcmC+YZ2LKkOycw3/WmKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1791505246; 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=gUm2iZ4I3Hei7T8B5tPaoUKtxTTX9MU3QzkmKB82H1I=; b=t/gtjfI9c/KldorJlbIF3K0d/mdmV+kKbqs7tzbYJTwbI9oLM6g58L9LqjzFP0yQmsDWsi wiAScXy01HKuWOaRQgz5cveRpU1XXz+AjV4O+OZWNtcza1EebgTIracgG0tmglFMazgzuv xgOuCM6vsyq1Dgc3HxDv9QCxA88qR/a+KGBzu3nyQIzM9N6ESfIdRpmvBugAshIxCgIIaY lYVyDGxuapAb0YzmeWoWhQxpE4MfJHzr4Jue2j860wuY261CEt1qC+PCH+9p294OdUdWvH 5tq/HoA/Ql+zl75AOA9ETRq977xx238mS3Kmt1qM64RLxLpUHRulh/hEN+JIkA== 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 4j16vy1yd2z12bx for ; Fri, 09 Oct 2026 00:20:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 19065 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 09 Oct 2026 00:20:46 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 1e6690a40729 - stable/14 - stand: Improve error handling when loading ELF files List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/14 X-Git-Reftype: branch X-Git-Commit: 1e6690a40729a469ccc5fe6ca3de819925cb78d9 Auto-Submitted: auto-generated Date: Fri, 09 Oct 2026 00:20:46 +0000 Message-Id: <6ac8335e.19065.4357d713@gitrepo.freebsd.org> The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=1e6690a40729a469ccc5fe6ca3de819925cb78d9 commit 1e6690a40729a469ccc5fe6ca3de819925cb78d9 Author: John Baldwin AuthorDate: 2026-07-31 17:51:37 +0000 Commit: John Baldwin CommitDate: 2026-10-08 18:41:24 +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 ec50f2970845..6d4cc5335bda 100644 --- a/stand/common/load_elf.c +++ b/stand/common/load_elf.c @@ -843,7 +843,6 @@ nosyms: if (module_verbose > MODULE_VERBOSE_SILENT) printf("\n"); - ret = lastaddr - firstaddr; fp->f_addr = firstaddr; php = NULL; @@ -906,25 +905,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)