From nobody Mon Mar 11 21:23:25 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 4TtqWf1ghPz5Dl70; Mon, 11 Mar 2024 21:23:26 +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 4TtqWd74CVz41RY; Mon, 11 Mar 2024 21:23:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1710192206; 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=6SwwY58pNv/P0YEuSyeAwo7fUXnLUGC3xdIbXLXmRiE=; b=csnBfIedYI7M+13UIq3jAU/73Vup+3Hi+Ij6QP4WZj6r8NE6xE4/53MOfjguj2G+j8tDg7 xZxL4gspQnbWWg/rlJ98GRjPhVw75vYUqoHjk9b6ksoYYeVaRjq+e3XNF+Sv63kOhoD7BE utKk6gTLCXDnfiYLP/slMUs5wDN/0ggwT9bZ8UyOnAGf541OHRUE8nKLd+M8a95236BO26 rMZh5/pkFu5STGuRsnB28lBEt9rUaLEOBPzdaTGccLB53C88PS4ycQ628SOashDULhpqPu 2LtUhXGzV/ZB0MAfKEuLNJaJU06R/APkJOI81yrJs5g8yegA2DTMKU95NYSFGA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1710192206; a=rsa-sha256; cv=none; b=TeRKCUd2N2vNLnw0XF0boU+MPICFHV0M/PBknjb5mY8sg1GoY53CHC0CcoNBeDVB1e9xO3 8ia08FHYJUdyRIpmdNMuWC/n1BMBTFghL4/ZXGf2UVvZDAzd+LUXidmZmQhAfUscpUGEj9 /LbEH0TiUofKiqPJrrqcjXRSUZ89yrOG7/dDfhSzd3CPHeUGE1ItNFrhFr+rD9KzPmf9ce ofnBzOVh3RlttQWlwmp2YTT75YTVvfpXN9SWsyYCvJIllID1Tn5QBPU3mBuPlFwrMXJ6rC z3VbYmcMbVz8ZKK/BDcxabeHXvNGkjgrEmu6w2vNKIrw1FOlx9SflBE/FqSj0Q== 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=1710192206; 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=6SwwY58pNv/P0YEuSyeAwo7fUXnLUGC3xdIbXLXmRiE=; b=x9kjdgejp97a/NqVHRrYi+89FVr53f0W6vWoMyTI5AmL61kfAS6S0g4JWvjnE+HRbi7kkU MDDDNL5V3cCan9Mr7/XsVFjPFovSP1ysQNGY/B8CzmgJndKVycBD7kZewq/8H3erPPHRo+ KGLWP0q+Thi4j1lE52RtRmWc8wB98gc2QVfhcUmU+N0iKR3xCdAO9f1njjX0rEGz5oEetj DG3VNm3KNkDSxQdKYS70zqlzBlBm6XQekntgHD/sQTSwIs1DyZFDvJ0Ib9BvVJuMFJnD46 NsYShOrLpPohD7tM/yaShubiUF6+mCSxUlpq9R3WnfMZQEVwKlnFWAgxwt1mCQ== 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 4TtqWd6gKtzmZZ; Mon, 11 Mar 2024 21:23:25 +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 42BLNPQi025578; Mon, 11 Mar 2024 21:23:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42BLNPOq025575; Mon, 11 Mar 2024 21:23:25 GMT (envelope-from git) Date: Mon, 11 Mar 2024 21:23:25 GMT Message-Id: <202403112123.42BLNPOq025575@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: d650c3efb638 - main - 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: 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/main X-Git-Reftype: branch X-Git-Commit: d650c3efb638f1b2742429a5fb8e7c087839868b Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=d650c3efb638f1b2742429a5fb8e7c087839868b commit d650c3efb638f1b2742429a5fb8e7c087839868b Author: Warner Losh AuthorDate: 2024-03-11 20:15:24 +0000 Commit: Warner Losh CommitDate: 2024-03-11 21:21:51 +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 --- 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); }