From nobody Tue Jan 02 01:13:11 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 4T3vx41fVzz562tT; Tue, 2 Jan 2024 01:13:12 +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 4T3vx41173z3Zyl; Tue, 2 Jan 2024 01:13:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704157992; 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=yBew6MCXAk8uqMOZK4Ua2/o8MSAXjWulDP3s3Jfc4o8=; b=Jn4yeDJ1znl/+6ZEy9UxiG+F7Bwf8xrq6su2N8SzOZtZjpX7pNuSruZ6IZr4TqxRLVv8Eo oTPwMUjUznp+l3CtF9qrmUAueqRSq6wcOwJaCxuRhvJuB2/ZfEQsNMrJC9L998UIpvgNUa ppM/AIctSOT+JasS83gZDeNv9Q28zAHvWp63yp4aCLmLO4JIJ1CtnCQe0rO+2q5D/EhJGq Hv4jsi5Ia3BBpTsL4cnyrLxuuMzGQOPJeUraY8u78FhOJtzDlRnJ1JE5LPtxx+OA9ShO23 iP8KCa66udGXKa7jo1at1z56dcTF5t4qWYjwrCDw7qTD+ix//gaE01rFtxiyZA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704157992; a=rsa-sha256; cv=none; b=OeZc8OVo/pyXrnYbLDR29cgIQUghzEHbCM8/kHgXk8b2+3Wn4mX3DhMZR7QtF0c3Is3eBH 4FIiRlypMrP8AqtF5rtxai3CD829Zmb8sAUekK9wlWNEfZ2YEIHjP4xVXzGrL/WMtqa88v mAZQwnxIDzpbDEilggE04m87kcI5x53/7pdkVBzYAMevTPnbIzbLVb4+3DZ5M1jpjXmdTy 7ScnBNFa3OBLO0HdXMoib8CfG1TXyUFdV5W+G5BO6ll06OvqlvbbdVvOQDzFnRafn3Df7E NjDIQUXbZyrgabAhjwhIFIbxBxc/U79PRZLmwx2OAiKGFpONyT8T8kyYC1lTXQ== 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=1704157992; 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=yBew6MCXAk8uqMOZK4Ua2/o8MSAXjWulDP3s3Jfc4o8=; b=bZzu6xdv23/bRAPeb08osSFCPgDaHlALourMNu+f7KvH3EklColWBSGbOCN+moRzR5eY2+ v55gYNV3bo9Ke2gKvuKH9/UD/l+ZKU6ep1XErrApTX4J2TeDQ2KgUejvRnnvt34JoUbgD4 hjCsQIOUlCNuNTT1cA34qHjhVNQy/GMr3YyAtPpsSK6M0j/7F0Ns3Ehi2ca6ePwsZ8LQLa 1AfAH90eV52AWnAzJ5EX1n3rIiJ0SIrYL5+/mkm+B8vXrvhHuKAEYsms4hoJcQsJb8I5Si u3wK9Ss8h+TrH/DO3oLtXgAZSuzKrpo0o0qoikiZec/XSrhEfDE5ybkYmf4qvA== 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 4T3vx406BWzgtJ; Tue, 2 Jan 2024 01:13:12 +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 4021DB6D055338; Tue, 2 Jan 2024 01:13:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4021DBcb055335; Tue, 2 Jan 2024 01:13:11 GMT (envelope-from git) Date: Tue, 2 Jan 2024 01:13:11 GMT Message-Id: <202401020113.4021DBcb055335@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: c69e922c6217 - stable/13 - gntdev: Handle errors from suword32() in gntdev_alloc_gref() 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: c69e922c6217717a2ab55215f10f8d6ffd34c2f0 Auto-Submitted: auto-generated The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=c69e922c6217717a2ab55215f10f8d6ffd34c2f0 commit c69e922c6217717a2ab55215f10f8d6ffd34c2f0 Author: Mark Johnston AuthorDate: 2023-12-26 01:42:58 +0000 Commit: Mark Johnston CommitDate: 2024-01-02 01:12:45 +0000 gntdev: Handle errors from suword32() in gntdev_alloc_gref() Try to copy out output values before handling errors, and check that we did so successfully. In particular, it doesn't seem sensible to ignore errors here, otherwise userspace won't have any way to refer to the allocations. This is in preparation for annotating copyin() and related functions with __result_use_check. Reviewed by: royger MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D43145 (cherry picked from commit 6cdff09c0d70f780a738dbd3d87deb3b13ec8446) --- sys/dev/xen/gntdev/gntdev.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sys/dev/xen/gntdev/gntdev.c b/sys/dev/xen/gntdev/gntdev.c index f40a5b2578ec..81c965c54ae5 100644 --- a/sys/dev/xen/gntdev/gntdev.c +++ b/sys/dev/xen/gntdev/gntdev.c @@ -384,6 +384,13 @@ gntdev_alloc_gref(struct ioctl_gntdev_alloc_gref *arg) } } + /* Copy the output values. */ + arg->index = file_offset; + for (i = 0; error == 0 && i < arg->count; i++) { + if (suword32(&arg->gref_ids[i], grefs[i].gref_id) != 0) + error = EFAULT; + } + if (error != 0) { /* * If target domain maps the gref (by guessing the gref-id), @@ -402,11 +409,6 @@ gntdev_alloc_gref(struct ioctl_gntdev_alloc_gref *arg) return (error); } - /* Copy the output values. */ - arg->index = file_offset; - for (i = 0; i < arg->count; i++) - suword32(&arg->gref_ids[i], grefs[i].gref_id); - /* Modify the per user private data. */ mtx_lock(&priv_user->user_data_lock); for (i = 0; i < arg->count; i++)