From nobody Thu Aug 28 02:08:48 2025 X-Original-To: bugs@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 4cC4ZS1J6cz6642l for ; Thu, 28 Aug 2025 02:08:48 +0000 (UTC) (envelope-from bugzilla-noreply@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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cC4ZS0J1Gz3g00 for ; Thu, 28 Aug 2025 02:08:48 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1756346928; 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: in-reply-to:in-reply-to:references:references; bh=a6qz5sysJ6NOf/6oZg9XJ0E4V8DbMuJl7518kuyAxZk=; b=B/ncmjNNTnmaS5GuUXGABrrYHu1BIRx5jnmeN12Ox6zh+K671dLO/mfnvrRXET42GWZ8EC hibynNqbWgokZl58STH+MTz++BkuA0FQj+TJUPkvFqgJkKErqKPQ+yJbeW5CCF9+N2jynv 940rfGv9h5RF7yjzVXKJBxe2fBZr/GMVdEL+Pa+LIBu5K2vABnJd69VHN6qv4QZ7iAr00C SmQbWMurjU7qt0fyoXodcpLZsNUMxBxZZFdB7u7cWlJ9S/IeDFz5IH3b+VQWWCv4tCKJZJ g8TiQ3kLRUUkKORa5SMlU7uGAVPJwJIHnPTMwZyYWXTpscdstBRVaxv+M91OZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1756346928; 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: in-reply-to:in-reply-to:references:references; bh=a6qz5sysJ6NOf/6oZg9XJ0E4V8DbMuJl7518kuyAxZk=; b=I0bY2uUcsQbH1Yl3pIVVZGW/oRE8NYlwlfr/xeoGCPMcT6Ma+dADRty1psbjai/PMMgKcm V3S7CI9jKDYmwvifIK2wHFgtksiTg7v+yOFr5vWXhCX2+DFZUjvbWi+djQyZssaZd9jDW0 XvInRZyNlbJQ3+vPPf53IvZcLpj8EvmminBaehI13eXJI+97CF4TBzN7r3w8uNlnpf5Ewa ICHrQBHAL/p+A0VH0nfyeJ3PIVW5Tsqr5QL9ReEaUK2VSsh0tpDkUhjxvDTNrtqN5A0OeT xjUEg4BHafHVnPZOG4tD1/426RjhS6fZPHEc34Mc2HTXr3TsmObgyHx/OVKeEw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1756346928; a=rsa-sha256; cv=none; b=JWatrKXG+llNFqeqbW0JDwBJvNe1OH0ObWio55Y3Uq+59+XODCvmHZFADF6pteLaqrsadu wdXgE54ebfd2AvnJyvCjQn50wAjZ+KS5XFo2sYq0gvCTZGqeG4EMLrd7srGdZ2YcTscgbK IBh1QsEpvXL4j0SKDa4gmej6TV69kNMyqi4miXrDDb+0Z7hKtm1L86BF0CZf6OOFM5zhSA k+NpnlBIf7DOW9+v6wBO9/IlM7tBMhYuXJfDy/ssIhPfTx51CtLdkH/olWrKQw1aTeuKVV ICBWPwKNAFARzeXhsep3TYiubojprGSEdTCpipaJKj6IsBorse1W87FtcN4jaA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (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 4cC4ZR6vrbzp1D for ; Thu, 28 Aug 2025 02:08:47 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 57S28lEa014183 for ; Thu, 28 Aug 2025 02:08:47 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 57S28lCe014182 for bugs@FreeBSD.org; Thu, 28 Aug 2025 02:08:47 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 289120] A time-of-check to time-of-use race exists in gpioc_kqread() of GPIO subsystem Date: Thu, 28 Aug 2025 02:08:48 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: 14.3-RELEASE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: chenqiuji666@gmail.com X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Bug reports List-Archive: https://lists.freebsd.org/archives/freebsd-bugs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-bugs@FreeBSD.org MIME-Version: 1.0 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D289120 --- Comment #1 from Qiu-ji Chen --- Updated description: In gpioc_kqread(), kn->kn_data is computed via number_of_events(), which re= ads evidx_head, evidx_tail, and numevents without synchronization. For example: static size_t number_of_events(struct gpioc_cdevpriv *priv) { if (priv->evidx_head >=3D priv->evidx_tail) return (priv->evidx_head - priv->evidx_tail); else return (priv->numevents + priv->evidx_head - priv->evidx_tail); } Because head/tail may change between the check and the use, the =E2=80=9Che= ad >=3D tail=E2=80=9D test can fail, and the subtraction may be negative, when converted to an unsigned integer, it wraps to a very large value. Impact =E2=80=A2 Integer overflow =E2=80=A2 Wrong interface semantics: EVFILT_READ kn_data may become a very = large value, leading to bogus copyout values and faulty user decisions (e.g., self-DoS). Suggested fix Snapshot head, tail, and numevents once into local variables and compute fr= om that single snapshot, instead of repeatedly reading shared fields. --=20 You are receiving this mail because: You are the assignee for the bug.=