From nobody Tue Dec 26 02:04:30 2023 X-Original-To: dev-commits-src-main@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 4SzdPW2bXZz55Kr5; Tue, 26 Dec 2023 02:04: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 4SzdPV74n4z4Kfx; Tue, 26 Dec 2023 02:04:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703556271; 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=hYlxlI8hJHRt+DSZWDgsEuY/pCF5MVRL6Xt0NWhfFlY=; b=WQjrD64pbDZpH7vmecBO3ob5cWlgpou8TTOTdQqfxzEuSIcrmWMMwj6sO9vOM9pE6AZPjR q3kn0gYN7KP3HIb08i6AHcTvVG1YaP7/D4hKE0YhZ53HKUbAf2k4wo1wUDHnAWyNAHzPgj owXc9eonI5jD7meAuSiQv8aO7iT/Qrh9LB1BQrZuHkqao9Dh+j36SXY9jiR8ADvFd6HWhs RIJPE2TsF2d1700E1e/upgMPywfTyaQypiqllNtldR9BYUR/JkXkauJf3Hkyc1ZJoyo+/F 4EYHRUiuitxiHYQccvqgKRuEGVJ3SwU2ZVqsauUfho0A5WKPuBVV+xJyxnde1A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703556271; a=rsa-sha256; cv=none; b=L87/ewWdGowfaEnWtoXlW9l2OJYX93GluK2EuBhoKooLTdnYtwpdyjOynwZjGDToh69jBs NgHD1516nIY9ToLAmJeA2J1JgpmkaSdUxVSL8MzcTJ36wYbfvsL9i7L+sKqt3t/O7Q+iVw +MfsU9m+pLJNxFSXXCtM/CiU4BoCTFNGEI6PP/ZcCR1AOFHuPNKTX4PNCSMrV3bVYHPbuI FRjac0FZK9a8MGqxgeR89GTaXAqLYfUunU3pFmnXFcqcKQyG9gp6QvzPTUtUBBbQciv9pM HV8DacEU0jLWnIQJtyGw4DgJpLCnqDOWLjJkj2k+Vc7yppr7sGil0C678y/Aug== 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=1703556271; 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=hYlxlI8hJHRt+DSZWDgsEuY/pCF5MVRL6Xt0NWhfFlY=; b=d9S2A4h7h2k+WYp6cJW5anw2lzexT0X11cpAS758c9tOF9hErXE+dMl4KCuEUoESybHZXL SeNje6lCxCc0U3f5kHYdoE+kDfi6zAgLNHpppAsUAwER/2aLGcdmBGJrw0byRPlIs0cUmf k/9k6ZIuetfDD3NLQymcXE+jXsSt0Lhpv4OrrfQlbiWCAE1ANkrnNS45/wZ9buLb8G7Y2y QI9IuSpcSbTIHJjdC+BgygN2bvG7sNuGySJ40lHhK1ViBCipX55tgrcgUT5X0QX+IRRd8O 5MErFSWQt0tE6nI410Le4Q1jxWBMxkhqOKBnQS18fYeXJF+0fZlGcIDiUFK+Yw== 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 4SzdPV6Bd4zbW7; Tue, 26 Dec 2023 02:04: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 3BQ24Uig003506; Tue, 26 Dec 2023 02:04:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BQ24Umh003503; Tue, 26 Dec 2023 02:04:30 GMT (envelope-from git) Date: Tue, 26 Dec 2023 02:04:30 GMT Message-Id: <202312260204.3BQ24Umh003503@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 6cdff09c0d70 - main - gntdev: Handle errors from suword32() in gntdev_alloc_gref() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 6cdff09c0d70f780a738dbd3d87deb3b13ec8446 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=6cdff09c0d70f780a738dbd3d87deb3b13ec8446 commit 6cdff09c0d70f780a738dbd3d87deb3b13ec8446 Author: Mark Johnston AuthorDate: 2023-12-26 01:42:58 +0000 Commit: Mark Johnston CommitDate: 2023-12-26 02:04:01 +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 --- 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 a9b69ba1605e..4530feb1c76d 100644 --- a/sys/dev/xen/gntdev/gntdev.c +++ b/sys/dev/xen/gntdev/gntdev.c @@ -383,6 +383,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), @@ -401,11 +408,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++)