From nobody Tue Jan 02 01:13:08 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 4T3vx10XKtz563G3; Tue, 2 Jan 2024 01:13:09 +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 4T3vx05D5Hz3b5m; Tue, 2 Jan 2024 01:13:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704157988; 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=Wd3hXRLgtbu8po8HoRfa5gX45oQATf48UtmyWkVJRUw=; b=lrgLh9OPg63+ZlG20HGHcVz+qLWHCGI247sACOJpjmbqMplRKHLpChT+6hx12eLhupHtop 76pA5IiwhSgGVUY1FJLrDL11s/2H+hvnaRKxYI2A8MGdrNRtiF4pUY23hUa8nYyUfKNGHP BlLQNG28E94NCl0irueFSjPQUja3kAwpcYmZa8zbxj6MLRajty6CqmT1JbkLqw8n1jQ9kd mlSdZmV8IgX82QRmG5HH/zB6fCEQhoZeR87B5p4zDgZdg+F039ZYIZXRaCtmjEBc+gVDfw yocPkN4ftjokaj1hTpeG5TQH7ABh92t8vFlBo3gClpxy3Zr7FYdRBYPR2Z74zw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704157988; a=rsa-sha256; cv=none; b=eOv4RmtPSDqh+xO5Uo8nqfbdo0QIdvngfm/xI/wOWTvOaWhjl70VJRciSU9vGLm9lGzyQq sT+vacUBiMv8VvzcRqNWs4CpZ9Ut+bQs07jLRp4gtuxgG9NBQ2hpjichesdEdtsZZsoocv kl0ZyxVx74o4g/1So130ZzmGnn/Juwh/47RI8iF8Jtkpr/Q/Hiin4PKBUJGHjbJQdXD8bh Lrp8mecmWnp00vuHRO/bXXxjDrIvtnwTVgbTNeRGO5Z7KuDSpq6ZacdOjua74/wIwXog1p 6AjRiYPYe30rnNBz3ClFWDFeuXZOsIJwuqXl/EJ4qY97Ah3A/PCSlrnouTRCdg== 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=1704157988; 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=Wd3hXRLgtbu8po8HoRfa5gX45oQATf48UtmyWkVJRUw=; b=bZurk9+OR+pN9z6eDdXjLtPYDWCfA1b0yTaOxPDKh8X3WCNdZy4fpo3bnqq82iLKs2Ngvq dnz7KO/9/ZVIJ6Oq2zpQCao5WF3hr8C8rrdi7qPeFFfiZ34Cx7CxChcAEXWzqARMz/lBVx f2xuJZdNnoEdq8rjKztk+nN5cViwq5baGAlhvlWSv+gKSOZPcds8o1/KigYXHZZK+4lVQW GmxD6y6TD9dzNFgMc2ukGqKMzjGabhEJ8lyUDXFGoMsXRCLzULTShQCcK1w/Q6DvFxcXEw HUh19mG5C9GxjbUny+uB9SKSjs4BBw4ojWenL6deWqs7ueOtAlH3fQWtUmOqAw== 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 4T3vx04L8dzgtH; Tue, 2 Jan 2024 01:13:08 +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 4021D8Yn055184; Tue, 2 Jan 2024 01:13:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4021D8ii055181; Tue, 2 Jan 2024 01:13:08 GMT (envelope-from git) Date: Tue, 2 Jan 2024 01:13:08 GMT Message-Id: <202401020113.4021D8ii055181@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: 573bb4875b99 - stable/13 - umtx: Check for errors from suword32() 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: 573bb4875b9994054dbc00218a3f08763af56c9e Auto-Submitted: auto-generated The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=573bb4875b9994054dbc00218a3f08763af56c9e commit 573bb4875b9994054dbc00218a3f08763af56c9e Author: Mark Johnston AuthorDate: 2023-12-26 01:42:17 +0000 Commit: Mark Johnston CommitDate: 2024-01-02 01:12:45 +0000 umtx: Check for errors from suword32() This is in preparation for annotating copyin() and related functions with __result_use_check. Reviewed by: kib MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D43144 (cherry picked from commit 3379d9b5de4c4876a317d25ca008e66b1111b701) --- sys/kern/kern_umtx.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/sys/kern/kern_umtx.c b/sys/kern/kern_umtx.c index de87206af844..94050beee7dd 100644 --- a/sys/kern/kern_umtx.c +++ b/sys/kern/kern_umtx.c @@ -2961,7 +2961,14 @@ do_cv_wait(struct thread *td, struct ucond *cv, struct umutex *m, */ error = fueword32(&cv->c_has_waiters, &hasw); if (error == 0 && hasw == 0) - suword32(&cv->c_has_waiters, 1); + error = suword32(&cv->c_has_waiters, 1); + if (error != 0) { + umtxq_lock(&uq->uq_key); + umtxq_remove(uq); + umtxq_unbusy(&uq->uq_key); + error = EFAULT; + goto out; + } umtxq_unbusy_unlocked(&uq->uq_key); @@ -2991,7 +2998,9 @@ do_cv_wait(struct thread *td, struct ucond *cv, struct umutex *m, umtxq_remove(uq); if (oldlen == 1) { umtxq_unlock(&uq->uq_key); - suword32(&cv->c_has_waiters, 0); + if (suword32(&cv->c_has_waiters, 0) != 0 && + error == 0) + error = EFAULT; umtxq_lock(&uq->uq_key); } } @@ -2999,7 +3008,7 @@ do_cv_wait(struct thread *td, struct ucond *cv, struct umutex *m, if (error == ERESTART) error = EINTR; } - +out: umtxq_unlock(&uq->uq_key); umtx_key_release(&uq->uq_key); return (error); @@ -3177,12 +3186,14 @@ sleep: */ rv = fueword32(&rwlock->rw_blocked_readers, &blocked_readers); + if (rv == 0) + rv = suword32(&rwlock->rw_blocked_readers, + blocked_readers + 1); if (rv == -1) { umtxq_unbusy_unlocked(&uq->uq_key); error = EFAULT; break; } - suword32(&rwlock->rw_blocked_readers, blocked_readers+1); while (state & wrflags) { umtxq_lock(&uq->uq_key); @@ -3207,12 +3218,14 @@ sleep: /* decrease read waiter count, and may clear read contention bit */ rv = fueword32(&rwlock->rw_blocked_readers, &blocked_readers); + if (rv == 0) + rv = suword32(&rwlock->rw_blocked_readers, + blocked_readers - 1); if (rv == -1) { umtxq_unbusy_unlocked(&uq->uq_key); error = EFAULT; break; } - suword32(&rwlock->rw_blocked_readers, blocked_readers-1); if (blocked_readers == 1) { rv = fueword32(&rwlock->rw_state, &state); if (rv == -1) { @@ -3361,12 +3374,14 @@ do_rw_wrlock(struct thread *td, struct urwlock *rwlock, struct _umtx_time *timeo sleep: rv = fueword32(&rwlock->rw_blocked_writers, &blocked_writers); + if (rv == 0) + rv = suword32(&rwlock->rw_blocked_writers, + blocked_writers + 1); if (rv == -1) { umtxq_unbusy_unlocked(&uq->uq_key); error = EFAULT; break; } - suword32(&rwlock->rw_blocked_writers, blocked_writers + 1); while ((state & URWLOCK_WRITE_OWNER) || URWLOCK_READER_COUNT(state) != 0) { @@ -3391,12 +3406,14 @@ sleep: rv = fueword32(&rwlock->rw_blocked_writers, &blocked_writers); + if (rv == 0) + rv = suword32(&rwlock->rw_blocked_writers, + blocked_writers - 1); if (rv == -1) { umtxq_unbusy_unlocked(&uq->uq_key); error = EFAULT; break; } - suword32(&rwlock->rw_blocked_writers, blocked_writers-1); if (blocked_writers == 1) { rv = fueword32(&rwlock->rw_state, &state); if (rv == -1) { @@ -3575,7 +3592,7 @@ again: rv1 = fueword32(&sem->_count, &count); if (rv == -1 || rv1 == -1 || count != 0 || (rv == 1 && count1 == 0)) { if (rv == 0) - suword32(&sem->_has_waiters, 0); + rv = suword32(&sem->_has_waiters, 0); umtxq_lock(&uq->uq_key); umtxq_unbusy(&uq->uq_key); umtxq_remove(uq);