From nobody Wed Dec 10 10:58:05 2025 X-Original-To: dev-commits-src-main@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 4dRCP96xfPz6KNLt for ; Wed, 10 Dec 2025 10:58:05 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dRCP9650jz3mJ0 for ; Wed, 10 Dec 2025 10:58:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765364285; 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=zIEtszgP43pNumvaN9QhIyelikQET3jYm2u3jnzJbOc=; b=lD1rUAluBFDXZ9eFcBI8MVfU+LuAxV4Shzkhg24VS/3sOtJ595TJA7pum3jT1Jf8xEoBwK Sryz98d/nl83B7jfy93QKaVrgpNelI08tjuMpW/JSphCQLnz+uYEgphlqlyKgozXAcM336 FcqiBy9wMJauAAjJHJ8zWgSXyMrqLIefZwPNCszbnlRZl7l8KDyE8CHxCv3Elxi3F6xdox S4hxtv8Fbb/GVM8UL1qgzpzRXkDAdWiK+i0Sx4ZR3hlN9Uf5RrjQxPF9NZ2WDUHYu9r37p rTMxC0qaHxTXamKXXz4k5G4M9aT5UioHwJVUP/N9Z7kJ0GcoKHfCFcAC9Iasig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765364285; 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=zIEtszgP43pNumvaN9QhIyelikQET3jYm2u3jnzJbOc=; b=VYa8ilL7oxdD6kkpu+wzcztJenQOe6qNv4LuUWSQhtVOVHNBJm3JJz7dVrtAtc+UpcBlf8 C96lHqmalc4RbHTbT5O2aBCkG3X6zBWF6P/b52k7iQZGt1lk4owUSGtTe0h5dpxGKSEkk/ nzQFkgSTpdSa1X+Y/MZOanJ12VtYOirx23hshkpiAIe7zb+akuqZk9BxHZseNuBbJ7IQ5z aSP3r0c9ayjXjFJ3hUWE313C6rtyl3qFtEJMQJvXM/lIhT0do4IeabylCwMjvLU4mIWc0V f1li0hWbEBFQrzS6RJcfhmKhRcTbCZ3JrA+WY3DBh1ZY5OADT+0duzBEOmRrnw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1765364285; a=rsa-sha256; cv=none; b=qcdqrirZweOXjIZDH0dXU1X/WrLhruECH1oL/MRRezW1odeo8HAHGeARbAmSDBboTKrYuO p7F3iFWvYUUQKT7urStTqDminCvzyz7yo6msyxyfaZMshOxb/sfDE9SpHYNBFBlMaaD87i dvIAxL3ykXtAKe7h0oADuuqnrF6Tc02Op08sAdBKfqI+QXaTPWphOeBqTIfYNFbkI9Xf9g aTGRWlaRmkQp67kk6TTbomWCKQZBY4yWcJuLzFkvVHGwb2qYbcyvewWYHxtjzC1HzjcXbe +kFfdWf/aVwOkfIUxw8hmYq9a8sBlPPCrvGfE3GYH4zNIAe5Mas1uk86tTKwgA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dRCP95HhDzjNy for ; Wed, 10 Dec 2025 10:58:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 8560 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 10 Dec 2025 10:58:05 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Brooks Davis Subject: git: ac79e2e025e0 - main - get*ent: be consistant about _ALIGN(p) - p List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: brooks X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ac79e2e025e03b7038e3abc886e34a03f5ec2934 Auto-Submitted: auto-generated Date: Wed, 10 Dec 2025 10:58:05 +0000 Message-Id: <6939523d.8560.71c378b7@gitrepo.freebsd.org> The branch main has been updated by brooks: URL: https://cgit.FreeBSD.org/src/commit/?id=ac79e2e025e03b7038e3abc886e34a03f5ec2934 commit ac79e2e025e03b7038e3abc886e34a03f5ec2934 Author: Brooks Davis AuthorDate: 2025-12-10 10:57:34 +0000 Commit: Brooks Davis CommitDate: 2025-12-10 10:57:34 +0000 get*ent: be consistant about _ALIGN(p) - p Add an nscache specific inline function to calculate the misalignment rather than adding and subtracting _ALIGN(p) and p which can take the buffer far out of bound (undefined behavior in C and unsupported on CHERI). Reviewed by: kib Effort: CHERI upstreaming Obtained from: CheriBSD Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D53945 --- lib/libc/gen/getgrent.c | 6 +++--- lib/libc/include/nscache.h | 8 ++++++++ lib/libc/net/gethostnamadr.c | 4 ++-- lib/libc/net/getnetnamadr.c | 4 ++-- lib/libc/net/getprotoent.c | 4 ++-- lib/libc/net/getservent.c | 4 ++-- lib/libc/rpc/getrpcent.c | 4 ++-- 7 files changed, 21 insertions(+), 13 deletions(-) diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c index 508e3d63eb60..8819708556b9 100644 --- a/lib/libc/gen/getgrent.c +++ b/lib/libc/gen/getgrent.c @@ -347,16 +347,16 @@ grp_unmarshal_func(char *buffer, size_t buffer_size, void *retval, va_list ap, memcpy(&p, buffer + sizeof(struct group), sizeof(char *)); if (orig_buf_size + sizeof(struct group) + sizeof(char *) + - _ALIGN(p) - (size_t)p < buffer_size) { + __nss_buf_misalignment(p) < buffer_size) { *ret_errno = ERANGE; return (NS_RETURN); } orig_buf = (char *)_ALIGN(orig_buf); memcpy(orig_buf, buffer + sizeof(struct group) + sizeof(char *) + - _ALIGN(p) - (size_t)p, + __nss_buf_misalignment(p), buffer_size - sizeof(struct group) - sizeof(char *) - - _ALIGN(p) + (size_t)p); + __nss_buf_misalignment(p)); p = (char *)_ALIGN(p); NS_APPLY_OFFSET(grp->gr_name, orig_buf, p, char *); diff --git a/lib/libc/include/nscache.h b/lib/libc/include/nscache.h index aab29e411ddc..5932d103a4da 100644 --- a/lib/libc/include/nscache.h +++ b/lib/libc/include/nscache.h @@ -29,6 +29,8 @@ #ifndef __NS_CACHE_H__ #define __NS_CACHE_H__ +#include + #include "nscachedcli.h" typedef int (*nss_cache_id_func_t)(char *, size_t *, va_list, void *); @@ -178,6 +180,12 @@ typedef struct _nss_cache_data { } nss_cache_data; __BEGIN_DECLS +static inline __ptrdiff_t +__nss_buf_misalignment(const void *p) +{ + return ((char *)_ALIGN(p) - (char *)p); +} + /* dummy function, which is needed to make nss_method_lookup happy */ extern int __nss_cache_handler(void *, void *, va_list); diff --git a/lib/libc/net/gethostnamadr.c b/lib/libc/net/gethostnamadr.c index b54ca8b2998e..6a8648ac693d 100644 --- a/lib/libc/net/gethostnamadr.c +++ b/lib/libc/net/gethostnamadr.c @@ -402,9 +402,9 @@ host_unmarshal_func(char *buffer, size_t buffer_size, void *retval, va_list ap, orig_buf = (char *)_ALIGN(orig_buf); memcpy(orig_buf, buffer + sizeof(struct hostent) + sizeof(char *) + - _ALIGN(p) - (size_t)p, + __nss_buf_misalignment(p), buffer_size - sizeof(struct hostent) - sizeof(char *) - - _ALIGN(p) + (size_t)p); + __nss_buf_misalignment(p)); p = (char *)_ALIGN(p); NS_APPLY_OFFSET(ht->h_name, orig_buf, p, char *); diff --git a/lib/libc/net/getnetnamadr.c b/lib/libc/net/getnetnamadr.c index 660de3302606..b380912955e8 100644 --- a/lib/libc/net/getnetnamadr.c +++ b/lib/libc/net/getnetnamadr.c @@ -249,9 +249,9 @@ net_unmarshal_func(char *buffer, size_t buffer_size, void *retval, va_list ap, orig_buf = (char *)_ALIGN(orig_buf); memcpy(orig_buf, buffer + sizeof(struct netent) + sizeof(char *) + - _ALIGN(p) - (size_t)p, + __nss_buf_misalignment(p), buffer_size - sizeof(struct netent) - sizeof(char *) - - _ALIGN(p) + (size_t)p); + __nss_buf_misalignment(p)); p = (char *)_ALIGN(p); NS_APPLY_OFFSET(ne->n_name, orig_buf, p, char *); diff --git a/lib/libc/net/getprotoent.c b/lib/libc/net/getprotoent.c index 9fcbf41530cf..5f25333caff3 100644 --- a/lib/libc/net/getprotoent.c +++ b/lib/libc/net/getprotoent.c @@ -265,9 +265,9 @@ __proto_unmarshal_func(char *buffer, size_t buffer_size, void *retval, orig_buf = (char *)_ALIGN(orig_buf); memcpy(orig_buf, buffer + sizeof(struct protoent) + sizeof(char *) + - _ALIGN(p) - (size_t)p, + __nss_buf_misalignment(p), buffer_size - sizeof(struct protoent) - sizeof(char *) - - _ALIGN(p) + (size_t)p); + __nss_buf_misalignment(p)); p = (char *)_ALIGN(p); NS_APPLY_OFFSET(proto->p_name, orig_buf, p, char *); diff --git a/lib/libc/net/getservent.c b/lib/libc/net/getservent.c index 26f68f24cc78..1cf7921ac679 100644 --- a/lib/libc/net/getservent.c +++ b/lib/libc/net/getservent.c @@ -1084,9 +1084,9 @@ serv_unmarshal_func(char *buffer, size_t buffer_size, void *retval, va_list ap, orig_buf = (char *)_ALIGN(orig_buf); memcpy(orig_buf, buffer + sizeof(struct servent) + sizeof(char *) + - (_ALIGN(p) - (size_t)p), + __nss_buf_misalignment(p), buffer_size - sizeof(struct servent) - sizeof(char *) - - (_ALIGN(p) - (size_t)p)); + __nss_buf_misalignment(p)); p = (char *)_ALIGN(p); NS_APPLY_OFFSET(serv->s_name, orig_buf, p, char *); diff --git a/lib/libc/rpc/getrpcent.c b/lib/libc/rpc/getrpcent.c index ee36c11b303f..a6eaac7079a3 100644 --- a/lib/libc/rpc/getrpcent.c +++ b/lib/libc/rpc/getrpcent.c @@ -778,9 +778,9 @@ rpc_unmarshal_func(char *buffer, size_t buffer_size, void *retval, va_list ap, orig_buf = (char *)_ALIGN(orig_buf); memcpy(orig_buf, buffer + sizeof(struct rpcent) + sizeof(char *) + - _ALIGN(p) - (size_t)p, + __nss_buf_misalignment(p), buffer_size - sizeof(struct rpcent) - sizeof(char *) - - _ALIGN(p) + (size_t)p); + __nss_buf_misalignment(p)); p = (char *)_ALIGN(p); NS_APPLY_OFFSET(rpc->r_name, orig_buf, p, char *);