From nobody Sun May 26 13:52:04 2024 X-Original-To: dev-commits-src-branches@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 4VnKvm5lB9z5LTgp; Sun, 26 May 2024 13:52:04 +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 4VnKvm5Fp6z4jxx; Sun, 26 May 2024 13:52:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716731524; 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=SWGkIGr3sh0vAVVN/1KoDJDIs4b4kiaKEX2dn8bUcVs=; b=dAWybWWbweZ6oaxuv9BWzDYFZY6u/JDO/ZUBh2WNgwGNZC/nmYqSFUxKRRjBwgVm6unqjq crHl9Y04boY4ihYE5yD2uIkM7D7cU6bIussBrHcYG8jZqSEtKzao2XojeM+Z9Dquc+4leI 98IEaa4prgXHQGeIV5Q3NULvWyAJL4BTLq1bZqoLeq5wTMGzynxDBMMkPVvdCjuMI9ea6V L6yYKbVRiSPwzCBLY0tQy51B+bOc71L/DjG1iOyZl2HPC/ZCZxTHQ5nTUJI3vv7O4fg/g1 jNb0EWzNgno2uSjwaqPNWUoVAddIu6+jDWohES3xqWcz/Od78cCNgil5Bb0k4A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716731524; a=rsa-sha256; cv=none; b=JHW5Cb80/otXEkZRjVQWPLRpNMdqTB3j7bZsQMnpUPLJkxcPSXY9IfrgX+DsEJ2L2ltWvN lNjr74QSbeKK9ethXSUSbhyN9C9H8U3IsQ3Og54YabmSQy1JPNjMe/Wuy7AzyVUlKuwhBI SWv5RWhKuTWlR5pylQBmM0cfVkk7c0p9pO1UxxX7QYtpADO4Oedze1lxu6PpeJjGeJHDbe z8W7ak3VCc3d+qnG/Z9/uyiTjbnAZ1F7uEVkKGSL877TWehAZ9bCeit76yj7ZlrjktiDTu aV0W76fwDmVVDe9wrJde/hhXyp72kjcnpHiSsfbFu1L9v27d6NPKaB9TNnFEhg== 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=1716731524; 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=SWGkIGr3sh0vAVVN/1KoDJDIs4b4kiaKEX2dn8bUcVs=; b=d+lwiSSWdJ8GJ57o65abdgMCnFPmf7kN9l5ncvRFR8LviDi2sZw46tH18jdoZqG7WPAgl5 Tyu8SxIT/1VAYDemm9Bmcyf7lt4epv8RGC10qZt6C8u+QhX1bAk3sz8y/tpAQDKdYi8OFw iVO/Jz/iI9/y5ZPgSwRzrVDfO5NEv2Bk7kYSyktEXosHdQzgktiors/bUGbf4mQMPub4RR 8lmEpRepZubCBWIsLumXNMD3DhGG1kKm6QLp9069lVcSXZousejpBdkDWDwcSY1nEFyJR9 +TUZmHAMmpHcDwC9ZAm+6R/uOaKVq4+KBd0x6dHYbdGXAGszTAvQ3uVuGHSVHQ== 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 4VnKvm4sFGz12Sb; Sun, 26 May 2024 13:52:04 +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 44QDq4cM098935; Sun, 26 May 2024 13:52:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44QDq4vS098932; Sun, 26 May 2024 13:52:04 GMT (envelope-from git) Date: Sun, 26 May 2024 13:52:04 GMT Message-Id: <202405261352.44QDq4vS098932@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Christos Margiolis Subject: git: 38286d9f6828 - stable/14 - pcm: centralize 32-bit ioctl compat List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: christos X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 38286d9f68284e68ac8764b19f7862fd28acc689 Auto-Submitted: auto-generated The branch stable/14 has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=38286d9f68284e68ac8764b19f7862fd28acc689 commit 38286d9f68284e68ac8764b19f7862fd28acc689 Author: Brooks Davis AuthorDate: 2024-05-23 16:14:36 +0000 Commit: Christos Margiolis CommitDate: 2024-05-26 13:51:33 +0000 pcm: centralize 32-bit ioctl compat Move all handlng of struct sndstioc_nv_arg(32) to sndstat_ioctl() and make the functions that actually do the work take a buffer and size or size pointer. The 32-bit compat work is minimal so just inline it. Remove checks that we've got a 32-bit process for 32-bit ioctls. We don't check that default ioctls are from 64-bit processes on 64-bit systems. Reviewed by: christos Differential Revision: https://reviews.freebsd.org/D45307 (cherry picked from commit fb9013f215211f013eccc54786f299e39a1f8773) --- sys/dev/sound/pcm/sndstat.c | 95 ++++++++++++++------------------------------- 1 file changed, 29 insertions(+), 66 deletions(-) diff --git a/sys/dev/sound/pcm/sndstat.c b/sys/dev/sound/pcm/sndstat.c index 6880ce383ba4..6670a1e43aac 100644 --- a/sys/dev/sound/pcm/sndstat.c +++ b/sys/dev/sound/pcm/sndstat.c @@ -45,9 +45,6 @@ #include #include #include -#ifdef COMPAT_FREEBSD32 -#include -#endif #include #include @@ -622,10 +619,9 @@ sndstat_refresh_devs(struct sndstat_file *pf) } static int -sndstat_get_devs(struct sndstat_file *pf, caddr_t data) +sndstat_get_devs(struct sndstat_file *pf, void *arg_buf, size_t *arg_nbytes) { int err; - struct sndstioc_nv_arg *arg = (struct sndstioc_nv_arg *)data; SNDSTAT_LOCK(); sx_xlock(&pf->lock); @@ -664,22 +660,22 @@ sndstat_get_devs(struct sndstat_file *pf, caddr_t data) SNDSTAT_UNLOCK(); - if (!arg->nbytes) { - arg->nbytes = pf->devs_nbytes; + if (*arg_nbytes == 0) { + *arg_nbytes = pf->devs_nbytes; err = 0; goto done; } - if (arg->nbytes < pf->devs_nbytes) { - arg->nbytes = 0; + if (*arg_nbytes < pf->devs_nbytes) { + *arg_nbytes = 0; err = 0; goto done; } - err = copyout(pf->devs_nvlbuf, arg->buf, pf->devs_nbytes); + err = copyout(pf->devs_nvlbuf, arg_buf, pf->devs_nbytes); if (err) goto done; - arg->nbytes = pf->devs_nbytes; + *arg_nbytes = pf->devs_nbytes; free(pf->devs_nvlbuf, M_NVLIST); pf->devs_nvlbuf = NULL; @@ -850,25 +846,24 @@ sndstat_dsp_unpack_nvlist(const nvlist_t *nvlist, struct sndstat_userdev *ud) } static int -sndstat_add_user_devs(struct sndstat_file *pf, caddr_t data) +sndstat_add_user_devs(struct sndstat_file *pf, void *nvlbuf, size_t nbytes) { int err; nvlist_t *nvl = NULL; const nvlist_t * const *dsps; size_t i, ndsps; - struct sndstioc_nv_arg *arg = (struct sndstioc_nv_arg *)data; if ((pf->fflags & FWRITE) == 0) { err = EPERM; goto done; } - if (arg->nbytes > SNDST_UNVLBUF_MAX) { + if (nbytes > SNDST_UNVLBUF_MAX) { err = ENOMEM; goto done; } - err = sndstat_unpack_user_nvlbuf(arg->buf, arg->nbytes, &nvl); + err = sndstat_unpack_user_nvlbuf(nvlbuf, nbytes, &nvl); if (err != 0) goto done; @@ -914,52 +909,17 @@ sndstat_flush_user_devs(struct sndstat_file *pf) return (0); } -#ifdef COMPAT_FREEBSD32 -static int -compat_sndstat_get_devs32(struct sndstat_file *pf, caddr_t data) -{ - struct sndstioc_nv_arg32 *arg32 = (struct sndstioc_nv_arg32 *)data; - struct sndstioc_nv_arg arg; - int err; - - arg.buf = (void *)(uintptr_t)arg32->buf; - arg.nbytes = arg32->nbytes; - - err = sndstat_get_devs(pf, (caddr_t)&arg); - if (err == 0) { - arg32->buf = (uint32_t)(uintptr_t)arg.buf; - arg32->nbytes = arg.nbytes; - } - - return (err); -} - -static int -compat_sndstat_add_user_devs32(struct sndstat_file *pf, caddr_t data) -{ - struct sndstioc_nv_arg32 *arg32 = (struct sndstioc_nv_arg32 *)data; - struct sndstioc_nv_arg arg; - int err; - - arg.buf = (void *)(uintptr_t)arg32->buf; - arg.nbytes = arg32->nbytes; - - err = sndstat_add_user_devs(pf, (caddr_t)&arg); - if (err == 0) { - arg32->buf = (uint32_t)(uintptr_t)arg.buf; - arg32->nbytes = arg.nbytes; - } - - return (err); -} -#endif - static int sndstat_ioctl( struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct thread *td) { int err; struct sndstat_file *pf; + struct sndstioc_nv_arg *arg; +#ifdef COMPAT_FREEBSD32 + struct sndstioc_nv_arg32 *arg32; + size_t nbytes; +#endif err = devfs_get_cdevpriv((void **)&pf); if (err != 0) @@ -967,27 +927,30 @@ sndstat_ioctl( switch (cmd) { case SNDSTIOC_GET_DEVS: - err = sndstat_get_devs(pf, data); + arg = (struct sndstioc_nv_arg *)data; + err = sndstat_get_devs(pf, arg->buf, &arg->nbytes); break; #ifdef COMPAT_FREEBSD32 case SNDSTIOC_GET_DEVS32: - if (!SV_CURPROC_FLAG(SV_ILP32)) { - err = ENODEV; - break; + arg32 = (struct sndstioc_nv_arg32 *)data; + nbytes = arg32->nbytes; + err = sndstat_get_devs(pf, (void *)(uintptr_t)arg32->buf, + &nbytes); + if (err == 0) { + KASSERT(nbytes < UINT_MAX, ("impossibly many bytes")); + arg32->nbytes = nbytes; } - err = compat_sndstat_get_devs32(pf, data); break; #endif case SNDSTIOC_ADD_USER_DEVS: - err = sndstat_add_user_devs(pf, data); + arg = (struct sndstioc_nv_arg *)data; + err = sndstat_add_user_devs(pf, arg->buf, arg->nbytes); break; #ifdef COMPAT_FREEBSD32 case SNDSTIOC_ADD_USER_DEVS32: - if (!SV_CURPROC_FLAG(SV_ILP32)) { - err = ENODEV; - break; - } - err = compat_sndstat_add_user_devs32(pf, data); + arg32 = (struct sndstioc_nv_arg32 *)data; + err = sndstat_add_user_devs(pf, (void *)(uintptr_t)arg32->buf, + arg32->nbytes); break; #endif case SNDSTIOC_REFRESH_DEVS: