From nobody Tue Jan 02 00:37:27 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 4T3v7q5DMcz55yXD; Tue, 2 Jan 2024 00:37:27 +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 4T3v7q2g1Bz3Hrs; Tue, 2 Jan 2024 00:37:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704155847; 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=gOJKjxbup0iAdJPIobV4fTpPWVRAmI4U1y/9tiPMNA4=; b=aFKfU8QttTGKDmC90lhqRzEVsO9SiHuFj66fBab5TdKzQa/kdUzr8C/9IcdmxQ2dzlCkJb 6Nvk+DUaU9jzD15p0C4FkAyR7J4XIhTDy7/4FjY5L2As9P/vhxJTrL3SFS0akwCo0ITJUC /T0f+/ylQT9JmU68QK5ERTMl515/TVA7digaUWUdFQfj1RzjXaBXWmDHhyd5VDw/XlG0P9 WlbfyGHgLXqSFxOOEG3Bf/pVHBhQwRMlB9vIvGQ6xwt/MaZGYuc+VftBNsIWa4TXHeCcVO uDZnlNircP2RIq2pdQmy586cMj3091x9bsMoupAYr7e4E37G/oDlIz3TGe/StA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704155847; a=rsa-sha256; cv=none; b=eIUvLCJiws6nHIs3FgRqKpP89wmgz/Ths1KGHU4RM8zPTdA2fSzwzTwd2wULj7t9jkq2Hc fw4trzehclMH575M7/3tEjkJw63pOjJbCDPLJ37FOAdLIBToFyXJwVNhK3nUM7En9n6HGk +0BfHyZdatyqw/YcJ6tT3FifKJJneZ7zYcJDJkqNKAYPI4kbTchBrA4aKHt7z6DRMP4qFi 40XqV1sDVZ5W/VE6nmnTm+/lPxx2qHr89N8ZIwD/cAAexg0DoxoWx7LGmeTYpMAL7d4C9x 9D/9nvD5q9Pi7kqj+y+HL+9uip4GU+Wl2OvTIs4Wz7csBPDGAj5e4X9354uW7A== 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=1704155847; 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=gOJKjxbup0iAdJPIobV4fTpPWVRAmI4U1y/9tiPMNA4=; b=DgQo8CSG81FW2lIfMLkTJjpuul1igvkNi4K4b3LuZRn8ok/EfEGnugQE8+DB7UWErph8Q4 jq3/PqMkz4ft2dgjyRnxGzP5ou+Nod3jNQrlht0kgkHdVGsOGeZIB3UkYXr2c6CMXSb5Wm 0ZvMSaKRbWlyOBbTwtUfUjHpPtOk4QGa50tnk5y0VLtY4kEi3n2r0kQnLPACgL8AkvTkOZ O9Ck+oU37l21Bn8IFgx5dE23enFQzYpgHwAPfYIHp6qEObGfsXhNOZlha9UDaW0Q868+3t HIFEPd+CQ52nAsM+cTvF0tZiOnULKE3bj0Eergb0YUikToWgNe3GJaOoGGgE1Q== 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 4T3v7q1mprzfmx; Tue, 2 Jan 2024 00:37:27 +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 4020bRo6085589; Tue, 2 Jan 2024 00:37:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4020bRpF085586; Tue, 2 Jan 2024 00:37:27 GMT (envelope-from git) Date: Tue, 2 Jan 2024 00:37:27 GMT Message-Id: <202401020037.4020bRpF085586@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: 8ff1566cb202 - stable/14 - 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/14 X-Git-Reftype: branch X-Git-Commit: 8ff1566cb202519cea1ad86850e1547fa01c749a Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=8ff1566cb202519cea1ad86850e1547fa01c749a commit 8ff1566cb202519cea1ad86850e1547fa01c749a Author: Mark Johnston AuthorDate: 2023-12-26 01:42:17 +0000 Commit: Mark Johnston CommitDate: 2024-01-02 00:29:54 +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 ff9505b8e31d..57ff74f5421e 100644 --- a/sys/kern/kern_umtx.c +++ b/sys/kern/kern_umtx.c @@ -2960,7 +2960,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); @@ -2990,7 +2997,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); } } @@ -2998,7 +3007,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); @@ -3176,12 +3185,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); @@ -3206,12 +3217,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) { @@ -3360,12 +3373,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) { @@ -3390,12 +3405,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) { @@ -3574,7 +3591,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);