ipf: copy{in,out}ptr -> ipf_copy{in,out}_indirect

These functions take the source or destintation address indirectly from
a potentially missaligned buffer.  Rename them to refect this and to
free up the copy{in,out}ptr names.

Some of the code in question is dead code and doesn't or won't compile,
but I've changed it all for consistency.

NB: If the pointers are actually stored under aligned then this code is
broken with CHERI.

Reviewed by:	cy
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D54232
This commit is contained in:
Brooks Davis 2025-12-19 15:59:08 +00:00
parent df6861d755
commit a79e2278c5
7 changed files with 18 additions and 16 deletions

View file

@ -619,7 +619,7 @@ ipf_checkv6sum(fin)
* See above for description, except that all addressing is in user space.
*/
int
copyoutptr(softc, src, dst, size)
ipf_copyout_indirect(softc, src, dst, size)
void *src, *dst;
size_t size;
{
@ -635,7 +635,7 @@ copyoutptr(softc, src, dst, size)
* See above for description, except that all addressing is in user space.
*/
int
copyinptr(src, dst, size)
ipf_copyin_indirect(src, dst, size)
void *src, *dst;
size_t size;
{

View file

@ -28,8 +28,8 @@ static ipf_error_entry_t *find_error(int);
static ipf_error_entry_t ipf_errors[] = {
{ 1, "auth table locked/full" },
{ 2, "" },
{ 3, "copyinptr received bad address" },
{ 4, "copyoutptr received bad address" },
{ 3, "ipf_copyin_indirect received bad address" },
{ 4, "ipf_copyout_indirect received bad address" },
{ 5, "" },
{ 6, "cannot load a rule with FR_T_BUILTIN flag set" },
{ 7, "internal rule without FR_T_BUILDINT flag set" },

View file

@ -4051,7 +4051,7 @@ ipf_sync(ipf_main_softc_t *softc, void *ifp)
* end up being unaligned) and on the kernel's local stack.
*/
/* ------------------------------------------------------------------------ */
/* Function: copyinptr */
/* Function: ipf_copyin_indirect */
/* Returns: int - 0 = success, else failure */
/* Parameters: src(I) - pointer to the source address */
/* dst(I) - destination address */
@ -4062,7 +4062,7 @@ ipf_sync(ipf_main_softc_t *softc, void *ifp)
/* NB: src - pointer to user space pointer, dst - kernel space pointer */
/* ------------------------------------------------------------------------ */
int
copyinptr(ipf_main_softc_t *softc, void *src, void *dst, size_t size)
ipf_copyin_indirect(ipf_main_softc_t *softc, void *src, void *dst, size_t size)
{
caddr_t ca;
int error;
@ -4084,7 +4084,7 @@ copyinptr(ipf_main_softc_t *softc, void *src, void *dst, size_t size)
/* ------------------------------------------------------------------------ */
/* Function: copyoutptr */
/* Function: ipf_copyout_indirect */
/* Returns: int - 0 = success, else failure */
/* Parameters: src(I) - pointer to the source address */
/* dst(I) - destination address */
@ -4095,7 +4095,7 @@ copyinptr(ipf_main_softc_t *softc, void *src, void *dst, size_t size)
/* NB: src - kernel space pointer, dst - pointer to user space pointer. */
/* ------------------------------------------------------------------------ */
int
copyoutptr(ipf_main_softc_t *softc, void *src, void *dst, size_t size)
ipf_copyout_indirect(ipf_main_softc_t *softc, void *src, void *dst, size_t size)
{
caddr_t ca;
int error;

View file

@ -1015,8 +1015,9 @@ ipf_auth_ioctlloop:
for (t = auth.fra_buf; m && (len > 0); ) {
i = MIN(M_LEN(m), len);
error = copyoutptr(softc, MTOD(m, char *),
&t, i);
error = ipf_copyout_indirect(softc,
MTOD(m, char *),
&t, i);
len -= i;
t += i;
if (error != 0) {

View file

@ -1679,8 +1679,9 @@ extern char *getifname(struct ifnet *);
extern int ipfattach(ipf_main_softc_t *);
extern int ipfdetach(ipf_main_softc_t *);
extern u_short ipf_cksum(u_short *, int);
extern int copyinptr(ipf_main_softc_t *, void *, void *, size_t);
extern int copyoutptr(ipf_main_softc_t *, void *, void *, size_t);
extern int ipf_copyin_indirect(ipf_main_softc_t *, void *, void *, size_t);
extern int ipf_copyout_indirect(ipf_main_softc_t *, void *, void *,
size_t);
extern int ipf_fastroute(mb_t *, mb_t **, fr_info_t *, frdest_t *);
extern int ipf_inject(fr_info_t *, mb_t *);
extern int ipf_inobj(ipf_main_softc_t *, void *, ipfobj_t *,

View file

@ -700,8 +700,8 @@ ipf_proxy_ioctl(ipf_main_softc_t *softc, caddr_t data, ioctlcmd_t cmd,
IPFERROR(80003);
error = ENOMEM;
} else {
error = copyinptr(softc, ctl.apc_data, ptr,
ctl.apc_dsize);
error = ipf_copyin_indirect(softc, ctl.apc_data,
ptr, ctl.apc_dsize);
if (error == 0)
ctl.apc_data = ptr;
}

View file

@ -106,7 +106,7 @@ ipf_scan_add(caddr_t data)
return (ENOMEM);
}
err = copyinptr(data, isc, sizeof(*isc));
err = ipf_copyin_indirect(data, isc, sizeof(*isc));
if (err) {
KFREE(isc);
return (err);
@ -150,7 +150,7 @@ ipf_scan_remove(caddr_t data)
ipscan_t isc, *i;
int err;
err = copyinptr(data, &isc, sizeof(isc));
err = ipf_copyin_indirect(data, &isc, sizeof(isc));
if (err)
return (err);