From nobody Tue Apr 16 20:13:33 2024 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 4VJwGP5htvz5H0j9; Tue, 16 Apr 2024 20:13:33 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VJwGP3Y5Kz4vTQ; Tue, 16 Apr 2024 20:13:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713298413; 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=LEP6hnKG4SbThO8whPzzOm9wdWcLzGSbCv0cN/UcKQU=; b=Kh4tA4EMalL2HuU8Nhe2ftcwXf5r2hC5QOvdOykHd8/oYSRuMzIvG9Zs4QRUxq5SxST+la BcVUBbrZm891iaEzdBaAX7a1XGRVUKqEqhtBF+0i9djf2c48hwsLdddTUWhD50v8ycYaDX X16ZRU/WkzDmds9ZAd0HVDYn3VbqbFAVqbfKiHnPk6H4OCL21m64unS8SFn/By9N0xLAki 64Ld32NV7rJDL7RCwD1j97Qggvun9v0UH2NFrv1Ers10UJg1fEFdrOSBGhroELh/vFUGX7 tS47letkBY5yl5CRB2cPQh0bp9wakMm72V9FNA5Tw+IEedSyYO9MwseJYTJwzg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1713298413; a=rsa-sha256; cv=none; b=OmUMTVFBC87zTIeteyrBD2OkJ+Z2I/eltAildhvgautIMrGT76d+nkqwvXxmRLePZj+Lk/ iiwbxsucKaUsuHqcJBgX7/OzdNXHsGBwoxKS3XXPRmZ1Hd2gsuUcmjqpxYbsAumRcM7DmZ nHJ4YTtucnTGO4Pekshjp3zH7IBt2sBzeBDThcww7hmTiLlD4Zi5rGEt/34Ctsck+uUqzD bZqI5MZ2Nl5R55xKxfeJazNrixtyU9hkYOj0WBb/Iu0HGOgUgGYxYybk5UiL3wz7jz73KL pchn0kJCERrc8iFMYJtW5zSnAavTwJuxnTmikBnYmnGXB5h9FpDDM0LriBVt8A== 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=1713298413; 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=LEP6hnKG4SbThO8whPzzOm9wdWcLzGSbCv0cN/UcKQU=; b=erq9sKxL5auggfCCnX3zytiXW9bVOjrXfOHwgZD4ZZs6Zxu78oJyv72kOVLjwh3BXYQh2E ZwDYpSvNDrr7hB74ZMMYw4xI6vJYUT18omAzIH1yd0zxnb3YJXtdbxSG4t4nD3FngnUslv DgqSWUcInohcnaowOIfD6V/oaQQ5gKK5PH+V7k2zk3Q/W7jwhxs4LIUdFK/f3VPvXynLXY YRiXRM+qAZ8S+A/lwI3P0uML73T20ChXlochGOR8g+McHv82poqEiZGtkvnLZKlmXpUsAj ny202INKGggXeg2JBqpH7RAPmf71a96sADg+/UkaUTgp2S5wD68wwsy7mHAOMA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VJwGP2trMzxdl; Tue, 16 Apr 2024 20:13:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 43GKDXNd039853; Tue, 16 Apr 2024 20:13:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43GKDXQw039850; Tue, 16 Apr 2024 20:13:33 GMT (envelope-from git) Date: Tue, 16 Apr 2024 20:13:33 GMT Message-Id: <202404162013.43GKDXQw039850@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: 519aef9045d0 - stable/14 - kboot: hostfs -- check for llseek failure correctly 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 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 519aef9045d00e0e2082d3096abef139b24623e9 Auto-Submitted: auto-generated The branch stable/14 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=519aef9045d00e0e2082d3096abef139b24623e9 commit 519aef9045d00e0e2082d3096abef139b24623e9 Author: Warner Losh AuthorDate: 2024-03-11 20:15:24 +0000 Commit: Warner Losh CommitDate: 2024-04-16 19:54:29 +0000 kboot: hostfs -- check for llseek failure correctly The host_* syscalls are all raw Linux system calls, not the POSIX wrappers that glibc / musl create. So we have to ranage change the return value of host_llseek correctly to use the negative value hack that all Linux system calls use. This fixes a false positive error detection when we do something like lseek(fd, 0xf1234567, ...); This returns 0xf1234567, which is a negative value which used to trigger the error path. Instead, we check using the is_linux_error() and store the return value in a long. Translate that errno to a host errno and set the global errno to that and return -1. lseek can't otherwise return a negative number, since it's the offset after seeking into the file, which by definition is positive. This kept the 'read the UEFI memory map out of physical memory' from working on aarch64 (whose boot loader falls back to reading it since there are restrictive kernel options that can also prevent it), since the physical address the memory map was at on my platform was like 0xfa008018. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D44286 (cherry picked from commit d650c3efb638f1b2742429a5fb8e7c087839868b) --- stand/kboot/kboot/hostfs.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/stand/kboot/kboot/hostfs.c b/stand/kboot/kboot/hostfs.c index 7c0600fc35a0..cfd3476b3c84 100644 --- a/stand/kboot/kboot/hostfs.c +++ b/stand/kboot/kboot/hostfs.c @@ -124,7 +124,7 @@ hostfs_seek(struct open_file *f, off_t offset, int whence) { hostfs_file *hf = f->f_fsdata; uint32_t offl, offh; - int err; + long err; uint64_t res; /* @@ -137,8 +137,15 @@ hostfs_seek(struct open_file *f, off_t offset, int whence) offl = res & 0xfffffffful; offh = (res >> 32) & 0xfffffffful; err = host_llseek(hf->hf_fd, offh, offl, &res, whence); - if (err < 0) - return (err); + /* + * Since we're interfacing to the raw linux system call, we have to + * carefully check. We have to translate the errno value from the host + * to libsa's conventions. + */ + if (is_linux_error(err)) { + errno = host_to_stand_errno(err); + return (-1); + } return (res); }