From nobody Thu Feb 20 14:13:52 2025 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 4YzFcJ6B9qz5nxCb; Thu, 20 Feb 2025 14:13:52 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YzFcJ3S7bz3WsK; Thu, 20 Feb 2025 14:13:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1740060832; 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=/G6f1sy+5PAi2oU50rmIGA1zhMlYFGOlLPLWOYoHgbw=; b=p7pnMJKAgDBx7evH15gypYhfBq+h6Uy/DE3AFejV2dYvD6CxhFpeG8wqpCladrfsLuZNh4 Y4ji1h86Al2LyJ2E1qJ9FrYFNLLqKa4zU73towId+hW3NowcO6CmSLUe0yI/4ezwC+F4yd eK43svVJOn1VjQaLrf17+RwiM9G14PpMPL5sGKeUlOtWDwD+yGcAoDW4MaWxrFUd3IjpZT DExL8evYI1luOrKTUdJn+vv1mWu4pjB+bm2XriN7ntghMxkq2nYx9VV71BDtAuZG+wmZHV oxxWq2cs+v53tkCs/+CdjUfOceJ78AB5icfqspkTNrOHZ19kosOjG9SZVim08Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1740060832; a=rsa-sha256; cv=none; b=pPVS2rIgMi+bCPyjO3SNc+TB5SRM5lTVsSs0JDTvrb+ydz6REyMbELf6anh6+a2WQ0paWi 0XRlLgGwxtZtTiTvmv1cndTg1sFO6XhNZYVo++G7b9YySvf/iAKyoeKh5+XGTZcaf8jwk+ Qf777RP3XQqeTkTQ8OPUM7f7g2Fyl+hjxeP5DaqQO0fZpeVKXmTNXZmXssJR+sEky90HyZ 37f+p1FhKgZROWFBx78QpYQuX3VeyJnvRnbaPiS17AhP6BbPooqmlBYjn6/tI2VNF2HE2B k96mGvaNzWuE0mSdUX83IQMSgLpKPVxzmcAPHyFDKB0lrAIg0Cs4rj+JkLWL2A== 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=1740060832; 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=/G6f1sy+5PAi2oU50rmIGA1zhMlYFGOlLPLWOYoHgbw=; b=BpAQZ7DFKAX1ezBcnsn+rZU8NnaQZ9nTeRJN3On+C9tEEdum3VwDcMVZyaLMrQcC7r2LNk 8vrKeF3io+keerDmUUY+LB2w6ZZsEo7GdCRGER8PnNQNBInBLg4Ve5y+Tof2c04BBz7VTf 5n+isNKdLiwW/C6C9akSUWNkWP2ItzVR/QRM0uKcZUyNXTFMASnV3UJAzZbwt+5Z8I0NU5 xCuSLb79uMZBMAd2P4nhPqVkruK2MoZRpA/38vB6D0eVpLqqIkAPxLEuaVfU5F7I7TosVY bJuLzI1gHxHUn+ssYa667JOTVYf3CL6CCTqfamxSB0o3ExXSapgo+MumQ8brZw== 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 4YzFcJ2Y22zvMk; Thu, 20 Feb 2025 14:13:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 51KEDqUX054504; Thu, 20 Feb 2025 14:13:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 51KEDqgV054501; Thu, 20 Feb 2025 14:13:52 GMT (envelope-from git) Date: Thu, 20 Feb 2025 14:13:52 GMT Message-Id: <202502201413.51KEDqgV054501@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: 6789b9f63023 - stable/14 - libc: Fix getentropy POSIX 2024 conformance issues 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 6789b9f630236a9bc0e7b4f2b930c1048c5312ef Auto-Submitted: auto-generated The branch stable/14 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=6789b9f630236a9bc0e7b4f2b930c1048c5312ef commit 6789b9f630236a9bc0e7b4f2b930c1048c5312ef Author: Ed Maste AuthorDate: 2024-11-16 15:14:21 +0000 Commit: Ed Maste CommitDate: 2025-02-20 14:13:25 +0000 libc: Fix getentropy POSIX 2024 conformance issues GETENTROPY_MAX should be defined in limits.h. EINVAL is the return value for buflen > GETENTROPY_MAX. PR: 282783 Reviewed by: markj, asomers, jhb Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D47689 --- include/limits.h | 4 ++++ lib/libc/gen/getentropy.3 | 14 ++++---------- lib/libc/gen/getentropy.c | 5 +++-- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/include/limits.h b/include/limits.h index 73036ca3ad7b..1a3c872b1ffb 100644 --- a/include/limits.h +++ b/include/limits.h @@ -139,6 +139,10 @@ #define MB_LEN_MAX 6 /* 31-bit UTF-8 */ +#if __POSIX_VISIBLE >= 202405 +#define GETENTROPY_MAX 256 +#endif + #include #if __POSIX_VISIBLE diff --git a/lib/libc/gen/getentropy.3 b/lib/libc/gen/getentropy.3 index 5bbbc80e2414..5f7ee32ebbfc 100644 --- a/lib/libc/gen/getentropy.3 +++ b/lib/libc/gen/getentropy.3 @@ -15,7 +15,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd November 20, 2024 +.Dd January 17, 2025 .Dt GETENTROPY 3 .Os .Sh NAME @@ -60,8 +60,8 @@ The .Fa buf parameter points to an invalid address. -.It Bq Er EIO -Too many bytes requested, or some other fatal error occurred. +.It Bq Er EINVAL +Too many bytes requested. .El .Sh SEE ALSO .Xr getrandom 2 , @@ -69,7 +69,7 @@ Too many bytes requested, or some other fatal error occurred. .Xr random 4 .Sh STANDARDS .Fn getentropy -nearly conforms to +conforms to .St -p1003.1-2024 . .Sh HISTORY The @@ -80,9 +80,3 @@ The .Fx libc compatibility shim first appeared in .Fx 12.0 . -.Sh BUGS -.In limits.h -does not define -.Dv GETENTROPY_MAX . -Some error values do not match -.St -p1003.1-2024 . diff --git a/lib/libc/gen/getentropy.c b/lib/libc/gen/getentropy.c index 060c2760bfad..5dffd91c6dee 100644 --- a/lib/libc/gen/getentropy.c +++ b/lib/libc/gen/getentropy.c @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -110,8 +111,8 @@ getentropy(void *buf, size_t buflen) ssize_t rd; bool have_getrandom; - if (buflen > 256) { - errno = EIO; + if (buflen > GETENTROPY_MAX) { + errno = EINVAL; return (-1); }