From nobody Tue Jan 02 00:37:30 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 4T3v7v0x4lz55ydZ; Tue, 2 Jan 2024 00:37:31 +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 4T3v7t5jBYz3J9q; Tue, 2 Jan 2024 00:37:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704155850; 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=gaKV74K/Hqi5XTuG5p2LSNdO/PGRytly7IGmsNPTvuA=; b=TaLR4t5D0x/jjFYRfQwNtxe3Lxpi/JGwVRdtFO36FDKVriqWFqkzDomn423i9dlHmrnN2j goxuC6ugldKC6Yz9v7sdn+ld4IIqjhvnx/E4ma35cFxkJ9GLGoqKeIH1XDy6xv+nEpjHVk l1k96WKyKAE10YAA4rft/yekp/5bFk/2fTq9Eh2oZoyNVAi2/v4RPlMvPiySxwXEo/Vzb3 etKQMbKFa9ErL293T2J7rgWleWQDq4hAFhK7O4Kv2+ELDuB8Aghw6tMf/ktROPS67Rq26a YF/Fn56snJT6HGiqMSPXHHc8V7qfGOSl+VLYPY9y7dOKAwfgyjbJ4YzSJTpyvg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704155850; a=rsa-sha256; cv=none; b=on6kwpe0072KM5ht/QV2Xujt/+PMLGTdQylICrc8UxxnECUTMYrSKBQltcT8icT/+v+ZQs D+/d/CGkwLPW02sW0rha6ApnRARBZ8DWI3u50sa15YkZd7nTeq3NC6G4akdDSqC65dCZ2D u6GzIR5reHDvVmNTcrRUjhZUNptBmuLRfSOn+nL3c7YlgObVVkpzPdLC2wKow0ORc6b44G YJzebiSreWY8hEnBmfeY4mGINETVYAYiECZtnaAdxKerlH38tF07nVRLMcXKXwOS53mFNh YxKwnN2kdh+P0URhZW1vDOL2X0Fs3IKxxoiwws+KaKAzr0h5ez4iLnDWpeIY0Q== 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=1704155850; 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=gaKV74K/Hqi5XTuG5p2LSNdO/PGRytly7IGmsNPTvuA=; b=kRACh9/MuihntHICmEd5SiCdX5FkyDsdDvyQYuqTQdZiznPAa/gmEpku6TkmsngunhaFcK bv2q/ugySN+GQ/ovfKFtYbhJTWNoaSSyHzDsb9CcOczmKUc6P7CfhVeurTMb35d6bdCVba mjCZ+v0IMVkYtPhZ+W6iEMACgMW6amR3mmzplsOsngnocItLHF01n+NW/zbfblJhpNip6V rQSRL2RIvZzykX4Bp/7OQsayAojke8Npb0fz1uWjB16rTvROAtjVlHwPZzmWydgVL9wR08 pO5Z2i5DuB5go1rfK+D2OakanTGKlNC1KsPqXJpSEtlZxlwWroiLyCHryt7P9w== 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 4T3v7t4nKkzfYN; Tue, 2 Jan 2024 00:37:30 +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 4020bUWc085742; Tue, 2 Jan 2024 00:37:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4020bUAi085739; Tue, 2 Jan 2024 00:37:30 GMT (envelope-from git) Date: Tue, 2 Jan 2024 00:37:30 GMT Message-Id: <202401020037.4020bUAi085739@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: 494fe2e050a6 - stable/14 - 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/14 X-Git-Reftype: branch X-Git-Commit: 494fe2e050a69455f33f76a365bd884f3a32842b Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=494fe2e050a69455f33f76a365bd884f3a32842b commit 494fe2e050a69455f33f76a365bd884f3a32842b Author: Mark Johnston AuthorDate: 2023-12-26 01:42:58 +0000 Commit: Mark Johnston CommitDate: 2024-01-02 00:29:56 +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 549917530f18..809afac75d0c 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++)