From nobody Tue Dec 26 02:04:27 2023 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 4SzdPS03kSz55KmK; Tue, 26 Dec 2023 02:04:28 +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 4SzdPR3xcJz4KbP; Tue, 26 Dec 2023 02:04:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703556267; 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=ex2aBnDtlBa/svfxEdCwp72a2NEQCeWaNqNdpVfbPfE=; b=WPuo+QLwfglxbLug/8GgDyV4L4HEFoedQtFziCIQ/AfOoByo8/YeIQWNkmOTy0b8dS47uW rh6F/JEd6Enc/M9jxBfzO9cceBXkmtrHbqRrnl/0fLHyM8J9CEnEfwkvV7MJltb5Jzb4v5 4Q9LL97naaP2hxdWqbfhxvduwI/sQ4+NMATUqL68uT2XB7JHVBoJQNzV2VSO4XiNkeL5qY V5O/6ZP66rQqBOL7cOsFaTfELqiuzy3TXOofDYUHPry9RiFvt1nwFeZsD1aM1EmqCOMszq NAYKAMRRn/7fMJHkqAM0rxhKK33sEkFuMIttGuHPKezBErxc3aNk411mNpe1KQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703556267; a=rsa-sha256; cv=none; b=X/qeUdJCqhOUzuK7s5uSZ1pIRHuIH5PU6NA8dtUdtRQQ0lYBx5jxKBA60/b7E/kLdWXUId l0AEdSqFpKI87f885nptyJ14Z+K/cT7ryli1m7BqZ8NoKv/Hu4xbZiuxwzxZxg44Y7w0Sn xckXR5Z0uJa/5WsCuREybmt1Ep0O7+mrBhV5SFKZiGnI+ig0webO2ICQalUXoI2rAGdNev yAaflwt9WZ8YUQdhXAI838i/R23zCk2GYk3YeETtDgajuHUdpYgcRjeiO+wSameBiGlUY1 85YfhRYSqEKgSN8JmR+Wh9zgNU72K0HaTvdSf+6jx/9uwRUV8z8hSb1A9yId6Q== 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=1703556267; 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=ex2aBnDtlBa/svfxEdCwp72a2NEQCeWaNqNdpVfbPfE=; b=tPzg9/24639Ez/iykaNict+cQxd+CADTeDa37Np3Zh1ituxtUZXTNUmTGGgoETcSjNp55S vw7PghqtpdcBQ4YVxMaMoIAfPJU82lWE00ZCuCBZknGELV5m4Vwj76AhLYAdtTKeaJNtae z2suWy1MZ+f7H1P53pA0rYz5rGIxam8TGVq0Wffc/DcP589nHdFBskZf9tWM0LimRGIFN1 npL5atKz9JCLzxdg70uUok91f+sun7i6yQ5iVUXQR62OLeZvaKstZIgJdH5SzkPwjPDAVD GZw4tBAvfPL/zX5Eut9VNVR74XSXTvCnrQkQ+HI12HgZAcFhFPq/J+AmAAZn7g== 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 4SzdPR32xLzc5Y; Tue, 26 Dec 2023 02:04: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 3BQ24Rio003350; Tue, 26 Dec 2023 02:04:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BQ24RQW003347; Tue, 26 Dec 2023 02:04:27 GMT (envelope-from git) Date: Tue, 26 Dec 2023 02:04:27 GMT Message-Id: <202312260204.3BQ24RQW003347@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: 3379d9b5de4c - main - 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/main X-Git-Reftype: branch X-Git-Commit: 3379d9b5de4c4876a317d25ca008e66b1111b701 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=3379d9b5de4c4876a317d25ca008e66b1111b701 commit 3379d9b5de4c4876a317d25ca008e66b1111b701 Author: Mark Johnston AuthorDate: 2023-12-26 01:42:17 +0000 Commit: Mark Johnston CommitDate: 2023-12-26 02:04:01 +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 --- 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);